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

Fixed mozilla/thimble.mozilla.org#1887: File overwrites without notifying user #712

Closed
wants to merge 3 commits into from

Conversation

sdalmeida
Copy link

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 👍

@sdalmeida
Copy link
Author

By the way, I just noticed that this PR needs to land first

#659

I've changed the title to WIP. Once that lands, I'll add my fix 👍

@sdalmeida sdalmeida changed the title Fixed mozilla/thimble.mozilla.org#1887: File overwrites without notifying user [WIP] Fixed mozilla/thimble.mozilla.org#1887: File overwrites without notifying user Apr 12, 2017
fs.writeFile(path.absPath, path.data, callback);
}
if (stats.type === "FILE") {
//console.log("File exists!", path.absPath);
Copy link

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) {
Copy link

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") {
Copy link

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
...

Copy link

@humphd humphd left a 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)) {

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

@flukeout flukeout removed the Launch label May 4, 2017
@humphd
Copy link

humphd commented May 8, 2017

I've landed #659 so, feel free to rebase and finish this.

@sdalmeida
Copy link
Author

sdalmeida commented May 12, 2017

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 👍

@sdalmeida
Copy link
Author

Wasn't as hard as I thought.
For some odd reason, the import doesn't trigger if the .tar archive contains empty files (0 bytes). Not too sure how files are stored when they are tar'd.

Going to remove the [WIP] label.
Please let me know if there's anything you want changed 👍

@sdalmeida sdalmeida changed the title [WIP] Fixed mozilla/thimble.mozilla.org#1887: File overwrites without notifying user Fixed mozilla/thimble.mozilla.org#1887: File overwrites without notifying user May 12, 2017
@@ -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?
Copy link

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
Copy link

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);
Copy link

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") {
Copy link

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;
}

Copy link

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!");
Copy link

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
Copy link

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");
Copy link

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.

@gideonthomas
Copy link

@Simon66 are you still working on this?

@humphd
Copy link

humphd commented Jun 13, 2017

If he's not, I'll finish it.

@humphd
Copy link

humphd commented Jul 20, 2017

Finishing this in #847

@humphd humphd closed this Jul 20, 2017
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.

4 participants