-
Notifications
You must be signed in to change notification settings - Fork 1
/
mount_blob.go
58 lines (48 loc) · 1.16 KB
/
mount_blob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package server
import (
"log"
"net/http"
"os"
"path"
"github.com/gorilla/mux"
)
func mountBlob(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
log.Printf("Mount Blob: %#v\n", vars)
_, ok := vars["imagename"]
if !ok {
w.WriteHeader(404)
return
}
sumType, ok := vars["sumtype"]
if !ok {
w.WriteHeader(404)
return
}
sum, ok := vars["sum"]
if !ok {
w.WriteHeader(404)
return
}
prefix1, prefix2 := sum[:2], sum[2:4]
blobPath := path.Join(blobsDirectory, sumType, prefix1, prefix2, sum)
fileInfo, err := os.Lstat(blobPath)
if err != nil {
errStatus := 500
if os.IsNotExist(err) {
// The blob does not exist. Indicate to the client that they should upload it.
errStatus = 300
}
log.Printf("unable to open blob file %q: %s\n", blobPath, err)
w.WriteHeader(errStatus)
return
}
if !fileInfo.Mode().IsRegular() {
log.Printf("unable to associate blob file %q: not a regular file", blobPath)
w.WriteHeader(500)
return
}
// The blob exists and is a regular file! On this naive server, that's OK.
// We don't really have access control lists to worry about, everything is public.
// TODO: return some content.
}