[corlib] Fix FileInfo.MoveTo with same name.
authorMarcos Henrich <marcos.henrich@xamarin.com>
Tue, 16 Feb 2016 11:17:19 +0000 (11:17 +0000)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Tue, 16 Feb 2016 11:17:19 +0000 (11:17 +0000)
FileInfo.MoveTo was not moving a file from one directory to another when
the file name did not change.

Fixes #18361.

An ArgumentException when destFileName is an empty array was added,
otherwise FileInfoTest.MoveTo_DestFileName_Empty would fail. Both
Path.GetFullPath and File.Move throw similar exceptions but
MoveTo_DestFileName_Empty expects the one from File.Move so it was added
to this method.

mcs/class/corlib/System.IO/FileInfo.cs

index cad54a4d553f71ff2141c8227c880d16332a2add..1e53bade58fbf5653b11b0d124bbbe31e7ead55b 100644 (file)
@@ -230,13 +230,17 @@ namespace System.IO {
                {
                        if (destFileName == null)
                                throw new ArgumentNullException ("destFileName");
-                       if (destFileName == Name || destFileName == FullName)
+                       if (destFileName.Length == 0)
+                               throw new ArgumentException ("An empty file name is not valid.", "destFileName");
+
+                       var destFullPath = Path.GetFullPath (destFileName);
+                       if (destFullPath == FullPath)
                                return;
                        if (!File.Exists (FullPath))
                                throw new FileNotFoundException ();
 
-                       File.Move (FullPath, destFileName);
-                       this.FullPath = Path.GetFullPath (destFileName);
+                       File.Move (FullPath, destFullPath);
+                       this.FullPath = destFullPath;
                }
 
                public FileInfo CopyTo (string destFileName)