[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
if ((stat.Attributes & FileAttributes.Directory) != 0)\r
return false;\r
\r
- return File.Exists (FullPath);\r
+ return exists;
}\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,
}
}
- 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