[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

[MD:1762]Bug fix of file-readable-p



Hi, I found a bug about file-writeable-p<f> function for Emacs 20.6 on
Win32 system.

There's patch attached.


Symptom
=======

In NT Emacs 20.6, elisp function file-writable-p<f> returns t although
directory path of specified FILENAME is not exist.

For example, (file-writable-p "/no-such-dir/new-file.txt") always 
return t.


Reason
======

Modifications of fileio.c in 2000-02-23 (only for WINDOWSNT defined) is
for writability of files in read-only directory on the Windows
environment.  However, as side effect, this modification discarded also
checking existance of parent directory. As result, file-writable-p() for
file in non-existant directory returns t.


Patch
=====

Patch is attached in this mail.

ChangeLog
2000-04-17  Shun-ichi Goto  <gotoh@xxxxxxxxxxx>
	* fileio.c (Ffile_writable_p) [WINDOWSNT]: Check existance of 
	parent directory of specified file.


Test Result
===========

For example, in following situation:
  * /temp        directory, rw permission
  * /temp/rwdir  directory, rw permission (have two files)
  * /temp/rodir  directory, ro permission (have two files)
  * /temp/rwdir/rw.c  file, rw permittion
  * /temp/rwdir/ro.c  file, ro permittion
  * /temp/rodir/rw.c  file, rw permittion
  * /temp/rodir/ro.c  file, ro permittion

This is test result with original Emacs 20.6 (for NT) and patched one
on Windows 2000.

                                     original  patched
(file-exists-p "/xxx")                 nil      nil   
(file-writable-p "/xxx/a.c")           t        nil    <--- here!
(file-writable-p "/temp/rwdir/rw.c")   t        t
(file-writable-p "/temp/rwdir/ro.c")   nil	nil
(file-writable-p "/temp/rwdir/new.c")  t	t
(file-writable-p "/temp/rodir/rw.c")   t	t
(file-writable-p "/temp/rodir/ro.c")   nil	nil
(file-writable-p "/temp/rodir/new.c")  t	t



--- Regards,
 Shun-ichi Goto  <gotoh@xxxxxxxxxxx>
   R&D Group, TAIYO Corp., Tokyo, JAPAN

RCS file: g:/repdev/Meadow/src/fileio.c,v
retrieving revision 1.1.1.7
diff -c -r1.1.1.7 fileio.c
*** fileio.c	2000/04/04 08:31:36	1.1.1.7
--- fileio.c	2000/04/13 08:32:23
***************
*** 2929,2940 ****
      return (check_writable (XSTRING (encoded)->data)
  	    ? Qt : Qnil);
  
- #ifdef WINDOWSNT
-   /* The read-only attribute of the parent directory doesn't affect
-      whether a file or directory can be created within it.  Some day we
-      should check ACLs though, which do affect this.  */
-   return Qt;
- #else
    dir = Ffile_name_directory (absname);
  #ifdef VMS
    if (!NILP (dir))
--- 2929,2934 ----
***************
*** 2946,2951 ****
--- 2940,2953 ----
  #endif /* MSDOS */
  
    dir = ENCODE_FILE (dir);
+ #ifdef WINDOWSNT
+   /* The read-only attribute of the parent directory doesn't affect
+      whether a file or directory can be created within it.  Some day we
+      should check ACLs though, which do affect this.  */
+   if (stat (XSTRING (dir)->data, &statbuf) < 0)
+     return Qnil;
+   return (statbuf.st_mode & S_IFMT) == S_IFDIR ? Qt : Qnil;
+ #else
    return (check_writable (!NILP (dir) ? (char *) XSTRING (dir)->data : "")
  	  ? Qt : Qnil);
  #endif