cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [01/12] cordova-plugin-file git commit: Rework to use normal url form on windows platform
Date Fri, 23 Jan 2015 20:19:18 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master f7bfa8925 -> 967ca4d84


Rework to use normal url form on windows platform


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/3dfd3e9a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/3dfd3e9a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/3dfd3e9a

Branch: refs/heads/master
Commit: 3dfd3e9afaa93dbbd880592e1c8f281b4091a252
Parents: 8ef744d
Author: Vladimir Avdonin <vldmrrr@gmail.com>
Authored: Sat Nov 1 17:40:54 2014 -0500
Committer: Vladimir Avdonin <vldmrrr@gmail.com>
Committed: Sat Nov 1 17:40:54 2014 -0500

----------------------------------------------------------------------
 src/windows/FileProxy.js | 1141 +++++++++++++++++++++++------------------
 tests/tests.js           |   50 +-
 2 files changed, 663 insertions(+), 528 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3dfd3e9a/src/windows/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileProxy.js b/src/windows/FileProxy.js
index 9910c54..a0f0001 100644
--- a/src/windows/FileProxy.js
+++ b/src/windows/FileProxy.js
@@ -27,36 +27,8 @@ var Entry = require('./Entry'),
     DirectoryEntry = require('./DirectoryEntry'),
     Flags = require('./Flags'),
     FileSystem = require('./FileSystem'),
-    LocalFileSystem = require('./LocalFileSystem');
-
-// Some private helper functions, hidden by the module
-function cordovaPathToNative(path) {
-    // turn / into \\
-    var cleanPath = path.replace(/\//g, '\\');
-    // turn  \\ into \
-    cleanPath = cleanPath.replace(/\\\\/g, '\\');
-    // strip end \\ characters
-    cleanPath = cleanPath.replace(/\\+$/g, '');
-    return cleanPath;
-};
-
-function nativePathToCordova(path) {
-    var cleanPath = path.replace(/\\/g, '/');
-    return cleanPath;
-};
-
-function getFilesystemFromPath(path) {
-    var storageFolderPermanent = Windows.Storage.ApplicationData.current.localFolder.path,
-        storageFolderTemporary = Windows.Storage.ApplicationData.current.temporaryFolder.path,
-        fs = null;
-
-    if (path.indexOf(storageFolderPermanent) === 0) {
-        fs = new FileSystem('persistent', { name: 'persistent', fullPath: storageFolderPermanent });
-    } else if (path.indexOf(storageFolderTemporary) === 0) {
-        fs = new FileSystem('temporary', { name: 'temporary', fullPath: storageFolderTemporary });
-    }
-    return fs;
-};
+    LocalFileSystem = require('./LocalFileSystem'),
+    utils = require('cordova/utils');
 
 var getFolderFromPathAsync = Windows.Storage.StorageFolder.getFolderFromPathAsync;
 var getFileFromPathAsync = Windows.Storage.StorageFile.getFileFromPathAsync;
@@ -86,15 +58,383 @@ var writeArrayBufferAsync = function writeArrayBufferAsync(storageFile, data) {
     return writeBlobAsync(storageFile, new Blob([data]));
 };
 
-module.exports = {
+function cordovaPathToNative(path) {
+    // turn / into \\
+    var cleanPath = path.replace(/\//g, '\\');
+    // turn  \\ into \
+    cleanPath = cleanPath.replace(/\\\\/g, '\\');
+    // strip end \\ characters
+    cleanPath = cleanPath.replace(/\\+$/g, '');
+    return cleanPath;
+}
+
+function nativePathToCordova(path) {
+    var cleanPath = path.replace(/\\/g, '/');
+    return cleanPath;
+}
+
+var invalidNameRE = /[\\?*|"<>:]/;
+function validName(name) {
+	return !invalidNameRE.test(name);
+}
+
+var slashesRE = new RegExp('/{2,}','g');
+var parentRE = new RegExp('/([^/]+/)\\.\\.(/|$)','g');
+function sanitize(path) {
+	return path.replace(slashesRE,'/').replace(parentRE,'$2');
+}
+
+var WinFS = function(name, root) {
+	this.winpath = root.winpath;
+    if (this.winpath && !/\/$/.test(this.winpath)) {
+        this.winpath += "/";
+    }
+    this.makeNativeURL = function(path) {
+    	return encodeURI(this.root.nativeURL + sanitize(path));};
+	root.fullPath = '/';
+	if (!root.nativeURL)
+		root.nativeURL = 'file://'+sanitize(this.winpath + root.fullPath);
+	WinFS.__super__.constructor.call(this, name, root);
+};
+
+utils.extend(WinFS, FileSystem);
 
+WinFS.prototype.__format__ = function(fullPath) {
+	var path = sanitize('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath));
+	return 'cdvfile://localhost' + path;
+};
+
+var AllFileSystems; 
+
+function getAllFS() {
+	if (!AllFileSystems) {
+		var storageFolderPermanent = Windows.Storage.ApplicationData.current.localFolder.path,
+			storageFolderTemporary = Windows.Storage.ApplicationData.current.temporaryFolder.path;
+		AllFileSystems = {
+			'persistent':
+			Object.freeze(new WinFS('persistent', { 
+				name: 'persistent', 
+				nativeURL: 'ms-appdata:///local',
+				winpath: nativePathToCordova(Windows.Storage.ApplicationData.current.localFolder.path)  
+			})),
+			'temporary':
+			Object.freeze(new WinFS('temporary', { 
+				name: 'temporary', 
+				nativeURL: 'ms-appdata:///temp',
+				winpath: nativePathToCordova(Windows.Storage.ApplicationData.current.temporaryFolder.path)
+			})),
+			'root':
+			Object.freeze(new WinFS('root', { 
+				name: 'root', 
+				//nativeURL: 'file:///'
+				winpath: '/'
+			}))
+		};
+	}
+	return AllFileSystems;
+}
+
+function getFS(name) {
+	return getAllFS()[name];
+}
+
+FileSystem.prototype.__format__ = function(fullPath) {
+	return getFS(this.name).__format__(fullPath);
+};
+
+require('./fileSystems').getFs = function(name, callback) {
+	setTimeout(function(){callback(getFS(name));});
+};
+
+function getFilesystemFromPath(path) {
+    var res;
+    var allfs = getAllFS();
+    Object.keys(allfs).some(function(fsn) {
+    	var fs = allfs[fsn];
+    	if (path.indexOf(fs.root.fullPath) === 0)
+    		res = fs;
+    	return res;
+    });
+    return res;
+}
+
+var msapplhRE = new RegExp('^ms-appdata://localhost/');
+function pathFromURL(url) {
+	url=url.replace(msapplhRE,'ms-appdata:///');
+	var path = decodeURI(url);
+	// support for file name with parameters
+	if (/\?/g.test(path)) {
+		path = String(path).split("?")[0];
+	}
+	if (path.indexOf("file:/")===0) {
+		if (path.indexOf("file://") !== 0) {
+			uri = "file:///" + uri.substr(6);
+		}
+	}
+	
+	['file://','ms-appdata:///','cdvfile://localhost/'].every(function(p) {
+		if (path.indexOf(p)!==0)
+			return true;
+		var thirdSlash = path.indexOf("/", p.length);
+		if (thirdSlash < 0) {
+			path = "";
+		} else {
+			path = sanitize(path.substr(thirdSlash));
+		}
+	});
+	
+	return path;
+}
+
+function getFilesystemFromURL(url) {
+	url=url.replace(msapplhRE,'ms-appdata:///');
+	var res;
+	if (url.indexOf("file:/")===0)
+		res = getFilesystemFromPath(cordovaPathToNative(pathFromURL(url)));
+	else {
+		var allfs = getAllFS();
+		Object.keys(allfs).every(function(fsn) {
+			var fs = allfs[fsn];
+			if (url.indexOf(fs.root.nativeURL) === 0 || 
+				url.indexOf('cdvfile://localhost/'+fs.name+'/') === 0) 
+			{
+				res = fs;
+				return false;
+			}
+			return true;
+		});
+	}
+    return res;
+}
+
+function getFsPathForWinPath(fs, wpath) {
+	var path = nativePathToCordova(wpath);
+	if (path.indexOf(fs.winpath) !== 0)
+		return null;
+	return path.replace(fs.winpath,'/');
+}
+
+var WinError = {
+	invalidArgument: -2147024809,
+	fileNotFound: -2147024894,
+	accessDenied: -2147024891
+};
+
+function openPath(path, ops) {
+	ops=ops?ops:{};
+	return new WinJS.Promise(function (complete,failed) {
+		getFileFromPathAsync(path).done(
+			function(file) {
+				complete({file:file});
+			},
+			function(err) {
+				if (err.number != WinError.fileNotFound && err.number != WinError.invalidArgument)
+					failed(FileError.NOT_READABLE_ERR);
+				getFolderFromPathAsync(path)
+				.done(
+					function(dir) {
+						if (!ops.getContent)
+							complete({folder:dir});
+						else
+							WinJS.Promise.join({
+								files:dir.getFilesAsync(),
+								folders:dir.getFoldersAsync()
+							}).done(
+								function(a) {
+									complete({
+										folder:dir,
+										files:a.files,
+										folders:a.folders
+									});
+								},
+								function(err) {
+									failed(FileError.NOT_READABLE_ERR);
+								}
+							);
+					},
+					function(err) {
+						if (err.number == WinError.fileNotFound || err.number == WinError.invalidArgument)
+							complete({});
+						else
+							failed(FileError.NOT_READABLE_ERR);
+					}
+				);
+			}
+		);
+	});
+}
+
+function copyFolder(src,dst,name) {
+	name = name?name:src.name;
+	return new WinJS.Promise(function (complete,failed) {
+		WinJS.Promise.join({
+			fld:dst.createFolderAsync(name, Windows.Storage.CreationCollisionOption.openIfExists),
+			files:src.getFilesAsync(),
+			folders:src.getFoldersAsync()
+		}).done(
+			function(the) {
+				if (!(the.files.length || the.folders.length)) {
+					complete();
+					return;
+				}
+				var todo = the.files.length;
+				var copyfolders = function() {
+					if (!todo--) {
+						complete();
+						return;
+					}
+					copyFolder(the.folders[todo],dst)
+					.done(function() {copyfolders(); }, failed);
+				};
+				var copyfiles = function() {
+					if (!todo--) {
+						todo = the.folders.length;
+						copyfolders();
+						return;
+					}
+					the.files[todo].copyAsync(the.fld)
+					.done(function() {copyfiles(); }, failed);
+				};
+				copyfiles();				
+			},
+			failed
+		);
+	});
+}
+
+function moveFolder(src,dst,name) {
+	name = name?name:src.name;
+	return new WinJS.Promise(function (complete,failed) {
+		var pending = [];
+		WinJS.Promise.join({
+			fld:dst.createFolderAsync(name, Windows.Storage.CreationCollisionOption.openIfExists),
+			files:src.getFilesAsync(),
+			folders:src.getFoldersAsync()
+		}).done(
+			function(the) {
+				if (!(the.files.length || the.folders.length)) {
+					complete();
+					return;
+				}
+				var todo = the.files.length;
+				var movefolders = function() {
+					if (!todo--) {
+						src.deleteAsync().done(complete,failed);
+						return;
+					}
+					moveFolder(the.folders[todo],dst)
+					.done(movefolders,failed); 
+				};
+				var movefiles = function() {
+					if (!todo--) {
+						todo = the.folders.length;
+						movefolders();
+						return;
+					}
+					the.files[todo].moveAsync(the.fld)
+					.done(function() {movefiles(); }, failed);
+				};
+				movefiles();				
+			},
+			failed
+		);
+	});
+}
+
+function transport(success, fail, args, ops) { // ["fullPath","parent", "newName"]
+	var src = args[0];
+	var parent = args[1];
+	var name = args[2];
+
+	var srcFS = getFilesystemFromURL(src);
+	var dstFS = getFilesystemFromURL(parent);
+	var srcPath = pathFromURL(src);
+	var dstPath = pathFromURL(parent);
+	if (!(srcFS && dstFS && validName(name))){
+		fail(FileError.ENCODING_ERR);
+		return;
+	}
+	
+	var srcWinPath = cordovaPathToNative(sanitize(srcFS.winpath + srcPath));
+	var dstWinPath = cordovaPathToNative(sanitize(dstFS.winpath + dstPath));
+	var tgtFsPath = sanitize(dstPath+'/'+name);
+	var tgtWinPath = cordovaPathToNative(sanitize(dstFS.winpath + dstPath+'/'+name));
+	if (srcWinPath == dstWinPath || srcWinPath == tgtWinPath) {
+		fail(FileError.INVALID_MODIFICATION_ERR);
+		return;
+	}
+	
+	
+	WinJS.Promise.join({
+		src:openPath(srcWinPath),
+		dst:openPath(dstWinPath),
+		tgt:openPath(tgtWinPath,{getContent:true})
+	})
+	.done(
+		function (the) {
+			if ((!the.dst.folder) || !(the.src.folder || the.src.file)) {
+				fail(FileError.NOT_FOUND_ERR);
+				return;
+			}
+			if (   (the.src.folder && the.tgt.file) 
+				|| (the.src.file && the.tgt.folder)
+				|| (the.tgt.folder && (the.tgt.files.length || the.tgt.folders.length))) 
+			{
+				fail(FileError.INVALID_MODIFICATION_ERR);
+				return;
+			}
+			if (the.src.file)
+				ops.fileOp(the.src.file,the.dst.folder, name, Windows.Storage.NameCollisionOption.replaceExisting)
+				.done(
+					function (storageFile) {
+						success(new FileEntry(
+							name,
+							tgtFsPath,
+							dstFS.name,
+							dstFS.makeNativeURL(tgtFsPath)
+						));
+					},
+					function (err) {
+						fail(FileError.INVALID_MODIFICATION_ERR);
+					}
+				);
+			else
+				ops.folderOp(the.src.folder, the.dst.folder, name).done(
+					function () {
+						success(new DirectoryEntry(
+							name, 
+							tgtFsPath, 
+							dstFS.name, 
+							dstFS.makeNativeURL(tgtFsPath)
+						));
+					},
+					function() {
+						fail(FileError.INVALID_MODIFICATION_ERR);
+					}
+				);
+		},
+		function(err) {
+			fail(FileError.INVALID_MODIFICATION_ERR);
+		}
+	);
+}
+
+module.exports = {
+	requestAllFileSystems: function() {
+		return getAllFS();
+	},
     getFileMetadata: function (success, fail, args) {
         module.exports.getMetadata(success, fail, args);
     },
 
     getMetadata: function (success, fail, args) {
-
-        var fullPath = cordovaPathToNative(args[0]);
+        var fs = getFilesystemFromURL(args[0]);
+        var path = pathFromURL(args[0]);
+        if (!fs || !validName(path)){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
+        var fullPath = cordovaPathToNative(fs.winpath + path);
 
         var getMetadataForFile = function (storageFile) {
             storageFile.getBasicPropertiesAsync().then(
@@ -133,26 +473,23 @@ module.exports = {
     },
 
     getParent: function (win, fail, args) { // ["fullPath"]
-
-        var fullPath = cordovaPathToNative(args[0]);
-
-        var storageFolderPer = Windows.Storage.ApplicationData.current.localFolder;
-        var storageFolderTem = Windows.Storage.ApplicationData.current.temporaryFolder;
-
-        if (fullPath == storageFolderPer.path) {
-            win(new DirectoryEntry(storageFolderPer.name, storageFolderPer.path, getFilesystemFromPath(storageFolderPer.path)));
-            return;
-        } else if (fullPath == storageFolderTem.path) {
-            win(new DirectoryEntry(storageFolderTem.name, storageFolderTem.path, getFilesystemFromPath(storageFolderTem.path)));
-            return;
+        var fs = getFilesystemFromURL(args[0]);
+        var path = pathFromURL(args[0]);
+        if (!fs || !validName(path)){
+        	fail(FileError.ENCODING_ERR);
+        	return;
         }
-        var splitArr = fullPath.split(new RegExp(/\/|\\/g));
-
-        var popItem = splitArr.pop();
-
-        var resultPath = fullPath.substr(0, fullPath.length - popItem.length - 1);
-        var result = new DirectoryEntry(popItem, resultPath, getFilesystemFromPath(resultPath));
-        getFolderFromPathAsync(result.fullPath).done(
+        if (!path || (new RegExp('/[^/]*/?$')).test(path)) {
+        	win(new DirectoryEntry(fs.root.name, fs.root.fullPath, fs, fs.makeNativeURL(fs.root.fullPath)));
+        	return;
+        }
+        
+        var parpath = path.replace(new RegExp('/[^/]+/?$','g'),'');
+        var parname = path.substr(parpath.length);
+        var fullPath = cordovaPathToNative(fs.winpath + parpath);
+        
+        var result = new DirectoryEntry(parname, parpath, fs, fs.makeNativeURL(parpath));
+        getFolderFromPathAsync(fullPath).done(
             function () { win(result); },
             function () { fail(FileError.INVALID_STATE_ERR); }
         );
@@ -160,11 +497,19 @@ module.exports = {
 
     readAsText: function (win, fail, args) {
 
-        var fileName = cordovaPathToNative(args[0]),
+        var url = args[0],
             enc = args[1],
             startPos = args[2],
             endPos = args[3];
         
+        var fs = getFilesystemFromURL(url);
+        var path = pathFromURL(url);
+        if (!fs){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
+        var wpath = cordovaPathToNative(sanitize(fs.winpath + path));
+        
         var encoding = Windows.Storage.Streams.UnicodeEncoding.utf8;
         if (enc == 'Utf16LE' || enc == 'utf16LE') {
             encoding = Windows.Storage.Streams.UnicodeEncoding.utf16LE;
@@ -172,7 +517,7 @@ module.exports = {
             encoding = Windows.Storage.Streams.UnicodeEncoding.utf16BE;
         }
 
-        getFileFromPathAsync(fileName).then(function(file) {
+        getFileFromPathAsync(wpath).then(function(file) {
                 return file.openReadAsync();
             }).then(function (stream) {
                 startPos = (startPos < 0) ? Math.max(stream.size + startPos, 0) : Math.min(stream.size, startPos);
@@ -191,12 +536,19 @@ module.exports = {
     },
 
     readAsBinaryString:function(win,fail,args) {
-        var fileName = cordovaPathToNative(args[0]),
+        var url = args[0],
             startPos = args[1],
             endPos = args[2];
 
+        var fs = getFilesystemFromURL(url);
+        var path = pathFromURL(url);
+        if (!fs){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
+        var wpath = cordovaPathToNative(sanitize(fs.winpath + path));
 
-        getFileFromPathAsync(fileName).then(
+        getFileFromPathAsync(wpath).then(
             function (storageFile) {
                 Windows.Storage.FileIO.readBufferAsync(storageFile).done(
                     function (buffer) {
@@ -222,9 +574,16 @@ module.exports = {
     },
 
     readAsArrayBuffer:function(win,fail,args) {
-        var fileName =cordovaPathToNative(args[0]);
+        var url = args[0];
+        var fs = getFilesystemFromURL(url);
+        var path = pathFromURL(url);
+        if (!fs){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
+        var wpath = cordovaPathToNative(sanitize(fs.winpath + path));
 
-        getFileFromPathAsync(fileName).then(
+        getFileFromPathAsync(wpath).then(
             function (storageFile) {
                 var blob = MSApp.createFileFromStorageFile(storageFile);
                 var url = URL.createObjectURL(blob, { oneTimeOnly: true });
@@ -264,10 +623,16 @@ module.exports = {
     },
 
     readAsDataURL: function (win, fail, args) {
+        var url = args[0];
+        var fs = getFilesystemFromURL(url);
+        var path = pathFromURL(url);
+        if (!fs){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
+        var wpath = cordovaPathToNative(sanitize(fs.winpath + path));
 
-        var fileName = cordovaPathToNative(args[0]);
-
-        getFileFromPathAsync(fileName).then(
+        getFileFromPathAsync(wpath).then(
             function (storageFile) {
                 Windows.Storage.FileIO.readBufferAsync(storageFile).done(
                     function (buffer) {
@@ -288,11 +653,23 @@ module.exports = {
     },
 
     getDirectory: function (win, fail, args) {
-
-        var fullPath = cordovaPathToNative(args[0]);
-        var path = cordovaPathToNative(args[1]);
+        var dirurl = args[0];
+        var path = args[1];
         var options = args[2];
 
+        var fs = getFilesystemFromURL(dirurl);
+        var dirpath = pathFromURL(dirurl);
+        if (!fs || !validName(path)){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }        	
+        var fspath = sanitize(dirpath +'/'+ path);
+        var completePath = sanitize(fs.winpath + fspath);
+
+        var name = completePath.substring(completePath.lastIndexOf('/')+1);
+        
+        var wpath = cordovaPathToNative(completePath.substring(0, completePath.lastIndexOf('/')));
+
         var flag = "";
         if (options) {
             flag = new Flags(options.create, options.exclusive);
@@ -300,41 +677,38 @@ module.exports = {
             flag = new Flags(false, false);
         }
 
-        getFolderFromPathAsync(fullPath).then(
+        getFolderFromPathAsync(wpath).done(
             function (storageFolder) {
                 if (flag.create === true && flag.exclusive === true) {
-                    storageFolder.createFolderAsync(path, Windows.Storage.CreationCollisionOption.failIfExists).done(
+                    storageFolder.createFolderAsync(name, Windows.Storage.CreationCollisionOption.failIfExists).done(
                         function (storageFolder) {
-                            win(new DirectoryEntry(storageFolder.name, nativePathToCordova(storageFolder.path), getFilesystemFromPath(storageFolder.path)));
+                            win(new DirectoryEntry(storageFolder.name, fspath, fs.name, fs.makeNativeURL(fspath)));
                         }, function (err) {
                             fail(FileError.PATH_EXISTS_ERR);
                         }
                     );
                 } else if (flag.create === true && flag.exclusive === false) {
-                    storageFolder.createFolderAsync(path, Windows.Storage.CreationCollisionOption.openIfExists).done(
+                    storageFolder.createFolderAsync(name, Windows.Storage.CreationCollisionOption.openIfExists).done(
                         function (storageFolder) {
-                            win(new DirectoryEntry(storageFolder.name, storageFolder.path + "/", getFilesystemFromPath(storageFolder.path + "/")));
+                            win(new DirectoryEntry(storageFolder.name, fspath, fs.name, fs.makeNativeURL(fspath)));
                         }, function () {
                             fail(FileError.INVALID_MODIFICATION_ERR);
                         }
                     );
                 } else if (flag.create === false) {
-                    if (/\?|\\|\*|\||\"|<|>|\:|\//g.test(path)) {
-                        fail(FileError.ENCODING_ERR);
-                        return;
-                    }
-
-                    storageFolder.getFolderAsync(path).done(
+                    storageFolder.getFolderAsync(name).done(
                         function (storageFolder) {
-                            win(new DirectoryEntry(storageFolder.name, storageFolder.path, getFilesystemFromPath(storageFolder.path)));
-                        }, function () {
+                            win(new DirectoryEntry(storageFolder.name, fspath, fs.name, fs.makeNativeURL(fspath)));
+                        }, 
+                        function () {
                             // check if path actually points to a file
-                            storageFolder.getFileAsync(path).done(
+                            storageFolder.getFileAsync(name).done(
                                 function () {
                                     fail(FileError.TYPE_MISMATCH_ERR);
                                 }, function() {
                                     fail(FileError.NOT_FOUND_ERR);
-                                });
+                                }
+							);
                         }
                     );
                 }
@@ -345,8 +719,19 @@ module.exports = {
     },
 
     remove: function (win, fail, args) {
+        var fs = getFilesystemFromURL(args[0]);
+        var path = pathFromURL(args[0]);
+        if (!fs || !validName(path)){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
 
-        var fullPath = cordovaPathToNative(args[0]);
+        // FileSystem root can't be removed!
+        if (!path || path=='/'){
+			fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
+			return;
+		}
+        var fullPath = cordovaPathToNative(fs.winpath + path);
 
         getFileFromPathAsync(fullPath).then(
             function (storageFile) {
@@ -355,52 +740,36 @@ module.exports = {
                 });
             },
             function () {
-                getFolderFromPathAsync(fullPath).then(
+                getFolderFromPathAsync(fullPath).done(
                     function (sFolder) {
-                        var removeEntry = function () {
-                            var storageFolderTop = null;
-
-                            getFolderFromPathAsync(fullPath).then(
-                                function (storageFolder) {
-                                    // FileSystem root can't be removed!
-                                    var storageFolderPer = Windows.Storage.ApplicationData.current.localFolder;
-                                    var storageFolderTem = Windows.Storage.ApplicationData.current.temporaryFolder;
-                                    if (fullPath == storageFolderPer.path || fullPath == storageFolderTem.path) {
-                                        fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
-                                        return;
-                                    }
-                                    storageFolderTop = storageFolder;
-                                    return storageFolder.getFilesAsync();
-                                }, function () {
-                                    fail(FileError.INVALID_MODIFICATION_ERR);
-
-                                }
-                            // check sub-files.
-                            ).then(function (fileList) {
-                                if (fileList) {
-                                    if (fileList.length === 0) {
-                                        return storageFolderTop.getFoldersAsync();
-                                    } else {
-                                        fail(FileError.INVALID_MODIFICATION_ERR);
-                                    }
-                                }
-                            // check sub-folders.
-                            }).then(function (folderList) {
-                                if (folderList) {
-                                    if (folderList.length === 0) {
-                                        storageFolderTop.deleteAsync().done(win, function () {
-                                            fail(FileError.INVALID_MODIFICATION_ERR);
-
-                                        });
-                                    } else {
-                                        fail(FileError.INVALID_MODIFICATION_ERR);
-                                    }
-                                }
-
-                            });
-                        };
-                        removeEntry();
-                    }, function () {
+                    	sFolder.getFilesAsync()
+						// check for files
+                    	.then(function(fileList) {
+							if (fileList) {
+								if (fileList.length === 0) {
+									return sFolder.getFoldersAsync();
+								} else {
+									fail(FileError.INVALID_MODIFICATION_ERR);
+								}
+							}
+						})
+						// check for folders
+						.done(function (folderList) {
+							if (folderList) {
+								if (folderList.length === 0) {
+									sFolder.deleteAsync().done(
+										win, 
+										function () {
+											fail(FileError.INVALID_MODIFICATION_ERR);
+										}
+									);
+								} else {
+									fail(FileError.INVALID_MODIFICATION_ERR);
+								}
+							}
+						});
+                    }, 
+                    function () {
                         fail(FileError.NOT_FOUND_ERR);
                     }
                 );
@@ -410,17 +779,21 @@ module.exports = {
 
     removeRecursively: function (successCallback, fail, args) {
 
-        var fullPath = cordovaPathToNative(args[0]);
-
-        getFolderFromPathAsync(fullPath).done(function (storageFolder) {
-            var storageFolderPer = Windows.Storage.ApplicationData.current.localFolder;
-            var storageFolderTem = Windows.Storage.ApplicationData.current.temporaryFolder;
+        var fs = getFilesystemFromURL(args[0]);
+        var path = pathFromURL(args[0]);
+        if (!fs || !validName(path)){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
 
-            if (storageFolder.path == storageFolderPer.path || storageFolder.path == storageFolderTem.path) {
-                fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
-                return;
-            }
+        // FileSystem root can't be removed!
+        if (!path || path=='/'){
+			fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
+			return;
+		}
+        var fullPath = cordovaPathToNative(fs.winpath + path);
 
+        getFolderFromPathAsync(fullPath).done(function (storageFolder) {
             storageFolder.deleteAsync().done(function (res) {
                 successCallback(res);
             }, function (err) {
@@ -434,20 +807,22 @@ module.exports = {
 
     getFile: function (win, fail, args) {
 
-        //not sure why, but it won't work with normal slashes...
-        var fullPath = cordovaPathToNative(args[0]);
-        var path = cordovaPathToNative(args[1]);
+        var dirurl = args[0];
+        var path = args[1];
         var options = args[2];
 
-        var completePath = fullPath + '\\' + path;
-        //handles trailing slash and leading slash, or just one or the other
-        completePath = completePath.replace(/\\\\\\/g, '/').replace(/\\\\/g, '\\');
+        var fs = getFilesystemFromURL(dirurl);
+        var dirpath = pathFromURL(dirurl);
+        if (!fs || !validName(path)){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
+        var fspath = sanitize(dirpath +'/'+ path);
+        var completePath = sanitize(fs.winpath + fspath);
 
-        var fileName = completePath.substring(completePath.lastIndexOf('\\'));
+        var fileName = completePath.substring(completePath.lastIndexOf('/')+1);
         
-        //final adjustment
-        fullPath = completePath.substring(0, completePath.lastIndexOf('\\'));
-        path = fileName.replace(/\\/g, '');
+        var wpath = cordovaPathToNative(completePath.substring(0, completePath.lastIndexOf('/')));
 
         var flag = "";
         if (options !== null) {
@@ -456,35 +831,31 @@ module.exports = {
             flag = new Flags(false, false);
         }
 
-        getFolderFromPathAsync(fullPath).then(
+        getFolderFromPathAsync(wpath).done(
             function (storageFolder) {
                 if (flag.create === true && flag.exclusive === true) {
-                    storageFolder.createFileAsync(path, Windows.Storage.CreationCollisionOption.failIfExists).done(
+                    storageFolder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.failIfExists).done(
                         function (storageFile) {
-                            win(new FileEntry(storageFile.name, nativePathToCordova(storageFile.path), getFilesystemFromPath(storageFile.path)));
+                            win(new FileEntry(storageFile.name, fspath, fs.name, fs.makeNativeURL(fspath)));
                         }, function () {
                             fail(FileError.PATH_EXISTS_ERR);
                         }
                     );
                 } else if (flag.create === true && flag.exclusive === false) {
-                    storageFolder.createFileAsync(path, Windows.Storage.CreationCollisionOption.openIfExists).done(
+                    storageFolder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.openIfExists).done(
                         function (storageFile) {
-                            win(new FileEntry(storageFile.name, nativePathToCordova(storageFile.path), getFilesystemFromPath(storageFile.path)));
+                            win(new FileEntry(storageFile.name, fspath, fs.name, fs.makeNativeURL(fspath)));
                         }, function () {
                             fail(FileError.INVALID_MODIFICATION_ERR);
                         }
                     );
                 } else if (flag.create === false) {
-                    if (/\?|\\|\*|\||\"|<|>|\:|\//g.test(path)) {
-                        fail(FileError.ENCODING_ERR);
-                        return;
-                    }
-                    storageFolder.getFileAsync(path).done(
+                    storageFolder.getFileAsync(fileName).done(
                         function (storageFile) {
-                            win(new FileEntry(storageFile.name, nativePathToCordova(storageFile.path), getFilesystemFromPath(storageFile.path)));
+                            win(new FileEntry(storageFile.name, fspath, fs.name, fs.makeNativeURL(fspath)));
                         }, function () {
                             // check if path actually points to a folder
-                            storageFolder.getFolderAsync(path).done(
+                            storageFolder.getFolderAsync(fileName).done(
                                 function () {
                                     fail(FileError.TYPE_MISMATCH_ERR);
                                 }, function () {
@@ -493,32 +864,51 @@ module.exports = {
                         }
                     );
                 }
-            }, function () {
-                fail(FileError.NOT_FOUND_ERR);
+            }, function (err) {
+                fail(
+                	err.number == WinError.accessDenied?
+                	FileError.SECURITY_ERR:
+                	FileError.NOT_FOUND_ERR
+				);
             }
         );
     },
 
     readEntries: function (win, fail, args) { // ["fullPath"]
-
-        var path = cordovaPathToNative(args[0]);
+        var fs = getFilesystemFromURL(args[0]);
+        var path = pathFromURL(args[0]);
+        if (!fs || !validName(path)){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
+        var fullPath = cordovaPathToNative(fs.winpath + path);
 
         var result = [];
 
-        getFolderFromPathAsync(path).then(function (storageFolder) {
+        getFolderFromPathAsync(fullPath).done(function (storageFolder) {
             var promiseArr = [];
             var index = 0;
             promiseArr[index++] = storageFolder.getFilesAsync().then(function (fileList) {
                 if (fileList !== null) {
                     for (var i = 0; i < fileList.length; i++) {
-                        result.push(new FileEntry(fileList[i].name, fileList[i].path, getFilesystemFromPath (fileList[i].path)));
+                    	var fspath = getFsPathForWinPath(fs, fileList[i].path);
+                    	if (!fspath) {
+                    		fail(FileError.NOT_FOUND_ERR);
+                    		return;
+                    	}
+                        result.push(new FileEntry(fileList[i].name, fspath, fs.name, fs.makeNativeURL(fspath)));
                     }
                 }
             });
             promiseArr[index++] = storageFolder.getFoldersAsync().then(function (folderList) {
                 if (folderList !== null) {
                     for (var j = 0; j < folderList.length; j++) {
-                        result.push(new DirectoryEntry(folderList[j].name, folderList[j].path, getFilesystemFromPath(folderList[j].path)));
+                    	var fspath = getFsPathForWinPath(fs, folderList[j].path);
+                    	if (!fspath) {
+                    		fail(FileError.NOT_FOUND_ERR);
+                    		return;
+                    	}
+                        result.push(new DirectoryEntry(folderList[j].name, fspath, fs.name, fs.makeNativeURL(fspath)));
                     }
                 }
             });
@@ -531,17 +921,22 @@ module.exports = {
 
     write: function (win, fail, args) {
 
-        var fileName = cordovaPathToNative(args[0]),
+        var url = args[0],
             data = args[1],
             position = args[2],
             isBinary = args[3];
 
-        fileName = fileName.split("/").join("\\");
-
-        // split path to folder and file name
-        var path = fileName.substring(0, fileName.lastIndexOf('\\')),
-            file = fileName.split('\\').pop();
-
+        var fs = getFilesystemFromURL(url);
+        var path = pathFromURL(url);
+        if (!fs){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
+        var completePath = sanitize(fs.winpath + path);
+        var fileName = completePath.substring(completePath.lastIndexOf('/')+1);
+        var dirpath = completePath.substring(0,completePath.lastIndexOf('/'));
+        var wpath = cordovaPathToNative(dirpath);
+        
         function getWriteMethodForData(data, isBinary) {
             
             if (data instanceof Blob) {
@@ -565,9 +960,9 @@ module.exports = {
 
         var writePromise = getWriteMethodForData(data, isBinary);
 
-        getFolderFromPathAsync(path).done(
+        getFolderFromPathAsync(wpath).done(
             function (storageFolder) {
-                storageFolder.createFileAsync(file, Windows.Storage.CreationCollisionOption.openIfExists).done(
+                storageFolder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.openIfExists).done(
                     function (storageFile) {
                         writePromise(storageFile, data).done(
                             function (bytesWritten) {
@@ -592,11 +987,20 @@ module.exports = {
     },
 
     truncate: function (win, fail, args) { // ["fileName","size"]
-
-        var fileName = cordovaPathToNative(args[0]);
+        var url = args[0];
         var size = args[1];
+        
+        var fs = getFilesystemFromURL(url);
+        var path = pathFromURL(url);
+        if (!fs){
+        	fail(FileError.ENCODING_ERR);
+        	return;
+        }
+        var completePath = sanitize(fs.winpath + path);
+        var wpath = cordovaPathToNative(completePath);
+        var dirwpath = cordovaPathToNative(completePath.substring(0,completePath.lastIndexOf('/')));
 
-        getFileFromPathAsync(fileName).done(function(storageFile){
+        getFileFromPathAsync(wpath).done(function(storageFile){
             //the current length of the file.
             var leng = 0;
 
@@ -611,25 +1015,19 @@ module.exports = {
                         fileContent = fileContent.substr(0, size);
                         var fullPath = storageFile.path;
                         var name = storageFile.name;
-                        var entry = new Entry(true, false, name, fullPath, getFilesystemFromPath(fullPath));
-                        var parentPath = "";
-                        var successCallBack = function (entry) {
-                            parentPath = entry.fullPath;
-                            storageFile.deleteAsync().then(function () {
-                                return getFolderFromPathAsync(parentPath);
-                            }).then(function (storageFolder) {
-                                storageFolder.createFileAsync(name).then(function (newStorageFile) {
-                                    Windows.Storage.FileIO.writeTextAsync(newStorageFile, fileContent).done(function () {
-                                        win(String(fileContent).length);
-                                    }, function () {
-                                        fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
-                                    });
-                                }, function() {
-                                    fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
-                                });
-                            });
-                        };
-                        entry.getParent(successCallBack, null);
+						storageFile.deleteAsync().then(function () {
+							return getFolderFromPathAsync(dirwpath);
+						}).done(function (storageFolder) {
+							storageFolder.createFileAsync(name).then(function (newStorageFile) {
+								Windows.Storage.FileIO.writeTextAsync(newStorageFile, fileContent).done(function () {
+									win(String(fileContent).length);
+								}, function () {
+									fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
+								});
+							}, function() {
+								fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
+							});
+						});
                     }, function () { fail(FileError.NOT_FOUND_ERR); });
                 }
             });
@@ -637,267 +1035,27 @@ module.exports = {
     },
 
     copyTo: function (success, fail, args) { // ["fullPath","parent", "newName"]
-
-        var srcPath = cordovaPathToNative(args[0]);
-        var parentFullPath = cordovaPathToNative(args[1]);
-        var name = args[2];
-
-        //name can't be invalid
-        if (/\?|\\|\*|\||\"|<|>|\:|\//g.test(name)) {
-            fail(FileError.ENCODING_ERR);
-            return;
-        }
-        // copy
-        var copyFiles = "";
-        getFileFromPathAsync(srcPath).then(
-            function (sFile) {
-                copyFiles = function (srcPath, parentPath) {
-                    var storageFileTop = null;
-                    getFileFromPathAsync(srcPath).then(function (storageFile) {
-                        storageFileTop = storageFile;
-                        return getFolderFromPathAsync(parentPath);
-                    }, function () {
-
-                        fail(FileError.NOT_FOUND_ERR);
-                    }).then(function (storageFolder) {
-                        storageFileTop.copyAsync(storageFolder, name, Windows.Storage.NameCollisionOption.failIfExists).then(function (storageFile) {
-
-                            success(new FileEntry(storageFile.name, nativePathToCordova(storageFile.path), getFilesystemFromPath(storageFile.path)));
-                        }, function () {
-
-                            fail(FileError.INVALID_MODIFICATION_ERR);
-                        });
-                    }, function () {
-
-                        fail(FileError.NOT_FOUND_ERR);
-                    });
-                };
-                var copyFinish = function (srcPath, parentPath) {
-                    copyFiles(srcPath, parentPath);
-                };
-                copyFinish(srcPath, parentFullPath);
-            },
-            function () {
-                getFolderFromPathAsync(srcPath).then(
-                    function (sFolder) {
-                        copyFiles = function (srcPath, parentPath) {
-                            var coreCopy = function (storageFolderTop, complete) {
-                                storageFolderTop.getFoldersAsync().then(function (folderList) {
-                                    var folderPromiseArr = [];
-                                    if (folderList.length === 0) { complete(); }
-                                    else {
-                                        getFolderFromPathAsync(parentPath).then(function (storageFolderTarget) {
-                                            var tempPromiseArr = [];
-                                            var index = 0;
-                                            for (var j = 0; j < folderList.length; j++) {
-                                                tempPromiseArr[index++] = storageFolderTarget.createFolderAsync(folderList[j].name).then(function (targetFolder) {
-                                                    folderPromiseArr.push(copyFiles(folderList[j].path, targetFolder.path));
-                                                });
-                                            }
-                                            WinJS.Promise.join(tempPromiseArr).then(function () {
-                                                WinJS.Promise.join(folderPromiseArr).then(complete);
-                                            });
-                                        });
-                                    }
-                                });
-                            };
-
-                            return new WinJS.Promise(function (complete) {
-                                var storageFolderTop = null;
-                                var filePromiseArr = [];
-                                var fileListTop = null;
-                                getFolderFromPathAsync(srcPath).then(function (storageFolder) {
-                                    storageFolderTop = storageFolder;
-                                    return storageFolder.getFilesAsync();
-                                }).then(function (fileList) {
-                                    fileListTop = fileList;
-                                    if (fileList) {
-                                        return getFolderFromPathAsync(parentPath);
-                                    }
-                                }).then(function (targetStorageFolder) {
-                                    for (var i = 0; i < fileListTop.length; i++) {
-                                        filePromiseArr.push(fileListTop[i].copyAsync(targetStorageFolder));
-                                    }
-                                    WinJS.Promise.join(filePromiseArr).done(function () {
-                                        coreCopy(storageFolderTop, complete);
-                                    }, function() {
-                                        fail(FileError.INVALID_MODIFICATION_ERR);
-                                    });
-                                });
-                            });
-                        };
-                        var copyFinish = function (srcPath, parentPath) {
-                            getFolderFromPathAsync(parentPath).then(function (storageFolder) {
-                                storageFolder.createFolderAsync(name, Windows.Storage.CreationCollisionOption.openIfExists).then(function (newStorageFolder) {
-                                    //can't copy onto itself
-                                    if (srcPath == newStorageFolder.path) {
-                                        fail(FileError.INVALID_MODIFICATION_ERR);
-                                        return;
-                                    }
-                                    //can't copy into itself
-                                    if (srcPath == parentPath) {
-                                        fail(FileError.INVALID_MODIFICATION_ERR);
-                                        return;
-                                    }
-                                    copyFiles(srcPath, newStorageFolder.path).then(function () {
-                                        getFolderFromPathAsync(newStorageFolder.path).done(
-                                            function (storageFolder) {
-                                                success(new DirectoryEntry(storageFolder.name, nativePathToCordova(storageFolder.path), getFilesystemFromPath(storageFolder.path)));
-                                            },
-                                            function () { fail(FileError.NOT_FOUND_ERR); }
-                                        );
-                                    });
-                                }, function () { fail(FileError.INVALID_MODIFICATION_ERR); });
-                            }, function () { fail(FileError.INVALID_MODIFICATION_ERR); });
-                        };
-                        copyFinish(srcPath, parentFullPath);
-                    }, function () {
-                        fail(FileError.NOT_FOUND_ERR);
-                    }
-                );
-            }
-        );
+    	transport(success, fail, args,
+    		{
+    			fileOp:function(file,folder,name,coll) {
+    				return file.copyAsync(folder,name,coll);
+    			},
+    			folderOp:function(src,dst,name) {
+    				return copyFolder(src,dst,name);
+			}}
+		);
     },
 
     moveTo: function (success, fail, args) {
-
-        var srcPath = cordovaPathToNative(args[0]);
-        var parentFullPath = cordovaPathToNative(args[1]);
-        var name = args[2];
-
-
-        //name can't be invalid
-        if (/\?|\\|\*|\||\"|<|>|\:|\//g.test(name)) {
-            fail(FileError.ENCODING_ERR);
-            return;
-        }
-
-        var moveFiles = "";
-        getFileFromPathAsync(srcPath).then(
-            function (sFile) {
-                moveFiles = function (srcPath, parentPath) {
-                    var storageFileTop = null;
-                    getFileFromPathAsync(srcPath).then(function (storageFile) {
-                        storageFileTop = storageFile;
-                        return getFolderFromPathAsync(parentPath);
-                    }, function () {
-                        fail(FileError.NOT_FOUND_ERR);
-                    }).then(function (storageFolder) {
-                        storageFileTop.moveAsync(storageFolder, name, Windows.Storage.NameCollisionOption.replaceExisting).then(function () {
-                            success(new FileEntry(name, nativePathToCordova(storageFileTop.path), getFilesystemFromPath(storageFolder.path)));
-                        }, function () {
-                            fail(FileError.INVALID_MODIFICATION_ERR);
-                        });
-                    }, function () {
-                        fail(FileError.NOT_FOUND_ERR);
-                    });
-                };
-                var moveFinish = function (srcPath, parentPath) {
-                    //can't copy onto itself
-                    if (srcPath == parentPath + "\\" + name) {
-                        fail(FileError.INVALID_MODIFICATION_ERR);
-                        return;
-                    }
-                    moveFiles(srcPath, parentFullPath);
-                };
-                moveFinish(srcPath, parentFullPath);
-            },
-            function () {
-                getFolderFromPathAsync(srcPath).then(
-                    function (sFolder) {
-                        moveFiles = function (srcPath, parentPath) {
-                            var coreMove = function (storageFolderTop, complete) {
-                                storageFolderTop.getFoldersAsync().then(function (folderList) {
-                                    var folderPromiseArr = [];
-                                    if (folderList.length === 0) {
-                                        // If failed, we must cancel the deletion of folders & files.So here wo can't delete the folder.
-                                        complete();
-                                    }
-                                    else {
-                                        getFolderFromPathAsync(parentPath).then(function (storageFolderTarget) {
-                                            var tempPromiseArr = [];
-                                            var index = 0;
-                                            for (var j = 0; j < folderList.length; j++) {
-                                                tempPromiseArr[index++] = storageFolderTarget.createFolderAsync(folderList[j].name).then(function (targetFolder) {
-                                                    folderPromiseArr.push(moveFiles(folderList[j].path, targetFolder.path));
-                                                });
-                                            }
-                                            WinJS.Promise.join(tempPromiseArr).then(function () {
-                                                WinJS.Promise.join(folderPromiseArr).then(complete);
-                                            });
-                                        });
-                                    }
-                                });
-                            };
-                            return new WinJS.Promise(function (complete) {
-                                var storageFolderTop = null;
-                                getFolderFromPathAsync(srcPath).then(function (storageFolder) {
-                                    storageFolderTop = storageFolder;
-                                    return storageFolder.getFilesAsync();
-                                }).then(function (fileList) {
-                                    var filePromiseArr = [];
-                                    getFolderFromPathAsync(parentPath).then(function (dstStorageFolder) {
-                                        if (fileList) {
-                                            for (var i = 0; i < fileList.length; i++) {
-                                                filePromiseArr.push(fileList[i].moveAsync(dstStorageFolder));
-                                            }
-                                        }
-                                        WinJS.Promise.join(filePromiseArr).then(function () {
-                                            coreMove(storageFolderTop, complete);
-                                        }, function () { });
-                                    });
-                                });
-                            });
-                        };
-                        var moveFinish = function (srcPath, parentPath) {
-                            var originFolderTop = null;
-                            getFolderFromPathAsync(srcPath).then(function (originFolder) {
-                                originFolderTop = originFolder;
-                                return getFolderFromPathAsync(parentPath);
-                            }, function () {
-                                fail(FileError.INVALID_MODIFICATION_ERR);
-                            }).then(function (storageFolder) {
-                                return storageFolder.createFolderAsync(name, Windows.Storage.CreationCollisionOption.openIfExists);
-                            }, function () {
-                                fail(FileError.INVALID_MODIFICATION_ERR);
-                            }).then(function (newStorageFolder) {
-                                //can't move onto directory that is not empty
-                                newStorageFolder.getFilesAsync().then(function (fileList) {
-                                    newStorageFolder.getFoldersAsync().then(function (folderList) {
-                                        if (fileList.length !== 0 || folderList.length !== 0) {
-                                            fail(FileError.INVALID_MODIFICATION_ERR);
-                                            return;
-                                        }
-                                        //can't copy onto itself
-                                        if (srcPath == newStorageFolder.path) {
-                                            fail(FileError.INVALID_MODIFICATION_ERR);
-                                            return;
-                                        }
-                                        //can't copy into itself
-                                        if (srcPath == parentPath) {
-                                            fail(FileError.INVALID_MODIFICATION_ERR);
-                                            return;
-                                        }
-                                        moveFiles(srcPath, newStorageFolder.path).then(function () {
-                                            var successCallback = function () {
-                                                success(new DirectoryEntry(name, nativePathToCordova(newStorageFolder.path), getFilesystemFromPath(newStorageFolder.path)));
-                                            };
-
-                                            originFolderTop.deleteAsync().done(successCallback, fail);
-
-                                        }, function () { console.log("error!"); });
-                                    });
-                                });
-                            }, function () { fail(FileError.INVALID_MODIFICATION_ERR); });
-
-                        };
-                        moveFinish(srcPath, parentFullPath);
-                    }, function () {
-                        fail(FileError.NOT_FOUND_ERR);
-                    }
-                );
-            }
-        );
+    	transport(success, fail, args,
+    		{
+    			fileOp:function(file,folder,name,coll) {
+    				return file.moveAsync(folder,name,coll);
+    			},
+    			folderOp:function(src,dst,name) {
+    				return moveFolder(src,dst,name);
+			}}
+		);
     },
     tempFileSystem:null,
 
@@ -907,76 +1065,47 @@ module.exports = {
 
         var type = args[0];
         var size = args[1];
-
-        var filePath = "";
-        var result = null;
-        var fsTypeName = "";
-
+        var MAX_SIZE = 10000000000;
+        if (size > MAX_SIZE) {
+            fail(FileError.QUOTA_EXCEEDED_ERR);
+            return;
+        }
+        
+        var fs;
         switch (type) {
             case LocalFileSystem.TEMPORARY:
-                filePath = Windows.Storage.ApplicationData.current.temporaryFolder.path;
-                fsTypeName = "temporary";
+            	fs = getFS('temporary');
                 break;
             case LocalFileSystem.PERSISTENT:
-                filePath = Windows.Storage.ApplicationData.current.localFolder.path;
-                fsTypeName = "persistent";
+            	fs = getFS('persistent');
                 break;
         }
-
-        var MAX_SIZE = 10000000000;
-        if (size > MAX_SIZE) {
-            fail(FileError.QUOTA_EXCEEDED_ERR);
-            return;
-        }
-
-        var fileSystem = new FileSystem(fsTypeName, new DirectoryEntry(fsTypeName, nativePathToCordova(filePath)));
-        result = fileSystem;
-        win(result);
+        if (fs)
+        	win(fs);
+        else
+        	fail(FileError.NOT_FOUND_ERR);
     },
 
     resolveLocalFileSystemURI: function (success, fail, args) {
 
         var uri = args[0];
-        var path = cordovaPathToNative(uri);
+        var inputURL;
 
-        // support for file name with parameters
-        if (/\?/g.test(path)) {
-            path = String(path).split("?")[0];
+        var path = pathFromURL(uri);
+		var fs = getFilesystemFromURL(uri);
+        if (!fs || !validName(path)) {
+        	fail(FileError.ENCODING_ERR);
+        	return;
         }
-
-        // support for encodeURI
-        if (/\%5/g.test(path)) {
-            path = decodeURI(path);
-        }
-
-        var msappdataLocalPrefix = 'ms-appdata:///local/',
-            msappdataTempPrefix = 'ms-appdata:///temp/',
-            msappdataLocalPath = Windows.Storage.ApplicationData.current.localFolder.path + '\\',
-            msappdataTempPath = Windows.Storage.ApplicationData.current.temporaryFolder.path + '\\';
-
-        // support for special path start with file:/// or ms-appdata://
-        if (uri.indexOf("file:///") === 0 ) {
-            path = msappdataLocalPath + uri.substr(8).replace('/', '\\');
-        } else if (uri.indexOf(msappdataLocalPrefix) === 0) {
-            path = msappdataLocalPath + uri.replace(msappdataLocalPrefix, '').replace('/', '\\');
-        } else if (uri.indexOf(msappdataTempPrefix) === 0) {
-            path = msappdataTempPath + uri.replace(msappdataTempPrefix, '').replace('/', '\\');
-        } else {
-            // method should not let read files outside of the [APP HASH]/Local or [APP HASH]/temp folders
-            if (path.indexOf(msappdataTempPath) != 0 && path.indexOf(msappdataLocalPath) != 0) {
-                fail(FileError.NOT_FOUND_ERR);
-                return;
-            }
-        }
-
-        getFileFromPathAsync(path).then(
+		var abspath = cordovaPathToNative(fs.winpath+path);
+		
+        getFileFromPathAsync(abspath).done(
             function (storageFile) {
-                success(new FileEntry(storageFile.name, nativePathToCordova(storageFile.path), getFilesystemFromPath(storageFile.path)));
+                success(new FileEntry(storageFile.name, path, fs, fs.makeNativeURL(path)));
             }, function () {
-                getFolderFromPathAsync(path).then(
+                getFolderFromPathAsync(abspath).done(
                     function (storageFolder) {
-                        var cordovaPath = nativePathToCordova(storageFolder.path);
-                        success(new DirectoryEntry(storageFolder.name, cordovaPath, getFilesystemFromPath(storageFolder.path), cordovaPath));
+                        success(new DirectoryEntry(storageFolder.name, path, fs,fs.makeNativeURL(path)));
                     }, function () {
                         fail(FileError.NOT_FOUND_ERR);
                     }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3dfd3e9a/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 6d625b9..5ace795 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -2652,17 +2652,20 @@ exports.defineAutoTests = function () {
                 /* This is a direct copy of file.spec.9, with the filename changed, * as reported in CB-5721.
                  */
                 var fileName = "resolve.file.uri";
+                var dirName = "resolve.dir.uri";
                 // create a new file entry
-                createFile("../" + fileName, function (entry) {
-                    // lookup file system entry
-                    window.resolveLocalFileSystemURL(entry.toURL(), function (fileEntry) {
-                        expect(fileEntry).toBeDefined();
-                        expect(fileEntry.name).toCanonicallyMatch(fileName);
-                        // cleanup
-                        deleteEntry(fileName);
-                        done();
-                    }, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving URI: ' + entry.toURL()));
-                }, failed.bind(null, done, 'createFile - Error creating file: ../' + fileName));
+				createDirectory(dirName, function () {
+					createFile(dirName+"/../" + fileName, function (entry) {
+						// lookup file system entry
+						window.resolveLocalFileSystemURL(entry.toURL(), function (fileEntry) {
+							expect(fileEntry).toBeDefined();
+							expect(fileEntry.name).toCanonicallyMatch(fileName);
+							// cleanup
+							deleteEntry(fileName);
+							done();
+						}, failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving URI: ' + entry.toURL()));
+					}, failed.bind(null, done, 'createFile - Error creating file: ../' + fileName));
+				}, failed.bind(null, done, 'createDirectory - Error creating directory: ' + dirName));
             });
             it("file.spec.111 should not traverse above above the root directory", function (done) {
                 var fileName = "traverse.file.uri";
@@ -2671,14 +2674,11 @@ exports.defineAutoTests = function () {
                     // lookup file system entry
                     root.getFile('../' + fileName, {
                         create : false
-                    }, function (fileEntry) {
-                        expect(fileEntry).toBeDefined();
-                        expect(fileEntry.name).toBe(fileName);
-                        expect(fileEntry.fullPath).toCanonicallyMatch('/' + fileName);
-                        // cleanup
-                        deleteEntry(fileName);
-                        done();
-                    }, failed.bind(null, done, 'root.getFile - Error getting file: ../' + fileName));
+                    }, succeed.bind(null, done, "root.getFile('../"+fileName+ "')- Unexpected success callback, it should not traverse abvoe the root directory"), 
+                    function (error) {
+                    	expect(error).toBeDefined();
+                    	done();
+                    });
                 }, failed.bind(null, done, 'createFile - Error creating file: ../' + fileName));
             });
             it("file.spec.112 should traverse above above the current directory", function (done) {
@@ -2709,7 +2709,10 @@ exports.defineAutoTests = function () {
                     create : false
                 }, succeed.bind(null, done, 'root.getFile - Unexpected success callback, it should not locate nonexistent file: ' + fileName), function (error) {
                     expect(error).toBeDefined();
-                    expect(error).toBeFileError(FileError.NOT_FOUND_ERR);
+                    if (cordova.platformId == "windows")
+                    	expect(error).toBeFileError(FileError.SECURITY_ERR);
+                    else
+						expect(error).toBeFileError(FileError.NOT_FOUND_ERR);
                     done();
                 });
             });
@@ -2729,7 +2732,8 @@ exports.defineAutoTests = function () {
                     expect(typeof entry.toNativeURL).toBe('function');
                     var nativeURL = entry.toNativeURL();
                     expect(typeof nativeURL).toBe("string");
-                    expect(nativeURL.substring(0, 7)).toEqual(pathExpect);
+                    if (cordova.platformId != "windows")
+						expect(nativeURL.substring(0, 7)).toEqual(pathExpect);
                     expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
                     // cleanup
                     deleteEntry(fileName);
@@ -2747,7 +2751,8 @@ exports.defineAutoTests = function () {
                     expect(typeof entries[0].toNativeURL).toBe('function');
                     var nativeURL = entries[0].toNativeURL();
                     expect(typeof nativeURL).toBe("string");
-                    expect(nativeURL.substring(0, 7)).toEqual(pathExpect);
+                    if (cordova.platformId != "windows")
+						expect(nativeURL.substring(0, 7)).toEqual(pathExpect);
                     expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
                     // cleanup
                     directory.removeRecursively(null, null);
@@ -2775,7 +2780,8 @@ exports.defineAutoTests = function () {
                         expect(typeof entry.toNativeURL).toBe('function');
                         var nativeURL = entry.toNativeURL();
                         expect(typeof nativeURL).toBe("string");
-                        expect(nativeURL.substring(0, 7)).toEqual(pathExpect);
+                        if (cordova.platformId != "windows")
+                        	expect(nativeURL.substring(0, 7)).toEqual(pathExpect);
                         expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
                         // cleanup
                         deleteEntry(fileName);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message