From 1419b6c5ca04f78e336c4f70a5054dd9a9eb7bc7 Mon Sep 17 00:00:00 2001 From: Michael Nelson Date: Thu, 29 Sep 2016 09:53:30 +0000 Subject: [PATCH] Rename the env var switch for deltas to use SNAPD_ prefix. Add more context to delta-related error message. --- store/store.go | 8 ++++---- store/store_test.go | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/store/store.go b/store/store.go index 3f1fe224318..a79680b577f 100644 --- a/store/store.go +++ b/store/store.go @@ -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, } @@ -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) @@ -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) diff --git a/store/store_test.go b/store/store_test.go index 4cdd2aa0d39..486dad5607d 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -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 { @@ -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 @@ -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`) @@ -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, ``)