From bb991a538d65f192d7c25c53917533aad9f728b9 Mon Sep 17 00:00:00 2001 From: Tyler Date: Wed, 13 Sep 2017 23:57:03 -0400 Subject: [PATCH] Fix temporary file uploads --- src/meow.tf/deb-simple/deb/archive/archive.go | 1 + src/meow.tf/deb-simple/http.go | 2 +- src/meow.tf/deb-simple/packages.go | 16 +++++++--------- src/meow.tf/deb-simple/server.go | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/meow.tf/deb-simple/deb/archive/archive.go b/src/meow.tf/deb-simple/deb/archive/archive.go index 198a762..90f6205 100644 --- a/src/meow.tf/deb-simple/deb/archive/archive.go +++ b/src/meow.tf/deb-simple/deb/archive/archive.go @@ -14,6 +14,7 @@ import ( func InspectPackage(filename string) (string, error) { f, err := os.Open(filename) + if err != nil { return "", fmt.Errorf("error opening package file %s: %s", filename, err) } diff --git a/src/meow.tf/deb-simple/http.go b/src/meow.tf/deb-simple/http.go index c74139a..c964e60 100644 --- a/src/meow.tf/deb-simple/http.go +++ b/src/meow.tf/deb-simple/http.go @@ -127,7 +127,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { dst.Close() // Get package name, if it already exists remove the old file. - f, err := newPackageFile(tempFile, part.FileName()) + f, err := newPackageFile(tempFile) if err != nil { httpErrorf(w, "error loading package info: %s", err) diff --git a/src/meow.tf/deb-simple/packages.go b/src/meow.tf/deb-simple/packages.go index 00ee52b..aaadef0 100644 --- a/src/meow.tf/deb-simple/packages.go +++ b/src/meow.tf/deb-simple/packages.go @@ -132,7 +132,7 @@ func scanRecursive(base string, m map[string]*PackageFile) error { continue } - p, err := newPackageFile(base, file.Name()) + p, err := newPackageFile(path.Join(base, file.Name())) if err != nil { return err @@ -154,17 +154,15 @@ func scanRecursive(base string, m map[string]*PackageFile) error { return nil } -func newPackageFile(base, name string) (*PackageFile, error) { +func newPackageFile(filePath string) (*PackageFile, error) { p := &PackageFile{ - Name: name, - Path: path.Join(stripPrefix(base, conf.Repo.Root), name), + Name: path.Base(filePath), + Path: stripPrefix(filePath, conf.Repo.Root), } - debPath := path.Join(base, name) - var err error - p.ControlData, err = archive.InspectPackage(debPath) + p.ControlData, err = archive.InspectPackage(filePath) if err != nil { return nil, err @@ -172,11 +170,11 @@ func newPackageFile(base, name string) (*PackageFile, error) { p.Info = parsePackageData(p.ControlData) - if stat, err := os.Stat(debPath); err == nil { + if stat, err := os.Stat(filePath); err == nil { p.Size = stat.Size() } - f, err := os.Open(debPath) + f, err := os.Open(filePath) if err != nil { return nil, err diff --git a/src/meow.tf/deb-simple/server.go b/src/meow.tf/deb-simple/server.go index a78c2c9..fd5c8c9 100644 --- a/src/meow.tf/deb-simple/server.go +++ b/src/meow.tf/deb-simple/server.go @@ -15,7 +15,7 @@ import ( "github.com/go-ini/ini" ) -var VERSION string = "1.3.1" +var VERSION string = "1.3.2" func packageName(name string) string { if index := strings.Index(name, "_"); index != -1 {