You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/08/15 01:50:13 UTC
[2/5] wp7 commit: File tests passing
File tests passing
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/47e4b1ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/47e4b1ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/47e4b1ae
Branch: refs/heads/master
Commit: 47e4b1ae59285ef0fb9d3d9251782d24fd324ae7
Parents: f82ab3d
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Aug 14 16:45:51 2012 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Aug 14 16:45:51 2012 -0700
----------------------------------------------------------------------
templates/standalone/cordovalib/Commands/File.cs | 131 +++++++++++------
1 files changed, 88 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/47e4b1ae/templates/standalone/cordovalib/Commands/File.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/File.cs b/templates/standalone/cordovalib/Commands/File.cs
index 5be792f..cbfc314 100644
--- a/templates/standalone/cordovalib/Commands/File.cs
+++ b/templates/standalone/cordovalib/Commands/File.cs
@@ -302,9 +302,9 @@ namespace WP7CordovaClassLib.Cordova.Commands
entry = new FileEntry(filePath);
}
- catch (Exception)
+ catch (Exception ex)
{
- Debug.WriteLine("Exception in GetEntry for filePath :: " + filePath);
+ Debug.WriteLine("Exception in GetEntry for filePath :: " + filePath + " " + ex.Message);
}
return entry;
}
@@ -319,6 +319,12 @@ namespace WP7CordovaClassLib.Cordova.Commands
{
throw new ArgumentException();
}
+
+ if(filePath.Contains(" "))
+ {
+ Debug.WriteLine("FilePath with spaces :: " + filePath);
+ }
+
using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
{
this.IsFile = isoFile.FileExists(filePath);
@@ -340,7 +346,14 @@ namespace WP7CordovaClassLib.Cordova.Commands
throw new FileNotFoundException();
}
- this.FullPath = new Uri(filePath).LocalPath;
+ try
+ {
+ this.FullPath = filePath;// new Uri(filePath).LocalPath;
+ }
+ catch (Exception ex)
+ {
+
+ }
}
}
@@ -810,6 +823,8 @@ namespace WP7CordovaClassLib.Cordova.Commands
if (isoFile.FileExists(filePath) || isoFile.DirectoryExists(filePath))
{
+
+
string path = this.GetParentDirectory(filePath);
entry = FileEntry.GetEntry(path);
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, entry));
@@ -838,6 +853,10 @@ namespace WP7CordovaClassLib.Cordova.Commands
{
try
{
+ if (filePath == "/" || filePath == "" || filePath == @"\")
+ {
+ throw new Exception("Cannot delete root file system") ;
+ }
using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isoFile.FileExists(filePath))
@@ -923,10 +942,6 @@ namespace WP7CordovaClassLib.Cordova.Commands
}
}
}
- //catch (SecurityException)
- //{
- // DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, SECURITY_ERR));
- //}
catch (Exception ex)
{
if (!this.HandleException(ex))
@@ -945,6 +960,8 @@ namespace WP7CordovaClassLib.Cordova.Commands
double fileSystemType = optVals[0];
double size = optVals[1];
+ IsolatedStorageFile.GetUserStoreForApplication();
+
if (size > (10 * 1024 * 1024)) // 10 MB, compier will clean this up!
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, QUOTA_EXCEEDED_ERR));
@@ -999,14 +1016,6 @@ namespace WP7CordovaClassLib.Cordova.Commands
}
}
- //catch (SecurityException)
- //{
- // DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, SECURITY_ERR));
- //}
- //catch (FileNotFoundException)
- //{
- // DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR));
- //}
catch (Exception ex)
{
if (!this.HandleException(ex))
@@ -1019,23 +1028,20 @@ namespace WP7CordovaClassLib.Cordova.Commands
public void resolveLocalFileSystemURI(string options)
{
string uri = getSingleStringOption(options).Split('?')[0];
+
if (uri != null)
{
+ // a single '/' is valid, however, '/someDir' is not, but '/tmp//somedir' is valid
+ if (uri.StartsWith("/") && uri.IndexOf("//") < 0 && uri != "/")
+ {
+ Debug.WriteLine("Starts with / ::: " + uri);
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ENCODING_ERR));
+ return;
+ }
try
{
- if (!Uri.IsWellFormedUriString(uri, UriKind.Absolute))
- {
- DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ENCODING_ERR));
- return;
- }
-
- Uri fileUri = new Uri(Uri.UnescapeDataString(uri));
- string path = fileUri.LocalPath;
-
- // TODO: research this :
- //if (Uri.UriSchemeFile == fileUri.Scheme)
- //{
- //}
+ // fix encoded spaces
+ string path = Uri.UnescapeDataString(uri);
FileEntry uriEntry = FileEntry.GetEntry(path);
if (uriEntry != null)
@@ -1047,10 +1053,6 @@ namespace WP7CordovaClassLib.Cordova.Commands
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR));
}
}
- //catch (SecurityException)
- //{
- // DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, SECURITY_ERR));
- //}
catch (Exception ex)
{
if (!this.HandleException(ex))
@@ -1100,13 +1102,25 @@ namespace WP7CordovaClassLib.Cordova.Commands
return this.GetParentDirectory(Path.GetDirectoryName(path));
}
- return Path.GetDirectoryName(path);
+ string result = Path.GetDirectoryName(path);
+ if (result == null)
+ {
+ result = "/";
+ }
+
+ return result;
}
private void removeDirRecursively(string fullPath)
{
try
{
+ if (fullPath == "/")
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NO_MODIFICATION_ALLOWED_ERR));
+ return;
+ }
+
using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isoFile.DirectoryExists(fullPath))
@@ -1128,7 +1142,7 @@ namespace WP7CordovaClassLib.Cordova.Commands
removeDirRecursively(path + dir + "/");
}
}
- isoFile.DeleteDirectory(Path.GetDirectoryName(path));
+ isoFile.DeleteDirectory(fullPath);
}
else
{
@@ -1145,6 +1159,14 @@ namespace WP7CordovaClassLib.Cordova.Commands
}
}
+ private bool CanonicalCompare(string pathA, string pathB)
+ {
+ string a = pathA.Replace("//", "/");
+ string b = pathB.Replace("//", "/");
+
+ return a.Equals(b, StringComparison.OrdinalIgnoreCase);
+ }
+
/*
* copyTo:["fullPath","parent", "newName"],
* moveTo:["fullPath","parent", "newName"],
@@ -1157,6 +1179,14 @@ namespace WP7CordovaClassLib.Cordova.Commands
string parent = optStrings[1];
string newFileName = optStrings[2];
+ char[] invalids = Path.GetInvalidPathChars();
+
+ if (newFileName.IndexOfAny(invalids) > -1 || newFileName.IndexOf(":") > -1 )
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ENCODING_ERR));
+ return;
+ }
+
try
{
if ((parent == null) || (string.IsNullOrEmpty(parent)) || (string.IsNullOrEmpty(fullPath)))
@@ -1174,7 +1204,7 @@ namespace WP7CordovaClassLib.Cordova.Commands
bool isDirectoryExist = isoFile.DirectoryExists(currentPath);
bool isParentExist = isoFile.DirectoryExists(parentPath);
- if (((!isFileExist) && (!isDirectoryExist)) || (!isParentExist))
+ if ( ( !isFileExist && !isDirectoryExist ) || !isParentExist )
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR));
return;
@@ -1188,10 +1218,16 @@ namespace WP7CordovaClassLib.Cordova.Commands
: newFileName;
newPath = Path.Combine(parentPath, newName);
-
- // remove destination file if exists, in other case there will be exception
- if (!newPath.Equals(currentPath) && isoFile.FileExists(newPath))
+
+ // sanity check ..
+ // cannot copy file onto itself
+ if (CanonicalCompare(newPath,currentPath)) //(parent + newFileName))
{
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, INVALID_MODIFICATION_ERR));
+ return;
+ }
+ else if (isoFile.FileExists(newPath))
+ { // remove destination file if exists, in other case there will be exception
isoFile.DeleteFile(newPath);
}
@@ -1214,7 +1250,6 @@ namespace WP7CordovaClassLib.Cordova.Commands
if (move)
{
-
// remove destination directory if exists, in other case there will be exception
// target directory should be empty
if (!newPath.Equals(currentPath) && isoFile.DirectoryExists(newPath))
@@ -1226,7 +1261,7 @@ namespace WP7CordovaClassLib.Cordova.Commands
}
else
{
- this.CopyDirectory(currentPath, newPath, isoFile);
+ CopyDirectory(currentPath, newPath, isoFile);
}
}
FileEntry entry = FileEntry.GetEntry(newPath);
@@ -1285,17 +1320,22 @@ namespace WP7CordovaClassLib.Cordova.Commands
{
string path = File.AddSlashToDirectory(sourceDir);
- if (!isoFile.DirectoryExists(destDir))
+ bool bExists = isoFile.DirectoryExists(destDir);
+
+ if (!bExists)
{
isoFile.CreateDirectory(destDir);
}
+
destDir = File.AddSlashToDirectory(destDir);
+
string[] files = isoFile.GetFileNames(path + "*");
+
if (files.Length > 0)
{
foreach (string file in files)
{
- isoFile.CopyFile(path + file, destDir + file);
+ isoFile.CopyFile(path + file, destDir + file,true);
}
}
string[] dirs = isoFile.GetDirectoryNames(path + "*");
@@ -1336,6 +1376,12 @@ namespace WP7CordovaClassLib.Cordova.Commands
string path;
+ if (fOptions.Path.Split(':').Length > 2)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ENCODING_ERR));
+ return;
+ }
+
try
{
path = Path.Combine(fOptions.FullPath + "/", fOptions.Path);
@@ -1373,7 +1419,6 @@ namespace WP7CordovaClassLib.Cordova.Commands
fileStream.Close();
}
}
-
}
else
{