summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2015-05-08 12:20:16 +0300
committerEli Zaretskii <eliz@gnu.org>2015-05-08 12:20:16 +0300
commit25fde89819f9b782646ee4edd2f32d382ef1b2b1 (patch)
treefd2e318fe9cf5f54c7e9b11e0a73fbd27a629071 /src
parent0d0a4d06efff115f35b4813fa7d2d68b2c600297 (diff)
downloademacs-25fde89819f9b782646ee4edd2f32d382ef1b2b1.tar.gz
Verify file modifications by other programs
* src/filelock.c (lock_file): Check whether the file was modified since it was visited even if 'create-lockfiles' is nil. (Bug#18828)
Diffstat (limited to 'src')
-rw-r--r--src/filelock.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 89d3e350219..4ee7a01ecb8 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -669,10 +669,6 @@ lock_file (Lisp_Object fn)
struct gcpro gcpro1;
USE_SAFE_ALLOCA;
- /* Don't do locking if the user has opted out. */
- if (! create_lockfiles)
- return;
-
/* Don't do locking while dumping Emacs.
Uncompressing wtmp files uses call-process, which does not work
in an uninitialized Emacs. */
@@ -690,9 +686,6 @@ lock_file (Lisp_Object fn)
#endif
encoded_fn = ENCODE_FILE (fn);
- /* Create the name of the lock-file for file fn */
- MAKE_LOCK_NAME (lfname, encoded_fn);
-
/* See if this file is visited and has changed on disk since it was
visited. */
{
@@ -707,27 +700,35 @@ lock_file (Lisp_Object fn)
}
- /* Try to lock the lock. */
- if (0 < lock_if_free (&lock_info, lfname))
+ /* Don't do locking if the user has opted out. */
+ if (create_lockfiles)
{
- /* Someone else has the lock. Consider breaking it. */
- Lisp_Object attack;
- char *dot = lock_info.dot;
- ptrdiff_t pidlen = lock_info.colon - (dot + 1);
- static char const replacement[] = " (pid ";
- int replacementlen = sizeof replacement - 1;
- memmove (dot + replacementlen, dot + 1, pidlen);
- strcpy (dot + replacementlen + pidlen, ")");
- memcpy (dot, replacement, replacementlen);
- attack = call2 (intern ("ask-user-about-lock"), fn,
- build_string (lock_info.user));
- /* Take the lock if the user said so. */
- if (!NILP (attack))
- lock_file_1 (lfname, 1);
+
+ /* Create the name of the lock-file for file fn */
+ MAKE_LOCK_NAME (lfname, encoded_fn);
+
+ /* Try to lock the lock. */
+ if (0 < lock_if_free (&lock_info, lfname))
+ {
+ /* Someone else has the lock. Consider breaking it. */
+ Lisp_Object attack;
+ char *dot = lock_info.dot;
+ ptrdiff_t pidlen = lock_info.colon - (dot + 1);
+ static char const replacement[] = " (pid ";
+ int replacementlen = sizeof replacement - 1;
+ memmove (dot + replacementlen, dot + 1, pidlen);
+ strcpy (dot + replacementlen + pidlen, ")");
+ memcpy (dot, replacement, replacementlen);
+ attack = call2 (intern ("ask-user-about-lock"), fn,
+ build_string (lock_info.user));
+ /* Take the lock if the user said so. */
+ if (!NILP (attack))
+ lock_file_1 (lfname, 1);
+ }
+ SAFE_FREE ();
}
UNGCPRO;
- SAFE_FREE ();
}
void