whyrusleeping / gx

A package management tool
MIT License
1.88k stars 110 forks source link

[WIP] get: try to remove destination directory before renaming download #162

Closed schomatis closed 6 years ago

schomatis commented 6 years ago

If the package.json file is missing from an installed package (not very likely) fetch will fail while trying to rename to an existing directory.

rm ~/go/src/gx/ipfs/QmdbxjQWogRCHRaxhhGnYdT1oQJzL9GdqSKzCdqWr85AP2/pubsub/package.json
gx install
# ERROR: [97 / 97 ] parallel fetch: failed to fetch package: QmdbxjQWogRCHRaxhhGnYdT1oQJzL9GdqSKzCdqWr85AP2: rename go/src/gx/ipfs/QmdbxjQWogRCHRaxhhGnYdT1oQJzL9GdqSKzCdqWr85AP2.part go/src/gx/ipfs/QmdbxjQWogRCHRaxhhGnYdT1oQJzL9GdqSKzCdqWr85AP2: file exists
# ERROR: install deps: failed to fetch dependencies

Should a test be added?

djdv commented 6 years ago

@schomatis I created a similar patch to this https://github.com/whyrusleeping/gx/pull/163 It moves the check up so it only tries to remove when proven to exist and also removes an uneeded dependency.

Sorry for the overlap, I came across this independently when I got frustrated with an ambiguous "Access is denied" error. I didn't see this pull request when I started.

I can instigating failure by doing this inside of the go-ipfs repo

gx install --local
git clean -fdx
gx install --local

git clean -fdx was not removing any packages with tests in them which caused the problem when trying to move the temporary to the target.

whyrusleeping commented 6 years ago

@schomatis sorry I didnt see this one either. I'm merging @djdv's PR as both of these fixes work, but he points out that go's os package now properly does the rename, we no longer need the gorename package.

thank you for the PR!

schomatis commented 6 years ago

@djdv No problem, I'm closing this PR as I like your solution more, it employs the standard library and handles the existence of the destination in a logically coherent place: next to the original check of FindPackageInDir, even if the Shell().Get() fails (for other reasons) it makes sense that the destination should be removed early in the function.

schomatis commented 6 years ago

Oh, @whyrusleeping already took care of it :)