[PATCH 1 of 5 remotenames-ext] locks: take wlock for file writes

Ryan McElroy rm at fb.com
Tue Jul 18 12:54:38 UTC 2017


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1500381544 25200
#      Tue Jul 18 05:39:04 2017 -0700
# Node ID 10c1f58b17bb0990d51be1658f1543a29b9109c5
# Parent  ff86a32a9179dec619b9aa0c5d52afdd85f88555
locks: take wlock for file writes

There are new warnings in upstream that catch vfs writes when the wlock isn't
taken. Remotenames triggers a couple of these. Let's take the lock. In both
cases, it happens during normal write operations (bookmark setting, and pull) so
we don't have to worry about this change causing locks during read operations.

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -167,10 +167,11 @@ def expull(orig, repo, remote, *args, **
     pullremotenames(repo, remote, bookmarks)
     if repo.vfs.exists(_selectivepullenabledfile):
         if not _isselectivepull(repo.ui):
-            repo.vfs.unlink(_selectivepullenabledfile)
+            with repo.wlock():
+                repo.vfs.unlink(_selectivepullenabledfile)
     else:
         if _isselectivepull(repo.ui):
-            with repo.vfs(_selectivepullenabledfile, 'w') as f:
+            with repo.wlock(), repo.vfs(_selectivepullenabledfile, 'w') as f:
                 f.write('enabled') # content doesn't matter
     return res
 
@@ -1164,11 +1165,12 @@ def _readtracking(repo):
     return tracking
 
 def _writetracking(repo, tracking):
-    data = ''
-    for book, track in tracking.iteritems():
-        data += '%s %s\n' % (book, track)
-    vfs = shareawarevfs(repo)
-    vfs.write('bookmarks.tracking', data)
+    with repo.wlock():
+        data = ''
+        for book, track in tracking.iteritems():
+            data += '%s %s\n' % (book, track)
+        vfs = shareawarevfs(repo)
+        vfs.write('bookmarks.tracking', data)
 
 def _removetracking(repo, bookmarks):
     tracking = _readtracking(repo)


More information about the Mercurial-devel mailing list