Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
When artifacts uploaded to APT repo, deb files storing without extension

Rename old deb files. Changed APT saving on filesystem
  • Loading branch information
emli committed Feb 21, 2018
1 parent 70f6f8f commit 6cbeaea
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions apt/apt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/mkrautz/goar"
"github.com/subutai-io/agent/log"
"os/exec"
)

func readDeb(hash string) (control bytes.Buffer, err error) {
Expand Down Expand Up @@ -128,6 +129,8 @@ func Upload(w http.ResponseWriter, r *http.Request) {
db.Write(owner, md5, header.Filename, meta)
w.Write([]byte(md5))
log.Info(meta["Filename"] + " saved to apt repo by " + owner)
os.Rename(config.Storage.Path+md5, config.Storage.Path+header.Filename)
generateReleaseFile()
}
}

Expand All @@ -136,10 +139,6 @@ func Download(w http.ResponseWriter, r *http.Request) {
if len(file) == 0 {
file = strings.TrimPrefix(r.RequestURI, "/kurjun/rest/apt/")
}
if file != "Packages" && file != "InRelease" && file != "Release" {
file = db.LastHash(file, "apt")
}

if f, err := os.Open(config.Storage.Path + file); err == nil && file != "" {
defer f.Close()
io.Copy(w, f)
Expand Down Expand Up @@ -217,9 +216,40 @@ func Delete(w http.ResponseWriter, r *http.Request) {
}

func Info(w http.ResponseWriter, r *http.Request) {
renameOldDebFiles()
if info := download.Info("apt", r); len(info) != 0 {
w.Write(info)
return
}
w.Write([]byte("Not found"))
}

func renameOldDebFiles() {
list := db.Search("")
for _, k := range list {
if db.CheckRepo("", "apt", k) == 0 {
continue
}
item := download.FormatItem(db.Info(k), "apt", "")
os.Rename(config.Storage.Path+item.Hash.Md5, config.Storage.Path+item.Name)
}
}

func generateReleaseFile() {
cmd := exec.Command("bash", "-c", "dpkg-scanpackages . /dev/null | tee Packages | gzip > Packages.gz")
cmd.Dir = config.Storage.Path
err := cmd.Run()
if err != nil {
log.Fatal(err)
panic("Can't run dpkg-scanpackages")
}

cmd = exec.Command("bash", "-c", "apt-ftparchive release . > Release")
cmd.Dir = config.Storage.Path
err = cmd.Run()
if err != nil {
log.Fatal(err)
panic("Can't run apt-ftparchive")
}

}

0 comments on commit 6cbeaea

Please sign in to comment.