Skip to content

Commit

Permalink
Last file search now handling repository. #13
Browse files Browse the repository at this point in the history
  • Loading branch information
soffokl committed May 19, 2016
1 parent 950a47a commit f026494
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apt/apt.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func Download(w http.ResponseWriter, r *http.Request) {
file = strings.TrimPrefix(r.RequestURI, "/kurjun/rest/apt/")
}
if file != "Packages" && file != "InRelease" && file != "Release" {
file = db.LastHash(file)
file = db.LastHash(file, "apt")
}
f, err := os.Open(config.Filepath + file)
if log.Check(log.WarnLevel, "Opening file "+config.Filepath+file, err) {
Expand Down
10 changes: 7 additions & 3 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,15 @@ func Search(query string) map[string]string {
return list
}

func LastHash(name string) (hash string) {
func LastHash(name, t string) (hash string) {
db.View(func(tx *bolt.Tx) error {
if b := tx.Bucket(search).Bucket([]byte(name)); b != nil {
_, v := b.Cursor().Last()
hash = string(v)
c := b.Cursor()
for k, v := c.Last(); k != nil; k, v = c.Prev() {
if t == "" || t == Info(string(v))["type"] {
hash = string(v)
}
}
}
return nil
})
Expand Down
4 changes: 2 additions & 2 deletions download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Handler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Please specify hash or name"))
return
} else if len(name) != 0 {
hash = db.LastHash(name)
hash = db.LastHash(name, "")
}

f, err := os.Open(path + hash)
Expand Down Expand Up @@ -150,7 +150,7 @@ func Info(repo string, r *http.Request) []byte {
}

if name == strings.Split(info["name"], "-subutai-template")[0] || name == info["name"] {
if (len(version) == 0 || info["version"] == version) && k == db.LastHash(info["name"]) {
if (len(version) == 0 || info["version"] == version) && k == db.LastHash(info["name"], info["type"]) {
if rtype == "text" {
return ([]byte("public." + k))
} else {
Expand Down

0 comments on commit f026494

Please sign in to comment.