2004-04-02 Dick Porter <dick@ximian.com>
[mono.git] / mcs / class / corlib / System.IO / FileInfo.cs
index 87a1f94747ab6e242e42da2700018f194ae938b0..62e79d489ecaddc5de87f3afdfe67dfffc87037e 100644 (file)
@@ -17,12 +17,21 @@ namespace System.IO {
        [Serializable]
        public sealed class FileInfo : FileSystemInfo {\r
        \r
+
+               private bool exists;
+
                public FileInfo (string path) {\r
                        CheckPath (path);\r
                \r
                        OriginalPath = path;\r
-                       FullPath = Path.GetFullPath (path);\r
+                       FullPath = Path.GetFullPath (path);
                }\r
+               \r
+               internal override void InternalRefresh ()\r
+               {\r
+                       exists = File.Exists (FullPath);\r
+               }\r
+\r
 \r
                // public properties\r
 \r
@@ -36,7 +45,7 @@ namespace System.IO {
                                if ((stat.Attributes & FileAttributes.Directory) != 0)\r
                                        return false;\r
 \r
-                               return true;\r
+                               return exists;
                        }\r
                }\r
 \r
@@ -110,25 +119,46 @@ namespace System.IO {
                }\r
 \r
                // file methods\r
-\r
-               public override void Delete () {\r
-                       if (!MonoIO.Exists (FullPath))          // a weird MS.NET behaviour\r
-                               return;\r
-               \r
-                       if (!MonoIO.DeleteFile (FullPath))\r
-                               throw MonoIO.GetException (OriginalPath);\r
-               }\r
-               \r
-               public void MoveTo (string dest) {\r
-                       File.Move (FullPath, dest);\r
-               }\r
-\r
+
+               public override void Delete () {
+                       MonoIOError error;
+                                               
+                       if (!MonoIO.Exists (FullPath, out error)) {
+                               // a weird MS.NET behaviour
+                               return;
+                       }
+
+                       if (MonoIO.ExistsDirectory (FullPath, out error)) {
+                               throw new UnauthorizedAccessException ("Access to the path \"" + FullPath + "\" is denied.");
+                       }
+                       
+                       if (!MonoIO.DeleteFile (FullPath, out error)) {
+                               throw MonoIO.GetException (OriginalPath,
+                                                          error);
+                       }
+               }
+               
+               public void MoveTo (string dest) {
+                       if (dest == null)
+                               throw new ArgumentNullException ();
+                       MonoIOError error;
+                       if (MonoIO.Exists (dest, out error) ||
+                               MonoIO.ExistsDirectory (dest, out error))
+                               throw new IOException ();
+                       File.Move (FullPath, dest);
+                       this.FullPath = Path.GetFullPath (dest);
+               }
+
                public FileInfo CopyTo (string path) {\r
                        return CopyTo (path, false);\r
                }\r
 \r
                public FileInfo CopyTo (string path, bool overwrite) {\r
                        string dest = Path.GetFullPath (path);\r
+
+                       if (overwrite && File.Exists (path))
+                               File.Delete (path);
+
                        File.Copy (FullPath, dest);\r
                \r
                        return new FileInfo (dest);\r