internal/file/utils.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | //nolint:forbidigo // wrappers for os.File functions go here package file import ( "errors" "io/fs" "os" "github.com/Southclaws/fault" "github.com/Southclaws/fault/fmsg" ) func mkdirp(dir string) error { err := os.MkdirAll(dir, os.ModeDir|os.ModePerm) if err != nil { return fault.Wrap(err, fmsg.Withf("could not create directory %s", dir)) } return nil } func needNotExist(err error) error { if err != nil && !errors.Is(err, fs.ErrNotExist) { return fault.Wrap(err) } return nil } func statIfExists(file string) (fs.FileInfo, error) { stat, err := os.Stat(file) return stat, needNotExist(err) } func exists(file string) (bool, error) { stat, err := statIfExists(file) return stat != nil, err } |