Skip to content

Commit

Permalink
Rename the env var switch for deltas to use SNAPD_ prefix.
Browse files Browse the repository at this point in the history
Add more context to delta-related error message.
  • Loading branch information
Michael Nelson committed Sep 29, 2016
1 parent 975a477 commit 1419b6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ func (s *Store) ListRefresh(installed []*RefreshCandidate, user *auth.UserState)
Data: jsonData,
}

if os.Getenv("SNAPPY_USE_DELTAS_EXPERIMENTAL") == "1" {
if os.Getenv("SNAPD_USE_DELTAS_EXPERIMENTAL") == "1" {
reqOptions.ExtraHeaders = map[string]string{
"X-Ubuntu-Delta-Formats": s.deltaFormat,
}
Expand Down Expand Up @@ -1133,7 +1133,7 @@ func (s *Store) Download(name string, downloadInfo *snap.DownloadInfo, pbar prog
}
}()

if os.Getenv("SNAPPY_USE_DELTAS_EXPERIMENTAL") == "1" && len(downloadInfo.Deltas) == 1 {
if os.Getenv("SNAPD_USE_DELTAS_EXPERIMENTAL") == "1" && len(downloadInfo.Deltas) == 1 {
downloadDir, err := ioutil.TempDir("", name+"-deltas")
if err == nil {
defer os.RemoveAll(downloadDir)
Expand Down Expand Up @@ -1219,13 +1219,13 @@ var download = func(name, downloadURL string, user *auth.UserState, s *Store, w
func (s *Store) downloadDelta(name string, downloadDir string, downloadInfo *snap.DownloadInfo, pbar progress.Meter, user *auth.UserState) (string, error) {

if len(downloadInfo.Deltas) != 1 {
return "", errors.New("store returned more than one delta")
return "", errors.New("store returned more than one download delta")
}

deltaInfo := downloadInfo.Deltas[0]

if deltaInfo.Format != s.deltaFormat {
return "", fmt.Errorf("store returned delta with format %q", deltaInfo.Format)
return "", fmt.Errorf("store returned a download delta with the wrong format (%q instead of the configured %s format)", deltaInfo.Format, s.deltaFormat)
}

deltaName := fmt.Sprintf("%s_%d_%d_delta.%s", name, deltaInfo.FromRevision, deltaInfo.ToRevision, deltaInfo.Format)
Expand Down
24 changes: 12 additions & 12 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ var deltaTests = []struct {
}}

func (t *remoteRepoTestSuite) TestDownloadWithDeltas(c *C) {
origUseDeltas := os.Getenv("SNAPPY_USE_DELTAS_EXPERIMENTAL")
defer os.Setenv("SNAPPY_USE_DELTAS_EXPERIMENTAL", origUseDeltas)
c.Assert(os.Setenv("SNAPPY_USE_DELTAS_EXPERIMENTAL", "1"), IsNil)
origUseDeltas := os.Getenv("SNAPD_USE_DELTAS_EXPERIMENTAL")
defer os.Setenv("SNAPD_USE_DELTAS_EXPERIMENTAL", origUseDeltas)
c.Assert(os.Setenv("SNAPD_USE_DELTAS_EXPERIMENTAL", "1"), IsNil)

for _, testCase := range deltaTests {

Expand Down Expand Up @@ -531,9 +531,9 @@ var downloadDeltaTests = []struct {
}}

func (t *remoteRepoTestSuite) TestDownloadDelta(c *C) {
origUseDeltas := os.Getenv("SNAPPY_USE_DELTAS_EXPERIMENTAL")
defer os.Setenv("SNAPPY_USE_DELTAS_EXPERIMENTAL", origUseDeltas)
c.Assert(os.Setenv("SNAPPY_USE_DELTAS_EXPERIMENTAL", "1"), IsNil)
origUseDeltas := os.Getenv("SNAPD_USE_DELTAS_EXPERIMENTAL")
defer os.Setenv("SNAPD_USE_DELTAS_EXPERIMENTAL", origUseDeltas)
c.Assert(os.Setenv("SNAPD_USE_DELTAS_EXPERIMENTAL", "1"), IsNil)

for _, testCase := range downloadDeltaTests {
t.store.deltaFormat = testCase.format
Expand Down Expand Up @@ -1845,9 +1845,9 @@ var MockUpdatesWithDeltasJSON = `
`

func (t *remoteRepoTestSuite) TestUbuntuStoreRepositoryListRefreshWithDeltas(c *C) {
origUseDeltas := os.Getenv("SNAPPY_USE_DELTAS_EXPERIMENTAL")
defer os.Setenv("SNAPPY_USE_DELTAS_EXPERIMENTAL", origUseDeltas)
c.Assert(os.Setenv("SNAPPY_USE_DELTAS_EXPERIMENTAL", "1"), IsNil)
origUseDeltas := os.Getenv("SNAPD_USE_DELTAS_EXPERIMENTAL")
defer os.Setenv("SNAPD_USE_DELTAS_EXPERIMENTAL", origUseDeltas)
c.Assert(os.Setenv("SNAPD_USE_DELTAS_EXPERIMENTAL", "1"), IsNil)

mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c.Check(r.Header.Get("X-Ubuntu-Delta-Formats"), Equals, `xdelta`)
Expand Down Expand Up @@ -1920,9 +1920,9 @@ func (t *remoteRepoTestSuite) TestUbuntuStoreRepositoryListRefreshWithDeltas(c *

func (t *remoteRepoTestSuite) TestUbuntuStoreRepositoryListRefreshWithoutDeltas(c *C) {
// Verify the X-Delta-Format header is not set.
origUseDeltas := os.Getenv("SNAPPY_USE_DELTAS_EXPERIMENTAL")
defer os.Setenv("SNAPPY_USE_DELTAS_EXPERIMENTAL", origUseDeltas)
c.Assert(os.Setenv("SNAPPY_USE_DELTAS_EXPERIMENTAL", "0"), IsNil)
origUseDeltas := os.Getenv("SNAPD_USE_DELTAS_EXPERIMENTAL")
defer os.Setenv("SNAPD_USE_DELTAS_EXPERIMENTAL", origUseDeltas)
c.Assert(os.Setenv("SNAPD_USE_DELTAS_EXPERIMENTAL", "0"), IsNil)

mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c.Check(r.Header.Get("X-Ubuntu-Delta-Formats"), Equals, ``)
Expand Down

0 comments on commit 1419b6c

Please sign in to comment.