-
Notifications
You must be signed in to change notification settings - Fork 279
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
Fixed mozilla/thimble.mozilla.org#1887: File overwrites without notifying user #712
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); |
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.
Remove this please.
return callback(); | ||
} | ||
|
||
fs.mkdirp(basedir, function(err) { | ||
if(err && err.code !== "EEXIST") { | ||
fs.mkdirp(basedir, function (err) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't care about any case other that "FILE"
do this:
if (stats.type !== "FILE") {
return callback();
}
// continue without indenting
...
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.
Left a few comments, and I'll do a deeper dive after you've dealt with these. Overall it looks good.
|
||
// Mac and Windows clutter zip files with extra files/folders we don't need | ||
function _skipFile(filename) { | ||
var basename = Path.basename(filename); | ||
|
||
// Skip OS X additions we don't care about in the browser fs | ||
if(/^__MACOSX\//.test(filename)) { | ||
if (/^__MACOSX\//.test(filename)) { |
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.
undo all these space changes
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 |
@@ -136,6 +139,7 @@ DND_SUCCESS_UNTAR_TITLE=Untar Completed Successfully | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have all these strings been added to Thimble's repo yet?
var Strings = require("strings"); | ||
var StringUtils = require("utils/StringUtils"); | ||
|
||
// These are const variables |
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.
Get rid of this comment.
} | ||
fs.stat(path.absPath, function(err, stats) { | ||
if(err && err.code !== "ENOENT") { | ||
return callback(err); |
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.
Too much indent here.
@@ -227,11 +288,33 @@ define(function (require, exports, module) { | |||
} | |||
|
|||
fs.mkdirp(basedir, function(err) { | |||
if(err && err.code !== "EEXIST") { |
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.
Why this change?
file.write(buffer, {encoding: encoding}, function(err) { | ||
if (err) { | ||
onError(deferred, filename, err); | ||
return; | ||
} | ||
|
||
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.
Get rid of this change.
function handleRegularFile(deferred, file, filename, buffer, encoding) { | ||
fs.exists(filename, function(doesExist) { | ||
if (doesExist) { | ||
console.log("File: ", filename, " already exists!"); |
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.
Remove this.
} | ||
}); | ||
} else { | ||
// File doesn't exist. Save without prompt |
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.
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.
@@ -182,6 +181,7 @@ define(function (require, exports, module) { | |||
return result.promise(); | |||
}, false) | |||
.fail(function () { | |||
console.log("fail"); |
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.
Revert all the changes in this file.
@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 👍