Commit 6dad7178 authored by Eli Zaretskii's avatar Eli Zaretskii

Support symlinks on latest versions of MS-Windows.

 src/w32.c: Include winioctl.h and aclapi.h.
 (is_symlink, chase_symlinks, enable_privilege, restore_privilege)
 (revert_to_self): Forward declarations of static functions.
 <static BOOL g_b_init_get_security_info>:
 <g_b_init_create_symbolic_link>: New static flags.
 (globals_of_w32): Initialize them to zero.
 (GetSecurityInfo_Proc, CreateSymbolicLink_Proc): New typedefs.
 (map_w32_filename): Improve commentary.  Simplify switch.
 (SYMBOLIC_LINK_FLAG_DIRECTORY): Define if not defined in system
 headers (most versions of MinGW w32api don't).
 (get_security_info, create_symbolic_link)
 (get_file_security_desc_by_handle, is_symlink, chase_symlinks):
 New functions.
 (sys_access, sys_chmod): Call 'chase_symlinks' to resolve symlinks
 in the argument file name.
 (sys_access): Call unc_volume_file_attributes only if
 GetFileAttributes fails with network-related error codes.
 (sys_rename): Diagnose renaming of a symlink when the user doesn't
 have the required privileges.
 (get_file_security_desc_by_name): Renamed from
 get_file_security_desc.
 (stat_worker): New function, with most of the guts of 'stat', and
 with addition of handling of symlinks and support for 'lstat'.  If
 possible, get file's attributes and security information by
 handle, not by name.  Produce S_IFLNK bit for symlinks, when
 called from 'lstat'.
 (stat, lstat): New functions, call 'stat_worker'.
 (symlink, readlink, careadlinkat): Rewritten to create and resolve
 symlinks when the underlying filesystem supports them.

 lib/src/ntlib.c (lstat): New function, calls 'stat'.

 nt/inc/sys/stat.h (S_IFLNK): Define.
 (S_ISLNK): A non-trivial definition.
 (lstat): Prototype instead of a macro that redirects to 'stat'.

 lisp/files.el (file-truename): Don't skip symlink-chasing part on
 windows-nt.  Incorporate the resolution of 8+3 short aliases on
 Windows into the loop that recursively chases symlinks.  Compare
 directory and its parent case-insensitively on MS-Windows and
 MS-DOS.

 etc/NEWS: Announce the symlink support on MS-Windows.
parent 09486324
...@@ -596,6 +596,8 @@ is detected. ...@@ -596,6 +596,8 @@ is detected.
Emacs now supports mouse highlight, help-echo (in the echo area), and Emacs now supports mouse highlight, help-echo (in the echo area), and
mouse-autoselect-window. mouse-autoselect-window.
** On MS-Windows Vista and later Emacs now supports symbolic links.
* Installation Changes in Emacs 24.1 * Installation Changes in Emacs 24.1
......
2012-08-03 Eli Zaretskii <eliz@gnu.org>
* ntlib.c (lstat): New function, calls 'stat'.
2012-08-02 Paul Eggert <eggert@cs.ucla.edu> 2012-08-02 Paul Eggert <eggert@cs.ucla.edu>
Use C99-style 'extern inline' if available. Use C99-style 'extern inline' if available.
......
...@@ -374,3 +374,9 @@ stat (const char * path, struct stat * buf) ...@@ -374,3 +374,9 @@ stat (const char * path, struct stat * buf)
return 0; return 0;
} }
int
lstat (const char * path, struct stat * buf)
{
return stat (path, buf);
}
2012-08-03 Eli Zaretskii <eliz@gnu.org>
* files.el (file-truename): Don't skip symlink-chasing part on
windows-nt. Incorporate the resolution of 8+3 short aliases on
Windows into the loop that recursively chases symlinks. Compare
directory and its parent case-insensitively on MS-Windows and
MS-DOS.
2012-08-03 Chong Yidong <cyd@gnu.org> 2012-08-03 Chong Yidong <cyd@gnu.org>
* menu-bar.el (menu-bar-tools-menu): Remove PCL-CVS. * menu-bar.el (menu-bar-tools-menu): Remove PCL-CVS.
......
...@@ -1079,9 +1079,7 @@ containing it, until no links are left at any level. ...@@ -1079,9 +1079,7 @@ containing it, until no links are left at any level.
(delq (rassq 'ange-ftp-completion-hook-function tem) tem))))) (delq (rassq 'ange-ftp-completion-hook-function tem) tem)))))
(or prev-dirs (setq prev-dirs (list nil))) (or prev-dirs (setq prev-dirs (list nil)))
;; andrewi@harlequin.co.uk - none of the following code (except for ;; andrewi@harlequin.co.uk - on Windows, there is an issue with
;; invoking the file-name handler) currently applies on Windows
;; (ie. there are no native symlinks), but there is an issue with
;; case differences being ignored by the OS, and short "8.3 DOS" ;; case differences being ignored by the OS, and short "8.3 DOS"
;; name aliases existing for all files. (The short names are not ;; name aliases existing for all files. (The short names are not
;; reported by directory-files, but can be used to refer to files.) ;; reported by directory-files, but can be used to refer to files.)
...@@ -1091,31 +1089,15 @@ containing it, until no links are left at any level. ...@@ -1091,31 +1089,15 @@ containing it, until no links are left at any level.
;; it is stored on disk (expanding short name aliases with the full ;; it is stored on disk (expanding short name aliases with the full
;; name in the process). ;; name in the process).
(if (eq system-type 'windows-nt) (if (eq system-type 'windows-nt)
(let ((handler (find-file-name-handler filename 'file-truename))) (unless (string-match "[[*?]" filename)
;; For file name that has a special handler, call handler. ;; If filename exists, use its long name. If it doesn't
;; This is so that ange-ftp can save time by doing a no-op. ;; exist, the recursion below on the directory of filename
(if handler ;; will drill down until we find a directory that exists,
(setq filename (funcall handler 'file-truename filename)) ;; and use the long name of that, with the extra
;; If filename contains a wildcard, newname will be the old name. ;; non-existent path components concatenated.
(unless (string-match "[[*?]" filename) (let ((longname (w32-long-file-name filename)))
;; If filename exists, use the long name. If it doesn't exist, (if longname
;; drill down until we find a directory that exists, and use (setq filename longname)))))
;; the long name of that, with the extra non-existent path
;; components concatenated.
(let ((longname (w32-long-file-name filename))
missing rest)
(if longname
(setq filename longname)
;; Include the preceding directory separator in the missing
;; part so subsequent recursion on the rest works.
(setq missing (concat "/" (file-name-nondirectory filename)))
(let ((length (length missing)))
(setq rest
(if (> length (length filename))
""
(substring filename 0 (- length)))))
(setq filename (concat (file-truename rest) missing))))))
(setq done t)))
;; If this file directly leads to a link, process that iteratively ;; If this file directly leads to a link, process that iteratively
;; so that we don't use lots of stack. ;; so that we don't use lots of stack.
...@@ -1135,6 +1117,8 @@ containing it, until no links are left at any level. ...@@ -1135,6 +1117,8 @@ containing it, until no links are left at any level.
(setq dirfile (directory-file-name dir)) (setq dirfile (directory-file-name dir))
;; If these are equal, we have the (or a) root directory. ;; If these are equal, we have the (or a) root directory.
(or (string= dir dirfile) (or (string= dir dirfile)
(and (memq system-type '(windows-nt ms-dos cygwin))
(eq (compare-strings dir 0 nil dirfile 0 nil t) t))
;; If this is the same dir we last got the truename for, ;; If this is the same dir we last got the truename for,
;; save time--don't recalculate. ;; save time--don't recalculate.
(if (assoc dir (car prev-dirs)) (if (assoc dir (car prev-dirs))
......
2012-08-03 Eli Zaretskii <eliz@gnu.org>
* inc/sys/stat.h (S_IFLNK): Define.
(S_ISLNK): A non-trivial definition.
(lstat): Prototype instead of a macro that redirects to 'stat'.
2012-08-02 Paul Eggert <eggert@cs.ucla.edu> 2012-08-02 Paul Eggert <eggert@cs.ucla.edu>
Use C99-style 'extern inline' if available. Use C99-style 'extern inline' if available.
......
...@@ -33,13 +33,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ ...@@ -33,13 +33,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
#define S_IFMT 0xF000 #define S_IFMT 0xF800
#define S_IFREG 0x8000 #define S_IFREG 0x8000
#define S_IFDIR 0x4000 #define S_IFDIR 0x4000
#define S_IFBLK 0x3000 #define S_IFBLK 0x3000
#define S_IFCHR 0x2000 #define S_IFCHR 0x2000
#define S_IFIFO 0x1000 #define S_IFIFO 0x1000
#define S_IFLNK 0x0800
#define S_IREAD 0x0100 #define S_IREAD 0x0100
#define S_IWRITE 0x0080 #define S_IWRITE 0x0080
...@@ -55,6 +56,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ ...@@ -55,6 +56,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
/* These don't exist on Windows, but lib/filemode.c wants them. */ /* These don't exist on Windows, but lib/filemode.c wants them. */
#define S_ISUID 0 #define S_ISUID 0
...@@ -68,7 +70,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ ...@@ -68,7 +70,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#define S_IXOTH (S_IXUSR >> 6) #define S_IXOTH (S_IXUSR >> 6)
#define S_ISSOCK(m) 0 #define S_ISSOCK(m) 0
#define S_ISLNK(m) 0
#define S_ISCTG(p) 0 #define S_ISCTG(p) 0
#define S_ISDOOR(m) 0 #define S_ISDOOR(m) 0
#define S_ISMPB(m) 0 #define S_ISMPB(m) 0
...@@ -103,9 +104,7 @@ struct stat { ...@@ -103,9 +104,7 @@ struct stat {
_CRTIMP int __cdecl __MINGW_NOTHROW fstat (int, struct stat*); _CRTIMP int __cdecl __MINGW_NOTHROW fstat (int, struct stat*);
_CRTIMP int __cdecl __MINGW_NOTHROW chmod (const char*, int); _CRTIMP int __cdecl __MINGW_NOTHROW chmod (const char*, int);
_CRTIMP int __cdecl __MINGW_NOTHROW stat (const char*, struct stat*); _CRTIMP int __cdecl __MINGW_NOTHROW stat (const char*, struct stat*);
_CRTIMP int __cdecl __MINGW_NOTHROW lstat (const char*, struct stat*);
/* fileio.c and dired.c want lstat. */
#define lstat stat
#endif /* INC_SYS_STAT_H_ */ #endif /* INC_SYS_STAT_H_ */
2012-08-03 Eli Zaretskii <eliz@gnu.org>
Support symlinks on latest versions of MS-Windows.
* w32.c: Include winioctl.h and aclapi.h.
(is_symlink, chase_symlinks, enable_privilege, restore_privilege)
(revert_to_self): Forward declarations of static functions.
<static BOOL g_b_init_get_security_info>:
<g_b_init_create_symbolic_link>: New static flags.
(globals_of_w32): Initialize them to zero.
(GetSecurityInfo_Proc, CreateSymbolicLink_Proc): New typedefs.
(map_w32_filename): Improve commentary. Simplify switch.
(SYMBOLIC_LINK_FLAG_DIRECTORY): Define if not defined in system
headers (most versions of MinGW w32api don't).
(get_security_info, create_symbolic_link)
(get_file_security_desc_by_handle, is_symlink, chase_symlinks):
New functions.
(sys_access, sys_chmod): Call 'chase_symlinks' to resolve symlinks
in the argument file name.
(sys_access): Call unc_volume_file_attributes only if
GetFileAttributes fails with network-related error codes.
(sys_rename): Diagnose renaming of a symlink when the user doesn't
have the required privileges.
(get_file_security_desc_by_name): Renamed from
get_file_security_desc.
(stat_worker): New function, with most of the guts of 'stat', and
with addition of handling of symlinks and support for 'lstat'. If
possible, get file's attributes and security information by
handle, not by name. Produce S_IFLNK bit for symlinks, when
called from 'lstat'.
(stat, lstat): New functions, call 'stat_worker'.
(symlink, readlink, careadlinkat): Rewritten to create and resolve
symlinks when the underlying filesystem supports them.
2012-08-02 Paul Eggert <eggert@cs.ucla.edu> 2012-08-02 Paul Eggert <eggert@cs.ucla.edu>
Fix macroexp crash on Windows with debugging (Bug#12118). Fix macroexp crash on Windows with debugging (Bug#12118).
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment