Skip to content

Commit 771f819

Browse files
authored
Merge pull request #29 from rande/fix_static_error
fix(static): fix error management
2 parents 668aabf + 40a5fd3 commit 771f819

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

mirror/static/static.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,18 @@ func (gs *StaticService) Serve(state *goapp.GoroutineState) error {
7474
}
7575

7676
func (gs *StaticService) WriteArchive(w io.Writer, path string) (*StaticFile, error) {
77-
logger := gs.Logger.WithFields(log.Fields{
78-
"path": path,
79-
"action": "WriteArchive",
80-
})
81-
8277
vaultKey := fmt.Sprintf("%s", path)
8378
bucketKey := vaultKey
84-
8579
url := fmt.Sprintf("%s/%s", gs.Config.SourceServer, path)
8680

81+
logger := gs.Logger.WithFields(log.Fields{
82+
"path": path,
83+
"action": "WriteArchive",
84+
"vaultKey": vaultKey,
85+
"bucketKey": bucketKey,
86+
"url": url,
87+
})
88+
8789
file := &StaticFile{}
8890

8991
err := gs.DB.View(func(tx *bolt.Tx) error {
@@ -104,7 +106,7 @@ func (gs *StaticService) WriteArchive(w io.Writer, path string) (*StaticFile, er
104106

105107
if err == pkgmirror.EmptyDataError {
106108
file.Url = url
107-
} else {
109+
} else if err != nil {
108110
return nil, err
109111
}
110112

@@ -163,6 +165,8 @@ func (gs *StaticService) WriteArchive(w io.Writer, path string) (*StaticFile, er
163165

164166
return nil
165167
})
168+
} else {
169+
logger.Info("Vault entry exist!")
166170
}
167171

168172
logger.Info("Read vault entry")

mirror/static/static_app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
package static
77

88
import (
9+
"bytes"
910
"fmt"
1011
"net/http"
1112

12-
"bytes"
13-
1413
log "github.com/Sirupsen/logrus"
1514
"github.com/rande/goapp"
1615
"github.com/rande/gonode/core/vault"
@@ -109,6 +108,7 @@ func ConfigureHttp(name string, conf *pkgmirror.StaticConfig, app *goapp.App) {
109108

110109
pkgmirror.SendWithHttpCode(w, code, err.Error())
111110
} else {
111+
112112
// copy header
113113
for name := range file.Header {
114114
if name == "Content-Length" {

test/mirror/static_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ func Test_Static_Get_Valid_File(t *testing.T) {
2525
assert.Equal(t, "This is a sample test file.", string(res.GetBody()))
2626

2727
// get the proxied file
28+
res, err = test.RunRequest("GET", fmt.Sprintf("%s/static/static/file.txt", args.TestServer.URL))
29+
30+
assert.NoError(t, err)
31+
assert.Equal(t, 200, res.StatusCode)
32+
assert.Equal(t, "This is a sample test file.", string(res.GetBody()))
2833

34+
// test if the second time the code work fine (using the cache)
2935
res, err = test.RunRequest("GET", fmt.Sprintf("%s/static/static/file.txt", args.TestServer.URL))
3036

3137
assert.NoError(t, err)

0 commit comments

Comments
 (0)