diff options
author | blanet <moweng.xx@alibaba-inc.com> | 2021-09-07 11:57:58 +0300 |
---|---|---|
committer | blanet <moweng.xx@alibaba-inc.com> | 2021-10-12 11:33:41 +0300 |
commit | 24ea8ec77f5d44ef95bfcc26acb8fc13764028ac (patch) | |
tree | ce714a05904a6a48d527b2161f6aa022ab618045 /cmd | |
parent | 7ad2163843207dbeb29d852fa5567e905f940326 (diff) |
gitaly-git2go: Add dir validation in creating and moving file
This commit adds a new function `validatePathDoesNotExist` wrapping
`validateFileDoesNotExist` and `validateDirectoryDoesNotExist` to ensure
the path of the target does not exist before operating, which is helpful
for actions including `CreateDirectory`, `CreateFile` and `MoveFile`.
Signed-off-by: blanet <moweng.xx@alibaba-inc.com>
Changelog: fixed
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/gitaly-git2go/commit/create_directory.go | 4 | ||||
-rw-r--r-- | cmd/gitaly-git2go/commit/create_file.go | 2 | ||||
-rw-r--r-- | cmd/gitaly-git2go/commit/move_file.go | 2 | ||||
-rw-r--r-- | cmd/gitaly-git2go/commit/validate.go | 10 |
4 files changed, 13 insertions, 5 deletions
diff --git a/cmd/gitaly-git2go/commit/create_directory.go b/cmd/gitaly-git2go/commit/create_directory.go index 226db4eaa..1a471d217 100644 --- a/cmd/gitaly-git2go/commit/create_directory.go +++ b/cmd/gitaly-git2go/commit/create_directory.go @@ -12,9 +12,7 @@ import ( ) func applyCreateDirectory(action git2go.CreateDirectory, repo *git.Repository, index *git.Index) error { - if err := validateFileDoesNotExist(index, action.Path); err != nil { - return err - } else if err := validateDirectoryDoesNotExist(index, action.Path); err != nil { + if err := validatePathDoesNotExist(index, action.Path); err != nil { return err } diff --git a/cmd/gitaly-git2go/commit/create_file.go b/cmd/gitaly-git2go/commit/create_file.go index 5fac3a01a..b3502d73b 100644 --- a/cmd/gitaly-git2go/commit/create_file.go +++ b/cmd/gitaly-git2go/commit/create_file.go @@ -9,7 +9,7 @@ import ( ) func applyCreateFile(action git2go.CreateFile, index *git.Index) error { - if err := validateFileDoesNotExist(index, action.Path); err != nil { + if err := validatePathDoesNotExist(index, action.Path); err != nil { return err } diff --git a/cmd/gitaly-git2go/commit/move_file.go b/cmd/gitaly-git2go/commit/move_file.go index de2ae3444..932e7f854 100644 --- a/cmd/gitaly-git2go/commit/move_file.go +++ b/cmd/gitaly-git2go/commit/move_file.go @@ -18,7 +18,7 @@ func applyMoveFile(action git2go.MoveFile, index *git.Index) error { return err } - if err := validateFileDoesNotExist(index, action.NewPath); err != nil { + if err := validatePathDoesNotExist(index, action.NewPath); err != nil { return err } diff --git a/cmd/gitaly-git2go/commit/validate.go b/cmd/gitaly-git2go/commit/validate.go index b7a2a9fad..1b36cbcc7 100644 --- a/cmd/gitaly-git2go/commit/validate.go +++ b/cmd/gitaly-git2go/commit/validate.go @@ -22,6 +22,16 @@ func validateFileExists(index *git.Index, path string) error { return nil } +func validatePathDoesNotExist(index *git.Index, path string) error { + if err := validateFileDoesNotExist(index, path); err != nil { + return err + } + if err := validateDirectoryDoesNotExist(index, path); err != nil { + return err + } + return nil +} + func validateFileDoesNotExist(index *git.Index, path string) error { _, err := index.Find(path) if err == nil { |