EnsureDir creates a directory if it doesn't exist. Returns nil if the directory already exists or was successfully created.
(path string)
| 55 | // EnsureDir creates a directory if it doesn't exist. |
| 56 | // Returns nil if the directory already exists or was successfully created. |
| 57 | func EnsureDir(path string) error { |
| 58 | ok, err := FileExists(path) |
| 59 | if err != nil { |
| 60 | return errors.Wrapf(err, "checking if dir exists at %s", path) |
| 61 | } |
| 62 | if ok { |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | if err := os.MkdirAll(path, 0755); err != nil { |
| 67 | return errors.Wrapf(err, "creating directory at %s", path) |
| 68 | } |
| 69 | |
| 70 | return nil |
| 71 | } |
| 72 | |
| 73 | // CopyDir copies a directory from src to dest, recursively copying nested |
| 74 | // directories |