daemon,overlord,snap,tests: download to .partial in final dir #2237

Merged
merged 6 commits into from Nov 1, 2016

Conversation

Projects
None yet
3 participants
Collaborator

mvo5 commented Nov 1, 2016

This branch makes snap download and snap prepare-image work as a user again. While the goal is similar to #2205 this approach uses a "$final.partial" approach instead of going into a "partial" directory.

The branch is relatively big, mostly because:
a) we reverse the way download works, before Download() would tells us where stuff got download, now we tell Download() where to download to
b) the downloaded files end up in the final place, so we don't need to copy/rename the downloaded files.

Slightly risky because of this. #2205 might be safer.

store/store.go
deltaInfo := &downloadInfo.Deltas[0]
- workingDir, err := ioutil.TempDir(dirs.SnapPartialBlobDir, "deltas-"+name)
+ // use /var/tmp here because it is not on a tmpfs
+ workingDir, err := ioutil.TempDir("/var/tmp", "deltas-"+name)
@chipaca

chipaca Nov 1, 2016

Member

in the spirit of .partial, this could be targetFn + ".deltas"

@niemeyer

niemeyer Nov 1, 2016

Contributor

Indeed. It'll also be better to not even create this directory. Using the same logic as above, we can use targetFn + ".delta.partial" in the final directory. If this ends up being a bit confusing, let's please just nuke the whole delta logic. This is experimental anyway and we can easily reintroduce on the next release.

@mvo5

mvo5 Nov 1, 2016

Collaborator

Thanks, removed for now

overlord/snapstate/flags.go
@@ -32,8 +32,8 @@ type Flags struct {
// Revert flags the SnapSetup as coming from a revert
Revert bool `json:"revert,omitempty"`
- // KeepSnapPath is used via InstallPath to flag that the file passed in is not temporary and should not be removed
- KeepSnapPath bool `json:"keep-snap-path,omitempty"`
+ // RemoveSnapPath is used via InstallPath to flag that the file passed in is not temporary and should not be removed
@niemeyer

niemeyer Nov 1, 2016

Contributor

Comment is still inverted.

@mvo5

mvo5 Nov 1, 2016

Collaborator

Thanks, fixed

store/store.go
+
+ if downloadInfo.Sha3_384 != "" && sha3_384 != downloadInfo.Sha3_384 {
+ // FIXME: find a better error message
+ return fmt.Errorf("hashsum mismatch for %s: got %s but expected %s", w.Name(), sha3_384, downloadInfo.Sha3_384)
@niemeyer

niemeyer Nov 1, 2016

Contributor

("sha3-384 mismatch downloading %s: got %s but expected %s", w.Name(), hash, downloadInfo.Sha3_384)

Note that this is different from the suggestion from the other PR, as here we can use the actual filename since it'll look nice (yay!).

@mvo5

mvo5 Nov 1, 2016

Collaborator

Thanks, updated.

store/store.go
}
// 3 pₙ₊₁ ≥ 5 pₙ; last entry should be 0 -- the sleep is done at the end of the loop
var downloadBackoffs = []int{113, 191, 331, 557, 929, 0}
// download writes an http.Request showing a progress.Meter
-var download = func(name, downloadURL string, user *auth.UserState, s *Store, w io.Writer, pbar progress.Meter) error {
+var download = func(name, downloadURL string, user *auth.UserState, s *Store, w io.Writer, pbar progress.Meter) (sha3_384 string, err error) {
@niemeyer

niemeyer Nov 1, 2016

Contributor

Same as the comment in the other PR, can we please revert the logic so we return the error above from within download, and pass the sha3-384 into download so it can do the comparison internally and report the error consistently for all cases.

@mvo5

mvo5 Nov 1, 2016

Collaborator

I moved the hash check into download(), the only small downside is that we can no longer show the real filename because we are only passing a io.Writer

store/store.go
deltaInfo := &downloadInfo.Deltas[0]
- workingDir, err := ioutil.TempDir(dirs.SnapPartialBlobDir, "deltas-"+name)
+ // use /var/tmp here because it is not on a tmpfs
+ workingDir, err := ioutil.TempDir("/var/tmp", "deltas-"+name)
@chipaca

chipaca Nov 1, 2016

Member

in the spirit of .partial, this could be targetFn + ".deltas"

@niemeyer

niemeyer Nov 1, 2016

Contributor

Indeed. It'll also be better to not even create this directory. Using the same logic as above, we can use targetFn + ".delta.partial" in the final directory. If this ends up being a bit confusing, let's please just nuke the whole delta logic. This is experimental anyway and we can easily reintroduce on the next release.

@mvo5

mvo5 Nov 1, 2016

Collaborator

Thanks, removed for now

@niemeyer niemeyer added the Critical label Nov 1, 2016

@niemeyer niemeyer changed the title from bugfix: use a .partial file in download to unbreak `snap download` as user to daemon,overlord,snap,tests: download to .partial in final dir Nov 1, 2016

Collaborator

mvo5 commented Nov 1, 2016

2016/11/02 01:06:54 Successful tasks: 273

Collaborator

mvo5 commented Nov 1, 2016

Travis was broken tonight, so I ran:

$ git status
On branch feature/partial-files-not-partial-dir
$GOPATH/bin/spread   -v  linode:
...
2016/11/02 01:06:54 Successful tasks: 273
2016/11/02 01:06:54 Aborted tasks: 0

@niemeyer niemeyer merged commit c4a7a27 into snapcore:master Nov 1, 2016

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment