From c786e2e6c56de9a807ef5bc5dcc6f33ce82e7a6e Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarek Date: Fri, 27 Feb 2015 10:31:58 +0100 Subject: [PATCH] [Filesystem] File.moveTo JS part [Verification] var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (files[i].isDirectory == false) { documentsDir.moveTo(files[i].fullPath, "images/newDir/" + files[i].name, false, function() {console.log("file moved");}); } } } function onerror(error) { console.log("The error " + error.message + " occurred during listing the files in the selected folder"); } tizen.filesystem.resolve( 'documents', function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error" + e.message); }, "rw" ); //should move all files from documents dir to images/newDir Change-Id: If02186dd2e01bfa92d947f1ad43bbb1544e54ad6 Signed-off-by: Pawel Kaczmarek --- src/filesystem/js/file.js | 58 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js index 6e2299ad..747450ba 100644 --- a/src/filesystem/js/file.js +++ b/src/filesystem/js/file.js @@ -330,10 +330,60 @@ File.prototype.moveTo = function(originFilePath, destinationFilePath, overwrite, {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true} ]); + if (this.isFile) { + setTimeout(function() { + native_.callIfPossible(args.onerror, + new tizen.WebAPIException(tizen.WebAPIException.IO_ERR, + 'File object which call this method is not directory')); + }, 0); + return; + } + + var _realOriginalPath = commonFS_.toRealPath(args.originFilePath); + var _realDestinationPath = commonFS_.toRealPath(args.destinationFilePath); + + var resultOldPath = native_.callSync('File_statSync', {location: _realOriginalPath}); + if (native_.isFailure(resultOldPath)) { + setTimeout(function() { + native_.callIfPossible(args.onerror, + new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR, + 'Source file is not avalaible')); + }, 0); + return; + } + + if (!args.overwrite) { + var resultNewPath = native_.callSync('File_statSync', {location: _realDestinationPath}); + if (native_.isSuccess(resultNewPath)) { + setTimeout(function() { + native_.callIfPossible(args.onerror, + new tizen.WebAPIException(tizen.WebAPIException.IO_ERR, 'Overwrite is not allowed')); + }, 0); + return; + } + } + + if (!commonFS_.f_isSubDir(_realOriginalPath, this.fullPath)) { + var m1 = 'Source file should be subdirectory of: ' + this.fullPath; + setTimeout(function() { + native_.callIfPossible(args.onerror, + new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR, m1)); + }, 0); + return; + } + + if (this.mode === 'r' || !commonFS_.isLocationAllowed(_realDestinationPath)) { + var m2 = 'Source/Destination is read only folder: ' + this.fullPath; + setTimeout(function() { + native_.callIfPossible(args.onerror, + new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR, m2)); + }, 0); + return; + } + var data = { - originFilePath: args.originFilePath, - destinationFilePath: args.destinationFilePath, - overwrite: args.overwrite + oldPath: _realOriginalPath, + newPath: _realDestinationPath }; var callback = function(result) { @@ -344,7 +394,7 @@ File.prototype.moveTo = function(originFilePath, destinationFilePath, overwrite, native_.callIfPossible(args.onsuccess); }; - native_.call('File_moveTo', data, callback); + native_.call('File_rename', data, callback); }; File.prototype.createDirectory = function(dirPath) { -- 2.34.1