-
Notifications
You must be signed in to change notification settings - Fork 972
Don't overwrite existing files when DOWNLOAD_ALWAYS_ASK is false #9867
Don't overwrite existing files when DOWNLOAD_ALWAYS_ASK is false #9867
Conversation
5d2ed55
to
11299f7
Compare
app/filtering.js
Outdated
@@ -520,14 +521,29 @@ function registerForDownloadListener (session) { | |||
} | |||
|
|||
const defaultPath = path.join(getSetting(settings.DOWNLOAD_DEFAULT_PATH) || getSetting(settings.DEFAULT_DOWNLOAD_SAVE_PATH) || app.getPath('downloads'), itemFilename) | |||
const savePath = ((process.env.SPECTRON || (!getSetting(settings.DOWNLOAD_ALWAYS_ASK) && !item.promptForSaveLocation())) ? defaultPath : dialog.showSaveDialog(win, { defaultPath })) | |||
let savePath = ((process.env.SPECTRON || (!getSetting(settings.DOWNLOAD_ALWAYS_ASK) && !item.promptForSaveLocation())) ? defaultPath : dialog.showSaveDialog(win, { defaultPath })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be a single if
statement here that wraps all of this, but can you switch !getSetting(settings.DOWNLOAD_ALWAYS_ASK) && !item.promptForSaveLocation()
to getSetting(settings.DOWNLOAD_ALWAYS_ASK) || item.promptForSaveLocation()
? The former is confusing
app/filtering.js
Outdated
|
||
// User cancelled out of save dialog prompt | ||
if (!savePath) { | ||
event.preventDefault() | ||
return | ||
} | ||
|
||
if (!getSetting(settings.DOWNLOAD_ALWAYS_ASK) && !item.promptForSaveLocation()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please merge into else
for if
above
app/filtering.js
Outdated
|
||
// User cancelled out of save dialog prompt | ||
if (!savePath) { | ||
event.preventDefault() | ||
return | ||
} | ||
|
||
if (!getSetting(settings.DOWNLOAD_ALWAYS_ASK) && !item.promptForSaveLocation()) { | ||
let willNotOverwrite = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double negative checks are also hard to understand !willNotOverwrite
-> willOverwrite
app/filtering.js
Outdated
let matchedFilenames = 0 | ||
let querySavePath | ||
while (!willNotOverwrite) { | ||
querySavePath = (matchedFilenames ? savePath.substring(0, savePath.lastIndexOf('.') >= 0 ? savePath.lastIndexOf('.') : savePath.length) + ` (${matchedFilenames})` + savePath.substring(savePath.lastIndexOf('.') >= 0 ? savePath.lastIndexOf('.') : savePath.length) : savePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will break things like .tar.gz
. Maybe get the first index?
11299f7
to
8a64255
Compare
Thanks for the feedback @bridiver I've refactored the code based on your suggestions. I also dug into the extension name edge cases (like I did some searching for possible solutions. One thought was to use the MIME:
....sadly, it didn't work for
It seems that the most common approach is to split on the last "."...even the OS X save prompt defaults to using the last ".": Short of rolling with a whitelist of file extensions, which feels like overkill....it looks like this may be the best option. |
8a64255
to
5b7a0b3
Compare
Just added tests....let me know if you think it needs more coverage. |
@timborden would you please rebase on the latest master? thanks! |
5b7a0b3
to
3cba178
Compare
Hey @luixxiul ...sorry for the delay (just changed my GitHub settings so I don't miss these notifications) I just rebased....FYI |
@timborden thanks! I'd like to see you keep up the nice work :-) |
Codecov Report
@@ Coverage Diff @@
## master #9867 +/- ##
==========================================
- Coverage 53.67% 53.63% -0.04%
==========================================
Files 238 238
Lines 21049 21063 +14
Branches 3256 3258 +2
==========================================
+ Hits 11297 11298 +1
- Misses 9752 9765 +13
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code works great 😄 👍 Good job on this one (including the tests too!)
@bridiver did you want to re-review before this gets merged? |
Merged 😄 👌 |
Awesome....thanks @bsclifton, @bridiver and @luixxiul |
Fixes #7764
Submitter Checklist:
git rebase -i
to squash commits (if needed).Test Plan:
Reviewer Checklist:
Tests