Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Holmes <holmes@mono-cvs.ximian.com>2007-08-20 22:48:55 +0400
committerBill Holmes <holmes@mono-cvs.ximian.com>2007-08-20 22:48:55 +0400
commitf18043102fefe96740e27b16de5a6a7a383c21b7 (patch)
treec882adfef9335f769b1b3f8f92e6356654a8416e /mcs/class/corlib/System.IO/File.cs
parentbfe29bdeaffae7bace3c430fc69ff8c7fdf4245a (diff)
2007-08-20 William Holmes <billholmes54@gmail.com>
Implementing System.IO.File.Replace *File.cs: Add implementation for IO.File.Replace methods. *MonoIO.cs: Declared an internal call for ReplaceFile *FileTest.cs: Added a test for IO.File.Replace. Code is contributed under MIT/X11 license. svn path=/trunk/mcs/; revision=84485
Diffstat (limited to 'mcs/class/corlib/System.IO/File.cs')
-rw-r--r--mcs/class/corlib/System.IO/File.cs50
1 files changed, 48 insertions, 2 deletions
diff --git a/mcs/class/corlib/System.IO/File.cs b/mcs/class/corlib/System.IO/File.cs
index 4d7fc102ed5..14ce44289f0 100644
--- a/mcs/class/corlib/System.IO/File.cs
+++ b/mcs/class/corlib/System.IO/File.cs
@@ -399,7 +399,7 @@ namespace System.IO
string destinationFileName,
string destinationBackupFileName)
{
- throw new NotImplementedException ();
+ Replace (sourceFileName, destinationFileName, destinationBackupFileName, false);
}
public static void Replace (string sourceFileName,
@@ -407,7 +407,53 @@ namespace System.IO
string destinationBackupFileName,
bool ignoreMetadataErrors)
{
- throw new NotImplementedException ();
+ MonoIOError error;
+
+ if (sourceFileName == null)
+ throw new ArgumentNullException ("sourceFileName");
+ if (destinationFileName == null)
+ throw new ArgumentNullException ("destinationFileName");
+ if (sourceFileName.Trim () == "" || sourceFileName.IndexOfAny (Path.InvalidPathChars) != -1)
+ throw new ArgumentException ("sourceFileName");
+ if (destinationFileName.Trim () == "" || destinationFileName.IndexOfAny (Path.InvalidPathChars) != -1)
+ throw new ArgumentException ("destinationFileName");
+
+ string fullSource = Path.GetFullPath (sourceFileName);
+ string fullDest = Path.GetFullPath (destinationFileName);
+ if (MonoIO.ExistsDirectory (fullSource, out error))
+ throw new IOException (Locale.GetText ("{0} is a directory", sourceFileName));
+ if (MonoIO.ExistsDirectory (fullDest, out error))
+ throw new IOException (Locale.GetText ("{0} is a directory", destinationFileName));
+
+ if (!Exists (fullSource))
+ throw new FileNotFoundException (Locale.GetText ("{0} does not exist", sourceFileName),
+ sourceFileName);
+ if (!Exists (fullDest))
+ throw new FileNotFoundException (Locale.GetText ("{0} does not exist", destinationFileName),
+ destinationFileName);
+ if (fullSource == fullDest)
+ throw new IOException (Locale.GetText ("Source and destination arguments are the same file."));
+
+ string fullBackup = null;
+ if (destinationBackupFileName != null) {
+ if (destinationBackupFileName.Trim () == "" ||
+ destinationBackupFileName.IndexOfAny (Path.InvalidPathChars) != -1)
+ throw new ArgumentException ("destinationBackupFileName");
+
+ fullBackup = Path.GetFullPath (destinationBackupFileName);
+ if (MonoIO.ExistsDirectory (fullBackup, out error))
+ throw new IOException (Locale.GetText ("{0} is a directory", destinationBackupFileName));
+ if (fullSource == fullBackup)
+ throw new IOException (Locale.GetText ("Source and backup arguments are the same file."));
+ if (fullDest == fullBackup)
+ throw new IOException (Locale.GetText (
+ "Destination and backup arguments are the same file."));
+ }
+
+ if (!MonoIO.ReplaceFile (fullSource, fullDest, fullBackup,
+ ignoreMetadataErrors, out error)) {
+ throw MonoIO.GetException (error);
+ }
}
public static void SetAccessControl (string path,