You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ti...@apache.org on 2012/06/07 22:40:44 UTC
[29/48] js commit: got some more tests passing with copy and move
functions
got some more tests passing with copy and move functions
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/19a85ab4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/19a85ab4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/19a85ab4
Branch: refs/heads/master
Commit: 19a85ab46020343c97f234ec58fc44af6ddc2ab4
Parents: c0fcfaf
Author: Tim Kim <ti...@nitobi.com>
Authored: Tue May 22 18:35:46 2012 -0700
Committer: Tim Kim <ti...@nitobi.com>
Committed: Thu Jun 7 13:40:23 2012 -0700
----------------------------------------------------------------------
lib/playbook/plugin/playbook/Entry.js | 138 ++++++++++++++++++++++-----
1 files changed, 112 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/19a85ab4/lib/playbook/plugin/playbook/Entry.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/Entry.js b/lib/playbook/plugin/playbook/Entry.js
index 478868b..2686a6f 100644
--- a/lib/playbook/plugin/playbook/Entry.js
+++ b/lib/playbook/plugin/playbook/Entry.js
@@ -61,44 +61,130 @@ module.exports = {
var theEntry = {};
if(this.isFile){
- if(blackberry.io.file.exists(parent.fullPath + '/' + name)){
- blackberry.io.file.deleteFile(parent.fullPath + '/' + name);
- blackberry.io.file.copy(srcPath,parent.fullPath + '/' + name);
+ if(srcPath != parent.fullPath + '/' + name){
+ if(blackberry.io.file.exists(parent.fullPath + '/' + name)){
+ blackberry.io.file.deleteFile(parent.fullPath + '/' + name);
+ blackberry.io.file.copy(srcPath,parent.fullPath + '/' + name);
- theEntry.fullPath = parent.fullPath + '/' + name;
- theEntry.name = name;
- theEntry.isDirectory = false;
- theEntry.isFile = true;
- success(theEntry);
+ theEntry.fullPath = parent.fullPath + '/' + name;
+ theEntry.name = name;
+ theEntry.isDirectory = false;
+ theEntry.isFile = true;
+ success(theEntry);
+ }else{
+ blackberry.io.file.copy(srcPath,parent.fullPath + '/' + name);
+ blackberry.io.file.deleteFile(srcPath);
+
+ theEntry.fullPath = parent.fullPath + '/' + name;
+ theEntry.name = name;
+ theEntry.isDirectory = false;
+ theEntry.isFile = true;
+ success(theEntry);
+ }
}else{
- blackberry.io.file.copy(srcPath,parent.fullPath + '/' + name);
- blackberry.io.file.deleteFile(srcPath);
-
- theEntry.fullPath = parent.fullPath + '/' + name;
- theEntry.name = name;
- theEntry.isDirectory = false;
- theEntry.isFile = true;
- success(theEntry);
+ console.log('file onto itself');
+ fail(FileError.INVALID_MODIFICATION_ERR);
}
}else{
- if(blackberry.io.dir.exists(parent.fullPath + '/' + name)){
- fail(FileError.INVALID_MODIFICATION_ERROR);
+ if(srcPath != parent.fullPath + '/' + name){
+ if(blackberry.io.dir.exists(parent.fullPath + '/' + name)){
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }else{
+ blackberry.io.dir.createNewDir(parent.fullPath + '/' + name);
+ blackberry.io.dir.deleteDirectory(srcPath);
+
+ theEntry.fullPath = parent.fullPath + '/' + name;
+ theEntry.name = name;
+ theEntry.isDirectory = true;
+ theEntry.isFile = false;
+ success(theEntry);
+ }
}else{
- blackberry.io.dir.createNewDir(parent.fullPath + '/' + name);
- blackberry.io.dir.deleteDirectory(srcPath);
-
- theEntry.fullPath = parent.fullPath + '/' + name;
- theEntry.name = name;
- theEntry.isDirectory = true;
- theEntry.isFile = false;
- success(theEntry);
+ console.log('directory onto itself');
+ fail(FileError.INVALID_MODIFICATION_ERR);
}
}
},
copyTo : function(parent, newName, successCallback, errorCallback) {
+ var fail = function(code) {
+ if (typeof errorCallback === 'function') {
+ errorCallback(new FileError(code));
+ }
+ };
+ // user must specify parent Entry
+ if (!parent) {
+ fail(FileError.NOT_FOUND_ERR);
+ return;
+ }
+ // source path
+ var srcPath = this.fullPath,
+ // entry name
+ name = newName || this.name,
+ success = function(entry) {
+ if (entry) {
+ if (typeof successCallback === 'function') {
+ // create appropriate Entry object
+ var result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath) : new FileEntry(entry.name, entry.fullPath);
+ try {
+ successCallback(result);
+ }
+ catch (e) {
+ console.log('Error invoking callback: ' + e);
+ }
+ }
+ }
+ else {
+ // no Entry object returned
+ fail(FileError.NOT_FOUND_ERR);
+ }
+ };
+
+ var theEntry = {};
+ if(this.isFile){
+ if(srcPath != parent.fullPath + '/' + name){
+ if(blackberry.io.file.exists(parent.fullPath + '/' + name)){
+ blackberry.io.file.copy(srcPath,parent.fullPath + '/' + name);
+
+ theEntry.fullPath = parent.fullPath + '/' + name;
+ theEntry.name = name;
+ theEntry.isDirectory = false;
+ theEntry.isFile = true;
+ success(theEntry);
+
+ }else{
+ blackberry.io.file.copy(srcPath,parent.fullPath + '/' + name);
+
+ theEntry.fullPath = parent.fullPath + '/' + name;
+ theEntry.name = name;
+ theEntry.isDirectory = false;
+ theEntry.isFile = true;
+ success(theEntry);
+ }
+ }else{
+ console.log('file onto itself');
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ }else{
+ if(srcPath != parent.fullPath + '/' + name){
+ if(blackberry.io.dir.exists(parent.fullPath + '/' + name)){
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }else{
+ blackberry.io.dir.createNewDir(parent.fullPath + '/' + name);
+
+ theEntry.fullPath = parent.fullPath + '/' + name;
+ theEntry.name = name;
+ theEntry.isDirectory = true;
+ theEntry.isFile = false;
+ success(theEntry);
+ }
+ }else{
+ console.log('directory onto itself');
+ fail(FileError.INVALID_MODIFICATION_ERR);
+ }
+ }
},