Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

Commit

Permalink
fix: mkdir should comply with os.IsExist
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Meier committed Sep 30, 2021
1 parent d10b037 commit 2bd644f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ func (f *GormFs) Create(name string) (afero.File, error) {
}

func (f *GormFs) Mkdir(name string, perm fs.FileMode) error {
//fmt.Println("creating", name)
if f.exists(name) {
return &fs.PathError{Op: "mkdir", Path: name, Err: fs.ErrExist}
}
if !f.hasParent(name) {
return &fs.PathError{Op: "mkdir", Path: name, Err: fs.ErrNotExist} // FIXME: error parity with os
return &fs.PathError{Op: "mkdir", Path: name, Err: fs.ErrNotExist}
}
if err := f.db.Create(&File{Name: filepath.Clean(name), IsDir: true, Mode: perm | fs.ModeDir}).Error; err != nil {
return err
Expand All @@ -97,7 +99,7 @@ func (f *GormFs) MkdirAll(path string, perm fs.FileMode) error {
if f.exists(name) {
continue
}
if err := f.Mkdir(name, perm); err != nil {
if err := f.Mkdir(name, perm); err != nil && !os.IsExist(err) {
return err
}
}
Expand Down

0 comments on commit 2bd644f

Please sign in to comment.