diff options
author | zeripath <art27@cantab.net> | 2020-11-28 02:42:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-27 21:42:08 -0500 |
commit | 742e21aeba5c02935269a2a3681f4486019ce542 (patch) | |
tree | e1572ab13c33dec1238321170a90d42851ae4ca2 /services | |
parent | 5b75f17043bc2a6d0e753ae5c9c6759adad5aaac (diff) | |
download | gitea-742e21aeba5c02935269a2a3681f4486019ce542.tar.gz gitea-742e21aeba5c02935269a2a3681f4486019ce542.zip |
Handle and propagate errors when checking if paths are Dirs, Files or Exist (#13186)
* Ensure errors from IsDir propagate
* Handle errors when checking IsFile
* Handle and propagate errors from IsExist
* Update modules/templates/static.go
* Update modules/templates/static.go
* Return after ctx.ServerError
* Apply suggestions from code review
* Fix tests
The previous merge managed to break repo_form.go
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'services')
-rw-r--r-- | services/archiver/archiver.go | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/services/archiver/archiver.go b/services/archiver/archiver.go index 4dd84524ca..359fc8b627 100644 --- a/services/archiver/archiver.go +++ b/services/archiver/archiver.go @@ -21,8 +21,7 @@ import ( "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - - "github.com/unknwon/com" + "code.gitea.io/gitea/modules/util" ) // ArchiveRequest defines the parameters of an archive request, which notably @@ -138,7 +137,12 @@ func DeriveRequestFrom(ctx *context.Context, uri string) *ArchiveRequest { } r.refName = strings.TrimSuffix(r.uri, r.ext) - if !com.IsDir(r.archivePath) { + isDir, err := util.IsDir(r.archivePath) + if err != nil { + ctx.ServerError("Download -> util.IsDir(archivePath)", err) + return nil + } + if !isDir { if err := os.MkdirAll(r.archivePath, os.ModePerm); err != nil { ctx.ServerError("Download -> os.MkdirAll(archivePath)", err) return nil @@ -146,9 +150,6 @@ func DeriveRequestFrom(ctx *context.Context, uri string) *ArchiveRequest { } // Get corresponding commit. - var ( - err error - ) if r.repo.IsBranchExist(r.refName) { r.commit, err = r.repo.GetBranchCommit(r.refName) if err != nil { @@ -179,7 +180,11 @@ func DeriveRequestFrom(ctx *context.Context, uri string) *ArchiveRequest { } r.archivePath = path.Join(r.archivePath, base.ShortSha(r.commit.ID.String())+r.ext) - r.archiveComplete = com.IsFile(r.archivePath) + r.archiveComplete, err = util.IsFile(r.archivePath) + if err != nil { + ctx.ServerError("util.IsFile", err) + return nil + } return r } @@ -198,7 +203,11 @@ func doArchive(r *ArchiveRequest) { // race conditions and difficulties in locking. Do one last check that // the archive we're referring to doesn't already exist. If it does exist, // then just mark the request as complete and move on. - if com.IsFile(r.archivePath) { + isFile, err := util.IsFile(r.archivePath) + if err != nil { + log.Error("Unable to check if %s util.IsFile: %v. Will ignore and recreate.", r.archivePath, err) + } + if isFile { r.archiveComplete = true return } |