[Mono-list] Bugfix for File.Set*Time() for directories

Elan Feingold efeingold@mn.rr.com
Fri, 28 Feb 2003 12:43:24 -0600

This is a multi-part message in MIME format.

Content-Type: text/plain;
Content-Transfer-Encoding: 7bit

* [io-layer/io.c]: Calling File.Set[LastWrite|LastAccess|Create]Time()
on a directory was failing, because the I/O layer was trying to open the
directory with write permission, which fails with EISDIR. This patch
works around the problem by recognizing this condition and reopening
without write permission.
(As a side-note, I tested my XML deserialization code for
interoperability with .NET last night and everything worked perfectly. I
ran the server on XP, the client on Linux, and they chatted with
asymmetric and symmetric key encryption and XML serialized objects.)

Best regards,


Content-Type: application/octet-stream;
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;

? patch.io=0A=
? arch/alpha/.deps=0A=
? arch/alpha/Makefile=0A=
? arch/alpha/Makefile.in=0A=
? arch/s390/.deps=0A=
? arch/s390/Makefile=0A=
? arch/s390/Makefile.in=0A=
? arch/sparc/.deps=0A=
? metadata/monosn=0A=
? os/win32/.deps=0A=
Index: io-layer/io.c=0A=
RCS file: /mono/mono/mono/io-layer/io.c,v=0A=
retrieving revision 1.33=0A=
diff -u -r1.33 io.c=0A=
--- io-layer/io.c	21 Feb 2003 12:20:47 -0000	1.33=0A=
+++ io-layer/io.c	28 Feb 2003 18:36:50 -0000=0A=
@@ -1373,6 +1373,20 @@=0A=
 	ret=3Dopen(filename, flags, perms);=0A=
+    =0A=
+	/* If we were trying to open a directory with write permissions=0A=
+	 * (e.g. O_WRONLY or O_RDWR), this call will fail with=0A=
+	 * EISDIR. However, this is a bit bogus because calls to=0A=
+	 * manipulate the directory (e.g. SetFileTime) will still work on=0A=
+	 * the directory because they use other API calls=0A=
+	 * (e.g. utime()). Hence, if we failed with the EISDIR error, try=0A=
+	 * to open the directory again without write permission.=0A=
+	 */=0A=
+	if (ret =3D=3D -1 && errno =3D=3D EISDIR)=0A=
+	{=0A=
+		/* Try again but don't try to make it writable */=0A=
+		ret=3Dopen(filename, flags  & ~(O_RDWR|O_WRONLY), perms);=0A=
+	}=0A=
 	if(ret=3D=3D-1) {=0A=
 #ifdef DEBUG=0A=