| 69 | } |
| 70 | |
| 71 | func ensurePath(args []string) (string, error) { |
| 72 | // Create the directory if it does not exist |
| 73 | path := args[0] |
| 74 | _, err := os.Stat(path) |
| 75 | if err != nil && os.IsNotExist(err) { |
| 76 | err := os.MkdirAll(path, 0755) |
| 77 | if err != nil { |
| 78 | return "", err |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // we have to resolve the real local path, because the watcher gives us the real path always |
| 83 | realLocalPath, err := filepath.EvalSymlinks(path) |
| 84 | if err != nil { |
| 85 | return "", err |
| 86 | } |
| 87 | |
| 88 | absolutePath, err := filepath.Abs(realLocalPath) |
| 89 | if err != nil { |
| 90 | return "", err |
| 91 | } |
| 92 | |
| 93 | if absolutePath == "/" && path != "/" { |
| 94 | return "", fmt.Errorf("you are trying to sync the complete container root (/). By default this is not allowed, because this usually leads to unwanted behaviour. Please specify the correct container directory via the `--path` flag or `.path: localPath:/remotePath` option") |
| 95 | } |
| 96 | |
| 97 | return absolutePath, nil |
| 98 | } |