diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eef4ebb..0eab408 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,6 +19,7 @@ glide-install: - mkdir -p build/i386 build/amd64 build/armv7 cache: key: "pipeline-$CI_PIPELINE_ID" + policy: push paths: - src/meow.tf/deb-simple/vendor diff --git a/src/meow.tf/deb-simple/config.go b/src/meow.tf/deb-simple/config.go index 75235e9..f64828e 100644 --- a/src/meow.tf/deb-simple/config.go +++ b/src/meow.tf/deb-simple/config.go @@ -48,7 +48,7 @@ func (c Conf) PoolPackagePath(distro, arch, name string) string { func (c Conf) RelativePoolPackagePath(distro, arch, name string) string { name = packageName(name) - return path.Join(c.Repo.Root, "pool/main", distro, arch, name[0:1], name) + return path.Join("pool/main", distro, arch, name[0:1], name) } func (c RepoConf) DistroNames() []string { diff --git a/src/meow.tf/deb-simple/http.go b/src/meow.tf/deb-simple/http.go index cdd26ae..23645c8 100644 --- a/src/meow.tf/deb-simple/http.go +++ b/src/meow.tf/deb-simple/http.go @@ -172,8 +172,13 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { f.Path = path.Join(conf.RelativePoolPackagePath(distroName, archType, f.Info.Package), part.FileName()) - if err := os.Rename(tempFile, path.Join(newPath, part.FileName())); err != nil { - httpErrorf(w, "error moving temporary file: %s", err) + if err := copyFile(tempFile, path.Join(newPath, part.FileName())); err != nil { + httpErrorf(w, "error copying temporary file: %s", err) + return + } + + if err := os.Remove(tempFile); err != nil { + httpErrorf(w, "unable to remove temporary file: %s", err) return } diff --git a/src/meow.tf/deb-simple/packages.go b/src/meow.tf/deb-simple/packages.go index aaadef0..5095e18 100644 --- a/src/meow.tf/deb-simple/packages.go +++ b/src/meow.tf/deb-simple/packages.go @@ -180,6 +180,8 @@ func newPackageFile(filePath string) (*PackageFile, error) { return nil, err } + defer f.Close() + var ( md5hash = md5.New() sha1hash = sha1.New() diff --git a/src/meow.tf/deb-simple/server.go b/src/meow.tf/deb-simple/server.go index d067b05..a610b2e 100644 --- a/src/meow.tf/deb-simple/server.go +++ b/src/meow.tf/deb-simple/server.go @@ -13,6 +13,7 @@ import ( "runtime" "errors" "github.com/go-ini/ini" + "io" ) var VERSION string = "1.3.3" @@ -190,4 +191,26 @@ func stripPrefix(str, prefix string) string { return strings.TrimLeft(str[len(prefix):], "/") } return str +} + +func copyFile(oldPath, newPath string) error { + old, err := os.Open(oldPath) + + if err != nil { + return err + } + + defer old.Close() + + n, err := os.Create(newPath) + + if err != nil { + return err + } + + defer n.Close() + + _, err = io.Copy(n, old) + + return err } \ No newline at end of file