Merge pull request #2799 from BrzVlad/fix-conc-card-clean
[mono.git] / mcs / class / corlib / System.IO / FileInfo.cs
index 9ace59e1688a4e7e30e1855e65d7f87ab5948927..69e1f32ffdd74bcf0f4b446b145468b9301769b1 100644 (file)
@@ -37,7 +37,7 @@ using System.Runtime.InteropServices;
 using System.Runtime.Serialization;
 using System.Security;
 
-#if !NET_2_1
+#if !MOBILE
 using System.Security.AccessControl;
 #endif
 
@@ -48,12 +48,8 @@ namespace System.IO {
        public sealed class FileInfo : FileSystemInfo
        {
                private bool exists;
+               private string displayPath;
 
-#if MOONLIGHT
-               internal FileInfo ()
-               {
-               }
-#endif
                public FileInfo (string fileName)
                {
                        if (fileName == null)
@@ -64,11 +60,14 @@ namespace System.IO {
 
                        OriginalPath = fileName;
                        FullPath = Path.GetFullPath (fileName);
+                       
+                       displayPath = OriginalPath;
                }
 
                private FileInfo (SerializationInfo info, StreamingContext context)
                        : base (info, context)
                {
+                       displayPath = OriginalPath;
                }
 
                internal override void InternalRefresh ()
@@ -98,7 +97,6 @@ namespace System.IO {
                        }
                }
 
-#if !NET_2_1
                public bool IsReadOnly {
                        get {
                                if (!Exists)
@@ -143,7 +141,6 @@ namespace System.IO {
                        // handling this exception to work properly.
                        throw new NotSupportedException (Locale.GetText ("File encryption isn't supported on any file system."));
                }
-#endif
 
                public long Length {
                        get {
@@ -237,13 +234,19 @@ 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;
+
+                       displayPath = destFileName;
                }
 
                public FileInfo CopyTo (string destFileName)
@@ -270,15 +273,10 @@ namespace System.IO {
 
                public override string ToString ()
                {
-#if NET_2_1
-                       // for Moonlight we *never* return paths, since ToString is not [SecurityCritical] we simply return the Name
-                       return Name;
-#else
-                       return OriginalPath;
-#endif
+                       return displayPath;
                }
 
-#if !NET_2_1
+#if !MOBILE
                public FileSecurity GetAccessControl ()
                {
                        return File.GetAccessControl (FullPath);