ValidateOutputPath validates the output paths of the "docker cp" command.
(path string)
| 60 | |
| 61 | // ValidateOutputPath validates the output paths of the "docker cp" command. |
| 62 | func ValidateOutputPath(path string) error { |
| 63 | dir := filepath.Dir(filepath.Clean(path)) |
| 64 | if dir != "" && dir != "." { |
| 65 | if _, err := os.Stat(dir); os.IsNotExist(err) { |
| 66 | return fmt.Errorf("invalid output path: directory %q does not exist", dir) |
| 67 | } |
| 68 | } |
| 69 | // check whether `path` points to a regular file |
| 70 | // (if the path exists and doesn't point to a directory) |
| 71 | if fileInfo, err := os.Stat(path); !os.IsNotExist(err) { |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | |
| 76 | if fileInfo.Mode().IsDir() || fileInfo.Mode().IsRegular() { |
| 77 | return nil |
| 78 | } |
| 79 | |
| 80 | if err := ValidateOutputPathFileMode(fileInfo.Mode()); err != nil { |
| 81 | return fmt.Errorf("invalid output path: %q must be a directory or a regular file: %w", path, err) |
| 82 | } |
| 83 | } |
| 84 | return nil |
| 85 | } |
| 86 | |
| 87 | // ValidateOutputPathFileMode validates the output paths of the "docker cp" command |
| 88 | // and serves as a helper to [ValidateOutputPath] |
nothing calls this directly
no test coverage detected
searching dependent graphs…