cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/2] git commit: CB-6923 Adding support to handle relative paths
Date Tue, 12 Aug 2014 01:33:48 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master c8c0f1200 -> aaba3274a


CB-6923 Adding support to handle relative paths

Added support to resolve relative paths.
When the path received is relative, it will combine and obtain a full
path before it becomes proceced by IsolatedStorageFile and determine if
exists.

Two private methods were added to handle this, it won't affect the
regular workflow if the path is absolute and it will combine it as
usual.


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/4152181c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/4152181c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/4152181c

Branch: refs/heads/master
Commit: 4152181c99251360eeddd8ec54795e4b8874d48e
Parents: 56976ae
Author: Martin Gonzalez <martin.c.glez.glez@gmail.com>
Authored: Tue Jul 22 15:09:20 2014 -0500
Committer: Martin Gonzalez <martin.c.glez.glez@gmail.com>
Committed: Tue Jul 22 15:09:20 2014 -0500

----------------------------------------------------------------------
 src/wp/File.cs | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/4152181c/src/wp/File.cs
----------------------------------------------------------------------
diff --git a/src/wp/File.cs b/src/wp/File.cs
index 07143b9..0f2fe50 100644
--- a/src/wp/File.cs
+++ b/src/wp/File.cs
@@ -1501,6 +1501,35 @@ namespace WPCordovaClassLib.Cordova.Commands
             }
         }
 
+        private string RemoveExtraSlash(string path) {
+            if (path.StartsWith("//")) {
+                path = path.Remove(0, 1);
+                path = RemoveExtraSlash(path);
+            }
+            return path;
+        }
+
+        private string ResolvePath(string parentPath, string path)
+        {   
+            string absolutePath = null;
+            
+            if (path.Contains(".."))
+            {
+                if (parentPath.Length > 1 && parentPath.StartsWith("/") &&
parentPath !="/")
+                {
+                    parentPath = RemoveExtraSlash(parentPath);
+                }
+                
+                string fullPath = Path.GetFullPath(Path.Combine(parentPath, path));
+                absolutePath = fullPath.Replace(Path.GetPathRoot(fullPath), @"//");
+            }
+            else
+            {
+                absolutePath = Path.Combine(parentPath + "/", path);
+            }
+            return absolutePath;
+        }
+
         private void GetFileOrDirectory(string options, bool getDirectory)
         {
             FileOptions fOptions = new FileOptions();
@@ -1539,13 +1568,13 @@ namespace WPCordovaClassLib.Cordova.Commands
 
                 try
                 {
-                    path = Path.Combine(fOptions.FullPath + "/", fOptions.Path);
+                    path = ResolvePath(fOptions.FullPath, fOptions.Path);
                 }
                 catch (Exception)
                 {
                     DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ENCODING_ERR),
callbackId);
                     return;
-                }        
+                }
 
                 using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                 {


Mime
View raw message