Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fallback location #54

Merged
merged 4 commits into from
May 10, 2017
Merged

Fix fallback location #54

merged 4 commits into from
May 10, 2017

Conversation

Siilwyn
Copy link
Contributor

@Siilwyn Siilwyn commented Apr 14, 2017

See @develar's concerns at the original issue #24 and at the atomic rename PR.

I have included a test that fails against master and is passing by moving the fallback logic to directory level.

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Apr 15, 2017

So my previous PR introduced a 🐛 that causes an error when trying to download a new version that is cached in the original location.
Just pushed again, CI was failing because of the linter, tagging those involved in the previous PR... @MarshallOfSound @zeke @kevinsawicki

This fixes caching versions later than 1.3.2 that are using checksum
validation.
@develar
Copy link
Contributor

develar commented Apr 15, 2017

Are we really need to worry about old cache?

lib/index.js Outdated
@@ -44,6 +44,11 @@ class ElectronDownloader {
}

get cache () {
const oldCacheDirectory = path.join(os.homedir(), './.electron')
if (pathExists.sync(path.join(oldCacheDirectory, this.filename))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we should avoid sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async code is often better but I chose for a sync method in this case. Firstly because the path to the cache is needed for all other functionality. Secondly all other code expects this method to be sync. Lastly this fallback will be removed in the future so rewriting other methods to work in an async way with get cache sounds unreasonable.

@Siilwyn
Copy link
Contributor Author

Siilwyn commented Apr 15, 2017

@develar see the original PR and in particular this comment on why we worry about the old cache.

@Siilwyn
Copy link
Contributor Author

Siilwyn commented May 1, 2017

Sorry I forgot to tag @malept who was also involved in the previous PR.
By the way could somebody re-run CI so it's green?

@Siilwyn
Copy link
Contributor Author

Siilwyn commented May 10, 2017

@kevinsawicki thoughts?

lib/index.js Outdated
if (pathExists.sync(path.join(oldCacheDirectory, this.filename))) {
return path.join(os.homedir(), './.electron')
}

// use passed argument or XDG environment variable fallback to OS default
return this.opts.cache || envPaths('electron', {suffix: ''}).cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this method always return this.opts.cache when specified? Even if the old directory exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sharp! Added a test to confirm this is working. Also found the first test could be improved.

Object.assign(
{},
downloadOptions,
{ cache: oldCachePath }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for the three objects here instead of just setting cache directly on downloadOptions?

Copy link
Contributor Author

@Siilwyn Siilwyn May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because I re-use the same settings object with the only difference being the cache property. It looks a bit wonky because of the newlines though, removed those. Thanks for your review!

lib/index.js Outdated

const oldCacheDirectory = path.join(os.homedir(), './.electron')
if (pathExists.sync(path.join(oldCacheDirectory, this.filename))) {
return path.join(os.homedir(), './.electron')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could just return oldCacheDirectory I believe.

@kevinsawicki kevinsawicki merged commit c7c0ad0 into electron:master May 10, 2017
@kevinsawicki
Copy link
Contributor

Thanks @Siilwyn for fixing this 👍 🚢

@Siilwyn
Copy link
Contributor Author

Siilwyn commented May 10, 2017

Thanks for your helpful reviews too @kevinsawicki! 🎉

@Siilwyn Siilwyn deleted the fix-fallback-location branch May 10, 2017 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants