Fix temporary file issues

This commit is contained in:
Tyler 2017-09-14 00:23:39 -04:00
parent 7d59377309
commit 78171c86c0
5 changed files with 34 additions and 3 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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
}

View File

@ -180,6 +180,8 @@ func newPackageFile(filePath string) (*PackageFile, error) {
return nil, err
}
defer f.Close()
var (
md5hash = md5.New()
sha1hash = sha1.New()

View File

@ -13,6 +13,7 @@ import (
"runtime"
"errors"
"github.com/go-ini/ini"
"io"
)
var VERSION string = "1.3.3"
@ -191,3 +192,25 @@ func stripPrefix(str, prefix string) string {
}
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
}