Răsfoiți Sursa

2006-09-21 Gonzalo Paniagua Javier <[email protected]>

	* Test/System.IO/FileInfoTest.cs:
	* System.IO/FileInfo.cs: added 2.0 IsReadOnly. Patch by Joel Reed.


svn path=/trunk/mcs/; revision=65802
Gonzalo Paniagua Javier 19 ani în urmă
părinte
comite
511182b2ed

+ 4 - 0
mcs/class/corlib/System.IO/ChangeLog

@@ -1,3 +1,7 @@
+2006-09-21 Gonzalo Paniagua Javier <[email protected]>
+
+	* FileInfo.cs: added 2.0 IsReadOnly. Patch by Joel Reed.
+
 2006-09-21 Gonzalo Paniagua Javier <[email protected]>
 
 	* FileInfo.cs: eol-style.

+ 25 - 0
mcs/class/corlib/System.IO/FileInfo.cs

@@ -78,6 +78,31 @@ namespace System.IO {
 			}
 		}
 
+#if NET_2_0
+		public bool IsReadOnly {
+			get {
+				if (!Exists)
+					throw new FileNotFoundException ("Could not find file \"" + OriginalPath + "\".", OriginalPath);
+					
+				return ((stat.Attributes & FileAttributes.ReadOnly) != 0);
+			}
+				
+			set {
+				if (!Exists)
+					throw new FileNotFoundException ("Could not find file \"" + OriginalPath + "\".", OriginalPath);
+					
+				FileAttributes attrs = File.GetAttributes(FullPath);
+
+				if (value) 
+					attrs |= FileAttributes.ReadOnly;
+				else
+					attrs &= ~FileAttributes.ReadOnly;					
+
+				File.SetAttributes(FullPath, attrs);
+			}
+		}
+#endif
+
 		public long Length {
 			get {
 				if (!Exists)

+ 24 - 0
mcs/class/corlib/Test/System.IO/FileInfoTest.cs

@@ -105,6 +105,30 @@ namespace MonoTests.System.IO
 				DeleteFile (path);
 			}
 		}
+
+#if NET_2_0
+		
+		[Test]
+		public void IsReadOnly ()
+		{
+			string path = TempFolder + DSC + "FIT.IsReadOnly.Test";
+			DeleteFile (path);
+			
+			try {
+				FileStream stream = File.Create (path);
+				stream.WriteByte (12);
+				stream.Close ();
+				FileInfo info = new FileInfo (path);
+				AssertEquals ("test#01", false, info.IsReadOnly);
+				info.IsReadOnly = true;
+				AssertEquals ("test#02", true, info.IsReadOnly);
+				info.IsReadOnly = false;
+				AssertEquals ("test#03", false, info.IsReadOnly);
+			} finally {
+				DeleteFile (path);
+			}
+		}
+#endif
 		
 		[Test]
 		public void Length ()