Mercurial > hg > xemacs-beta
comparison src/filelock.c @ 4972:c448f4c38d65
change name of lock file to avoid problems with etags, byte-recompile-directory, etc.
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-02-04 Ben Wing <ben@xemacs.org>
* filelock.c:
* filelock.c (fill_in_lock_file_name):
Name the lock symlink file .#FN# instead of .#FN for file FN, so
that the link file doesn't have a .c or .el or whatever extension,
which confuses programs/functions that search by extension (e.g.
etags, byte-recompile-directory, etc.).
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Thu, 04 Feb 2010 05:58:40 -0600 |
parents | 304aebb79cd3 |
children | 16112448d484 |
comparison
equal
deleted
inserted
replaced
4971:bcdf496e49d0 | 4972:c448f4c38d65 |
---|---|
1 /* Copyright (C) 1985, 86, 87, 93, 94, 96 Free Software Foundation, Inc. | 1 /* Copyright (C) 1985, 86, 87, 93, 94, 96 Free Software Foundation, Inc. |
2 Copyright (C) 2001 Ben Wing. | 2 Copyright (C) 2001, 2010 Ben Wing. |
3 | 3 |
4 This file is part of XEmacs. | 4 This file is part of XEmacs. |
5 | 5 |
6 XEmacs is free software; you can redistribute it and/or modify | 6 XEmacs is free software; you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
36 Lisp_Object Qask_user_about_lock; | 36 Lisp_Object Qask_user_about_lock; |
37 int inhibit_clash_detection; | 37 int inhibit_clash_detection; |
38 | 38 |
39 #ifdef CLASH_DETECTION | 39 #ifdef CLASH_DETECTION |
40 | 40 |
41 /* The strategy: to lock a file FN, create a symlink .#FN in FN's | 41 /* The strategy: to lock a file FN, create a symlink .#FN# in FN's |
42 directory, with link data `user@host.pid'. This avoids a single | 42 directory, with link data `user@host.pid'. This avoids a single |
43 mount (== failure) point for lock files. | 43 mount (== failure) point for lock files. |
44 | 44 |
45 When the host in the lock data is the current host, we can check if | 45 When the host in the lock data is the current host, we can check if |
46 the pid is valid with kill. | 46 the pid is valid with kill. |
65 | 65 |
66 Similarly, we don't worry about a possible 14-character limit on | 66 Similarly, we don't worry about a possible 14-character limit on |
67 file names, because those are all the same systems that don't have | 67 file names, because those are all the same systems that don't have |
68 symlinks. | 68 symlinks. |
69 | 69 |
70 This is compatible with the locking scheme used by Interleaf (which | 70 Originally we used a name .#FN without the final #; this may have been |
71 has contributed this implementation for Emacs), and was designed by | 71 compatible with the locking scheme used by Interleaf (which has |
72 Ethan Jacobson, Kimbo Mundy, and others. | 72 contributed this implementation for Emacs), and was designed by Ethan |
73 Jacobson, Kimbo Mundy, and others. | |
73 | 74 |
74 --karl@cs.umb.edu/karl@hq.ileaf.com. */ | 75 --karl@cs.umb.edu/karl@hq.ileaf.com. */ |
76 | |
77 /* NOTE: We added the final # in the name .#FN# so that programs | |
78 that e.g. search for all .c files, such as etags, or try to | |
79 byte-compile all .el files in a directory (byte-recompile-directory), | |
80 won't get tripped up by the bogus symlink file. --ben */ | |
75 | 81 |
76 | 82 |
77 /* Here is the structure that stores information about a lock. */ | 83 /* Here is the structure that stores information about a lock. */ |
78 | 84 |
79 typedef struct | 85 typedef struct |
91 #define FREE_LOCK_INFO(i) do { \ | 97 #define FREE_LOCK_INFO(i) do { \ |
92 xfree ((i).user, Ibyte *); \ | 98 xfree ((i).user, Ibyte *); \ |
93 xfree ((i).host, Ibyte *); \ | 99 xfree ((i).host, Ibyte *); \ |
94 } while (0) | 100 } while (0) |
95 | 101 |
96 /* Write the name of the lock file for FN into LFNAME. Length will be | 102 /* Write the name of the lock file for FN into LFNAME. Length will be that |
97 that of FN plus two more for the leading `.#' plus one for the null. */ | 103 of FN plus two more for the leading `.#' plus one for the trailing # |
104 plus one for the null. */ | |
98 #define MAKE_LOCK_NAME(lock, file) \ | 105 #define MAKE_LOCK_NAME(lock, file) \ |
99 (lock = alloca_ibytes (XSTRING_LENGTH (file) + 2 + 1), \ | 106 (lock = alloca_ibytes (XSTRING_LENGTH (file) + 2 + 1 + 1), \ |
100 fill_in_lock_file_name (lock, file)) | 107 fill_in_lock_file_name (lock, file)) |
101 | 108 |
102 static void | 109 static void |
103 fill_in_lock_file_name (Ibyte *lockfile, Lisp_Object fn) | 110 fill_in_lock_file_name (Ibyte *lockfile, Lisp_Object fn) |
104 { | 111 { |
114 | 121 |
115 memcpy (lockfile, file_name, dirlen); | 122 memcpy (lockfile, file_name, dirlen); |
116 p = lockfile + dirlen; | 123 p = lockfile + dirlen; |
117 *(p++) = '.'; | 124 *(p++) = '.'; |
118 *(p++) = '#'; | 125 *(p++) = '#'; |
119 memcpy (p, file_name + dirlen, XSTRING_LENGTH (fn) - dirlen + 1); | 126 memcpy (p, file_name + dirlen, XSTRING_LENGTH (fn) - dirlen); |
127 p += XSTRING_LENGTH (fn) - dirlen; | |
128 *(p++) = '#'; | |
129 *p = '\0'; | |
120 } | 130 } |
121 | 131 |
122 /* Lock the lock file named LFNAME. | 132 /* Lock the lock file named LFNAME. |
123 If FORCE is nonzero, we do so even if it is already locked. | 133 If FORCE is nonzero, we do so even if it is already locked. |
124 Return 1 if successful, 0 if not. */ | 134 Return 1 if successful, 0 if not. */ |