eventmanager: don't fail if a directory to be created already exists
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
4cd340e07f
commit
78f75cdcb9
2 changed files with 20 additions and 11 deletions
|
@ -589,17 +589,18 @@ func executeDeleteFsAction(deletes []string, replacer *strings.Replacer, usernam
|
||||||
if conn.IsNotExistError(err) {
|
if conn.IsNotExistError(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return err
|
return fmt.Errorf("unable to check item to delete %q, user %q: %w", item, user.Username, err)
|
||||||
}
|
}
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
if err = conn.RemoveDir(item); err != nil {
|
if err = conn.RemoveDir(item); err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to remove dir %q, user %q: %w", item, user.Username, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = executeDeleteFileFsAction(conn, item, info); err != nil {
|
if err = executeDeleteFileFsAction(conn, item, info); err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to remove file %q, user %q: %w", item, user.Username, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
eventManagerLog(logger.LevelDebug, "item %q removed for user %q", item, user.Username)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -619,11 +620,12 @@ func executeMkDirsFsAction(dirs []string, replacer *strings.Replacer, username s
|
||||||
for _, item := range dirs {
|
for _, item := range dirs {
|
||||||
item = replaceWithReplacer(item, replacer)
|
item = replaceWithReplacer(item, replacer)
|
||||||
if err = conn.CheckParentDirs(path.Dir(item)); err != nil {
|
if err = conn.CheckParentDirs(path.Dir(item)); err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to check parent dirs for %q, user %q: %w", item, user.Username, err)
|
||||||
}
|
}
|
||||||
if err = conn.CreateDir(item, false); err != nil {
|
if err = conn.createDirIfMissing(item); err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to create dir %q, user %q: %w", item, user.Username, err)
|
||||||
}
|
}
|
||||||
|
eventManagerLog(logger.LevelDebug, "directory %q created for user %q", item, user.Username)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -644,8 +646,9 @@ func executeRenameFsAction(renames []dataprovider.KeyValue, replacer *strings.Re
|
||||||
source := replaceWithReplacer(item.Key, replacer)
|
source := replaceWithReplacer(item.Key, replacer)
|
||||||
target := replaceWithReplacer(item.Value, replacer)
|
target := replaceWithReplacer(item.Value, replacer)
|
||||||
if err = conn.Rename(source, target); err != nil {
|
if err = conn.Rename(source, target); err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to rename %q->%q, user %q: %w", source, target, user.Username, err)
|
||||||
}
|
}
|
||||||
|
eventManagerLog(logger.LevelDebug, "rename %q->%q ok, user %q", source, target, user.Username)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -790,12 +790,18 @@ func TestFilesystemActionErrors(t *testing.T) {
|
||||||
err = os.Chmod(dirPath, 0555)
|
err = os.Chmod(dirPath, 0555)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = executeDeleteFsAction([]string{"/adir/sub/f.dat"}, testReplacer, username)
|
err = executeDeleteFsAction([]string{"/adir/sub/f.dat"}, testReplacer, username)
|
||||||
assert.Error(t, err)
|
if assert.Error(t, err) {
|
||||||
|
assert.Contains(t, err.Error(), "unable to remove file")
|
||||||
|
}
|
||||||
|
|
||||||
err = executeMkDirsFsAction([]string{"/adir/sub"}, testReplacer, username)
|
err = executeMkDirsFsAction([]string{"/adir/sub/sub"}, testReplacer, username)
|
||||||
assert.Error(t, err)
|
if assert.Error(t, err) {
|
||||||
|
assert.Contains(t, err.Error(), "unable to create dir")
|
||||||
|
}
|
||||||
err = executeMkDirsFsAction([]string{"/adir/sub/sub/sub"}, testReplacer, username)
|
err = executeMkDirsFsAction([]string{"/adir/sub/sub/sub"}, testReplacer, username)
|
||||||
assert.Error(t, err)
|
if assert.Error(t, err) {
|
||||||
|
assert.Contains(t, err.Error(), "unable to check parent dirs")
|
||||||
|
}
|
||||||
|
|
||||||
err = os.Chmod(dirPath, os.ModePerm)
|
err = os.Chmod(dirPath, os.ModePerm)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
Loading…
Reference in a new issue