2010-06-02 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Wed, 2 Jun 2010 18:30:40 +0000 (18:30 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Wed, 2 Jun 2010 18:30:40 +0000 (18:30 -0000)
* IsolatedStorageFile.cs: Check for empty paths and existing paths in
both MoveFile and MoveDirectory, just as we do in CopyFile. Finally
cover our IO calls with a try-catch block, so all the IOException
instances are reported as IsolatedStorageException.

svn path=/trunk/mcs/; revision=158355

mcs/class/corlib/System.IO.IsolatedStorage/ChangeLog
mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs

index 2f56dcfc23cd554686fa83b2f822e7a885638ea7..b42a53902ecedf50551ae7c0ce20c85d083b0358 100644 (file)
@@ -1,3 +1,10 @@
+2010-06-02  Carlos Alberto Cortez <calberto.cortez@gmail.com>
+
+       * IsolatedStorageFile.cs: Check for empty paths and existing paths in
+       both MoveFile and MoveDirectory, just as we do in CopyFile. Finally
+       cover our IO calls with a try-catch block, so all the IOException
+       instances are reported as IsolatedStorageException.
+
 2010-05-31  Carlos Alberto Cortez <calberto.cortez@gmail.com>
 
        * IsolatedStorage.cs:
index d4878b7f21836aa5e5d6ee1ff5248219e0cc0628..ff62bda7c96b032e5b792c22fe075e88a73c0f09 100644 (file)
@@ -779,10 +779,26 @@ namespace System.IO.IsolatedStorage {
                                throw new ArgumentNullException ("sourceDirectoryName");
                        if (destinationDirectoryName == null)
                                throw new ArgumentNullException ("sourceDirectoryName");
+                       if (sourceDirectoryName.Trim ().Length == 0)
+                               throw new ArgumentException ("An empty directory name is not valid.", "sourceDirectoryName");
+                       if (destinationDirectoryName.Trim ().Length == 0)
+                               throw new ArgumentException ("An empty directory name is not valid.", "destinationDirectoryName");
 
                        CheckOpen ();
-                       Directory.Move (Path.Combine (directory.FullName, sourceDirectoryName),
-                                       Path.Combine (directory.FullName, destinationDirectoryName));
+
+                       string src_full_path = Path.Combine (directory.FullName, sourceDirectoryName);
+                       string dest_full_path = Path.Combine (directory.FullName, destinationDirectoryName);
+
+                       if (!Directory.Exists (src_full_path))
+                               throw new DirectoryNotFoundException ("Could not find a part of path '" + sourceDirectoryName + "'.");
+                       if (!Directory.Exists (Path.GetDirectoryName (dest_full_path)))
+                               throw new DirectoryNotFoundException ("Could not find a part of path '" + destinationDirectoryName + "'.");
+
+                       try {
+                               Directory.Move (src_full_path, dest_full_path);
+                       } catch (IOException) {
+                               throw new IsolatedStorageException ("Operation not allowed.");
+                       }
                }
 
                [ComVisible (false)]
@@ -792,10 +808,27 @@ namespace System.IO.IsolatedStorage {
                                throw new ArgumentNullException ("sourceFileName");
                        if (destinationFileName == null)
                                throw new ArgumentNullException ("sourceFileName");
+                       if (sourceFileName.Trim ().Length == 0)
+                               throw new ArgumentException ("An empty file name is not valid.", "sourceFileName");
+                       if (destinationFileName.Trim ().Length == 0)
+                               throw new ArgumentException ("An empty file name is not valid.", "destinationFileName");
 
                        CheckOpen ();
-                       File.Move (Path.Combine (directory.FullName, sourceFileName),
-                                       Path.Combine (directory.FullName, destinationFileName));
+
+                       string source_full_path = Path.Combine (directory.FullName, sourceFileName);
+                       string dest_full_path = Path.Combine (directory.FullName, destinationFileName);
+
+                       if (!File.Exists (source_full_path))
+                               throw new FileNotFoundException ("Could not find a part of path '" + sourceFileName + "'.");
+                       // I expected a DirectoryNotFound exception.
+                       if (!Directory.Exists (Path.GetDirectoryName (dest_full_path)))
+                               throw new IsolatedStorageException ("Operation not allowed.");
+
+                       try {
+                               File.Move (source_full_path, dest_full_path);
+                       } catch (IOException) {
+                               throw new IsolatedStorageException ("Operation not allowed.");
+                       }
                }
 
                [ComVisible (false)]