Fixed mozilla/thimble.mozilla.org#1887: File overwrites without notifying user#712
Fixed mozilla/thimble.mozilla.org#1887: File overwrites without notifying user#712sdalmeida wants to merge 3 commits intomozilla:masterfrom
Conversation
|
By the way, I just noticed that this PR needs to land first I've changed the title to WIP. Once that lands, I'll add my fix 👍 |
| fs.writeFile(path.absPath, path.data, callback); | ||
| } | ||
| if (stats.type === "FILE") { | ||
| //console.log("File exists!", path.absPath); |
|
|
||
| fs.mkdirp(basedir, function(err) { | ||
| if(err && err.code !== "EEXIST") { | ||
| fs.mkdirp(basedir, function (err) { |
There was a problem hiding this comment.
It looks to me like we're duplicating code here from above. Is there any way to refactor this to a function that both call?
| if (err && err.code !== "ENOENT") { | ||
| return callback(err); | ||
| } | ||
| if (stats.type === "FILE") { |
There was a problem hiding this comment.
If you don't care about any case other that "FILE" do this:
if (stats.type !== "FILE") {
return callback();
}
// continue without indenting
...
humphd
left a comment
There was a problem hiding this comment.
Left a few comments, and I'll do a deeper dive after you've dealt with these. Overall it looks good.
|
|
||
| // Skip OS X additions we don't care about in the browser fs | ||
| if(/^__MACOSX\//.test(filename)) { | ||
| if (/^__MACOSX\//.test(filename)) { |
|
I've landed #659 so, feel free to rebase and finish this. |
|
This might take a bit to complete. If this is an urgent issue that needs to be completed soon, let me know. I'll continue working on it :) From debugging, looks like the code was moved to "WebKitFileImport.js". Going to make my changes there and test 👍 |
|
Wasn't as hard as I thought. Going to remove the |
| DND_SUCCESS_UNZIP=Successfully unzipped <b>{0}</b>. | ||
| # {0} will be replaced by a tar filename | ||
| DND_SUCCESS_UNTAR=Successfully untarred <b>{0}</b>. | ||
| DND_FILE_REPLACE=A file named \"{0}\" already exists in this location. Do you want to use the imported file or keep the existing? |
There was a problem hiding this comment.
Have all these strings been added to Thimble's repo yet?
| var Strings = require("strings"); | ||
| var StringUtils = require("utils/StringUtils"); | ||
|
|
||
| // These are const variables |
| } | ||
| fs.stat(path.absPath, function(err, stats) { | ||
| if(err && err.code !== "ENOENT") { | ||
| return callback(err); |
| } | ||
|
|
||
| fs.mkdirp(basedir, function(err) { | ||
| if(err && err.code !== "EEXIST") { |
| return; | ||
| } | ||
|
|
||
| function handleRegularFile(deferred, file, filename, buffer, encoding) { | ||
| fs.exists(filename, function(doesExist) { | ||
| if (doesExist) { | ||
| console.log("File: ", filename, " already exists!"); |
| } | ||
| }); | ||
| } else { | ||
| // File doesn't exist. Save without prompt |
There was a problem hiding this comment.
Do this case first, and then return, and then you don't need to indent everything above so much:
if (!doesExist) {
// File doesn't exist. Save without prompt
saveFile(deferred, file, filename, buffer, encoding);
return;
}
// rest of code here for other case.| return result.promise(); | ||
| }, false) | ||
| .fail(function () { | ||
| console.log("fail"); |
|
@Simon66 are you still working on this? |
|
If he's not, I'll finish it. |
|
Finishing this in #847 |
Fixed bug where imported items could overwrite local files without notifying the user (As shown here: https://github.com/mozilla/thimble.mozilla.org/issues/1887).
While working on the file, I've added some spaces (for better code indentation). Let me know if thats something you want reverted 👍