From: Pawel Kaczmarek
Date: Wed, 18 Feb 2015 10:33:46 +0000 (+0100)
Subject: [Filesystem] File.deleteDirectory JS part
X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~368^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1b562c298ec19616c5f15c74e2f7e80b115ede2b;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Filesystem] File.deleteDirectory JS part
[Verification]
var documentsDir;
function onsuccess(files) {
for (var i = 0; i < files.length; i++) {
if (files[i].isDirectory) {
documentsDir.deleteDirectory(
files[i].fullPath,
false,
function() {
console.log("Directory Deleted");
}, function(e) {
console.log("Error" + e.message);
});
}
}
}
function onerror(error) {
console.log("The error " + error.message + " occurred when 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 remove all directories from documents directory
[Depends on]
http://168.219.209.56/gerrit/#/c/20606/
http://168.219.209.56/gerrit/#/c/20616/ - needed for verification
Change-Id: I09ba7a2e3552b857e34e944758248a147977ad34
Signed-off-by: Pawel Kaczmarek
---
diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js
index dbb61fb4..df52e31f 100644
--- a/src/filesystem/js/file.js
+++ b/src/filesystem/js/file.js
@@ -253,21 +253,59 @@ File.prototype.deleteDirectory = function(directoryPath, recursive, onsuccess, o
{name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}
]);
- var data = {
- directoryPath: args.directoryPath,
- recursive: args.recursive
- };
-
- var callback = function(result) {
- if (native_.isFailure(result)) {
- native_.callIfPossible(args.onerror, native_.getErrorObject(result));
- return;
- }
- native_.callIfPossible(args.onsuccess);
- };
-
- native_.call('File_deleteDirectory', data, callback);
+ if (this.mode === 'r') {
+ setTimeout(function() {
+ native_.callIfPossible(args.onerror,
+ new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+ 'Invalid path or readonly access'));
+ }, 0);
+ return;
+ }
+ var _myPath = commonFS_.toRealPath(args.directoryPath);
+ var _result = native_.callSync('File_statSync', {location: _myPath});
+ var _statObj = native_.getResultObject(_result);
+ var _info = commonFS_.getFileInfo(_myPath, _statObj);
+ var _node = new File(_info);
+
+ if (!_node.isDirectory) {
+ setTimeout(function() {
+ native_.callIfPossible(args.onerror,
+ new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+ 'It is file not directory'));
+ }, 0);
+ return;
+ } else {
+ _node.listFiles(
+ function(files) {
+ if (files.length > 0) {
+ if (!args.recursive) {
+ native_.callIfPossible(args.onerror,
+ new tizen.WebAPIException(tizen.WebAPIException.IO_ERR,
+ 'Non empty folder ' + _myPath + ' passed for non recursive delete'));
+ return;
+ }
+ }
+ var data = {
+ pathToDelete: _myPath
+ };
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.onerror, native_.getErrorObject(result));
+ }
+ native_.callIfPossible(args.onsuccess);
+ };
+
+ native_.call('File_removeDirectory', data, callback);
+ },
+ function() {
+ native_.callIfPossible(args.onerror,
+ new tizen.WebAPIException(tizen.WebAPIException.IO_ERR,
+ 'List files failed for ' + _myPath));
+ }
+ );
+ }
};
File.prototype.deleteFile = function(filePath, onsuccess, onerror) {