gapi, lang: gapi: Make dir to avoid errors

It seems we sometimes need to make the intermediate dir.
This commit is contained in:
James Shubin
2025-01-17 23:25:06 -05:00
parent a713c08585
commit b392285e1d
2 changed files with 11 additions and 0 deletions

View File

@@ -89,3 +89,9 @@ func CopyDirToFsForceAll(fs engine.Fs, src, dst string) error {
func CopyDirContentsToFs(fs engine.Fs, src, dst string) error { func CopyDirContentsToFs(fs engine.Fs, src, dst string) error {
return util.CopyDiskContentsToFs(fs, src, dst, false) return util.CopyDiskContentsToFs(fs, src, dst, false)
} }
// MkdirAllOnFs writes a dir to a dst path on fs. It makes the parent dirs if
// they don't exist.
func MkdirAllOnFs(fs engine.WriteableFS, dst string, perm os.FileMode) error {
return fs.MkdirAll(dst, perm)
}

View File

@@ -463,6 +463,11 @@ func (obj *GAPI) Cli(info *gapi.Info) (*gapi.Deploy, error) {
continue continue
} }
// it's a regular file path // it's a regular file path
// Occasionally, we need the dir to exist first or we'll error.
if err := gapi.MkdirAllOnFs(writeableFS, util.Dirname(dst), 0700); err != nil {
return nil, errwrap.Wrapf(err, "can't mkdir at `%s`", dst)
}
if err := gapi.CopyFileToFs(writeableFS, src, dst); err != nil { if err := gapi.CopyFileToFs(writeableFS, src, dst); err != nil {
return nil, errwrap.Wrapf(err, "can't copy file from `%s` to `%s`", src, dst) return nil, errwrap.Wrapf(err, "can't copy file from `%s` to `%s`", src, dst)
} }