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

login
register
mail settings
Submitter Ryan McElroy
Date July 18, 2017, 12:54 p.m.
Message ID <10c1f58b17bb0990d51b.1500382478@devbig314.prn1.facebook.com>
Download mbox | patch
Permalink /patch/22484/
State Accepted
Headers show

Comments

Ryan McElroy - July 18, 2017, 12:54 p.m.
# HG changeset patch
# User Durham Goode <durham@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.

Patch

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)