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

feat(): Add copy implementation #1758

Merged
merged 12 commits into from
Aug 2, 2019

Conversation

27pchrisl
Copy link
Contributor

Implementation for all platforms, and uses the same copy semantics across all.

This method is called 'copy' (rather than node-style copyFile), since it can copy both directory structures and individual files.

It turns out that a copy operation has almost everything in common with a rename operation, so in each case there is a _copy method that does the bulk of the param checking/error handling etc. so as not to end up with a lot of duplication.

Copy, and now rename support a 'toDirectory' as well as the pre-existing 'directory'. Developers can omit 'directory' to use DEFAULT_DIRECTORY, include only 'directory' to rename/copy within a directory, or include both to rename/copy between directories.

Finally, added a set of tests to the example app to show the move/copy operations working.

@27pchrisl 27pchrisl changed the title Add copy implementation feat(): Add copy implementation Jul 22, 2019
@mlynch
Copy link
Contributor

mlynch commented Jul 31, 2019

Looks good to me! Thanks @27pchrisl for adding this!

Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

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

Is working fine for web platform, but there are some problems in the other platforms, I've commented the problems so you can fix them.

Also, the example app are not tests that automatically run, but something to manually test, so I think having all that functions in a single button can be overkill, can you add a few more buttons and split the functions? at least one for copy functions and another for rename functions.

Other than that, awesome PR!

return
}

let directoryOption = call.get("directory", String.self, DEFAULT_DIRECTORY)!
var toDirectoryOption = call.get("toDirectory", String.self, DEFAULT_DIRECTORY)!
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var toDirectoryOption = call.get("toDirectory", String.self, DEFAULT_DIRECTORY)!
var toDirectoryOption = call.get("toDirectory", String.self, "")!

Set the default to "", otherwise the following if will never be true and will always copy to DOCUMENTS directory as it's the default if no "toDirectory" is provided

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

});
}

copy(options: CopyOptions): Promise<CopyResult> {
return this._copy(options, true);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return this._copy(options, true);
return this._copy(options, false);

copy doesn't rename, so should be false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, missed this during refactoring

}

rename(options: RenameOptions): Promise<RenameResult> {
return this._copy(options, false);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return this._copy(options, false);
return this._copy(options, true);

Here the opposite, rename should be true on rename function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -455,28 +493,72 @@ public void rename(PluginCall call) {
}
Copy link
Member

Choose a reason for hiding this comment

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

this is preventing from copying/renaming if the path is the same but the directory is different, you should compare fromObject and toObject instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@27pchrisl
Copy link
Contributor Author

I've also hugely simplified the tests into four buttons, and removed all the negative tests and kept the main gist of it.

Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

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

Looks good to me

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