[CB-339] Should not be able to create a file or directory if the parent 
directory does not exist.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/79792880
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/79792880
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/79792880

Branch: refs/heads/master
Commit: 79792880b12574dda080c5f24c5f5bf8f3223ce6
Parents: d805058
Author: Jesse MacFadyen <[email protected]>
Authored: Thu Nov 8 16:59:12 2012 -0800
Committer: Jesse MacFadyen <[email protected]>
Committed: Thu Nov 8 16:59:12 2012 -0800

----------------------------------------------------------------------
 templates/standalone/cordovalib/Commands/File.cs |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/79792880/templates/standalone/cordovalib/Commands/File.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/File.cs 
b/templates/standalone/cordovalib/Commands/File.cs
index 579dd6e..af7fc26 100644
--- a/templates/standalone/cordovalib/Commands/File.cs
+++ b/templates/standalone/cordovalib/Commands/File.cs
@@ -1406,6 +1406,21 @@ namespace WP7CordovaClassLib.Cordova.Commands
                             return;
                         }
 
+                        // need to make sure the parent exists
+                        // it is an error to create a directory whose 
immediate parent does not yet exist
+                        string[] pathParts = path.Split('/');
+                        string builtPath = pathParts[0];
+                        for (int n = 1; n < pathParts.Length - 1; n++)
+                        {
+                            builtPath += "/" + pathParts[n];
+                            if (!isoFile.DirectoryExists(builtPath))
+                            {
+                                Debug.WriteLine(String.Format("Error :: Parent 
folder \"{0}\" does not exist, when attempting to create 
\"{1}\"",builtPath,path));
+                                DispatchCommandResult(new 
PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR));
+                                return;
+                            }
+                        }
+
                         if ((getDirectory) && (!isDirectory))
                         {
                             isoFile.CreateDirectory(path);

Reply via email to