2004-04-02 Dick Porter <dick@ximian.com>
[mono.git] / mcs / class / corlib / System.IO / FileInfo.cs
index 4cb45ca8a69eeebc78fb5248985c308a46fb9831..62e79d489ecaddc5de87f3afdfe67dfffc87037e 100644 (file)
@@ -17,13 +17,22 @@ 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
                public override bool Exists {\r
@@ -36,7 +45,7 @@ namespace System.IO {
                                if ((stat.Attributes & FileAttributes.Directory) != 0)\r
                                        return false;\r
 \r
-                               return File.Exists (FullPath);\r
+                               return exists;
                        }\r
                }\r
 \r
@@ -113,11 +122,15 @@ namespace System.IO {
 
                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,
@@ -125,16 +138,27 @@ namespace System.IO {
                        }
                }
                
-               public void MoveTo (string dest) {\r
-                       File.Move (FullPath, dest);\r
-               }\r
-\r
+               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