##// END OF EJS Templates
transaction: use the location value when doing backup...
Pierre-Yves David -
r23311:64ab33ff default
parent child Browse files
Show More
@@ -919,7 +919,9 b' class localrepository(object):'
919 try:
919 try:
920 if self.svfs.exists("journal"):
920 if self.svfs.exists("journal"):
921 self.ui.status(_("rolling back interrupted transaction\n"))
921 self.ui.status(_("rolling back interrupted transaction\n"))
922 transaction.rollback(self.sopener, "journal",
922 vfsmap = {'': self.sopener,
923 'plain': self.opener,}
924 transaction.rollback(self.sopener, vfsmap, "journal",
923 self.ui.warn)
925 self.ui.warn)
924 self.invalidate()
926 self.invalidate()
925 return True
927 return True
@@ -975,7 +977,8 b' class localrepository(object):'
975
977
976 parents = self.dirstate.parents()
978 parents = self.dirstate.parents()
977 self.destroying()
979 self.destroying()
978 transaction.rollback(self.sopener, 'undo', ui.warn)
980 vfsmap = {'plain': self.opener}
981 transaction.rollback(self.sopener, vfsmap, 'undo', ui.warn)
979 if self.vfs.exists('undo.bookmarks'):
982 if self.vfs.exists('undo.bookmarks'):
980 self.vfs.rename('undo.bookmarks', 'bookmarks')
983 self.vfs.rename('undo.bookmarks', 'bookmarks')
981 if self.svfs.exists('undo.phaseroots'):
984 if self.svfs.exists('undo.phaseroots'):
@@ -25,7 +25,8 b' def active(func):'
25 return func(self, *args, **kwds)
25 return func(self, *args, **kwds)
26 return _active
26 return _active
27
27
28 def _playback(journal, report, opener, entries, backupentries, unlink=True):
28 def _playback(journal, report, opener, vfsmap, entries, backupentries,
29 unlink=True):
29 for f, o, _ignore in entries:
30 for f, o, _ignore in entries:
30 if o or not unlink:
31 if o or not unlink:
31 try:
32 try:
@@ -44,9 +45,10 b' def _playback(journal, report, opener, e'
44
45
45 backupfiles = []
46 backupfiles = []
46 for l, f, b, c in backupentries:
47 for l, f, b, c in backupentries:
48 vfs = vfsmap[l]
47 if f and b:
49 if f and b:
48 filepath = opener.join(f)
50 filepath = vfs.join(f)
49 backuppath = opener.join(b)
51 backuppath = vfs.join(b)
50 try:
52 try:
51 util.copyfile(backuppath, filepath)
53 util.copyfile(backuppath, filepath)
52 backupfiles.append(b)
54 backupfiles.append(b)
@@ -56,7 +58,7 b' def _playback(journal, report, opener, e'
56 else:
58 else:
57 target = f or b
59 target = f or b
58 try:
60 try:
59 opener.unlink(target)
61 vfs.unlink(target)
60 except (IOError, OSError), inst:
62 except (IOError, OSError), inst:
61 if inst.errno != errno.ENOENT:
63 if inst.errno != errno.ENOENT:
62 raise
64 raise
@@ -105,9 +107,11 b' class transaction(object):'
105 self.file = opener.open(self.journal, "w")
107 self.file = opener.open(self.journal, "w")
106
108
107 # a list of ('location', 'path', 'backuppath', cache) entries.
109 # a list of ('location', 'path', 'backuppath', cache) entries.
108 # if 'backuppath' is empty, no file existed at backup time
110 # - if 'backuppath' is empty, no file existed at backup time
109 # if 'path' is empty, this is a temporary transaction file
111 # - if 'path' is empty, this is a temporary transaction file
110 # (location, and cache are current unused)
112 # - if 'location' is not empty, the path is outside main opener reach.
113 # use 'location' value as a key in a vfsmap to find the right 'vfs'
114 # (cache is currently unused)
111 self._backupentries = []
115 self._backupentries = []
112 self._backupmap = {}
116 self._backupmap = {}
113 self._backupjournal = "%s.backupfiles" % journal
117 self._backupjournal = "%s.backupfiles" % journal
@@ -361,9 +365,10 b' class transaction(object):'
361 self.file.close()
365 self.file.close()
362 self._backupsfile.close()
366 self._backupsfile.close()
363 # cleanup temporary files
367 # cleanup temporary files
364 for _l, f, b, _c in self._backupentries:
368 for l, f, b, _c in self._backupentries:
365 if not f and b and self.opener.exists(b):
369 vfs = self._vfsmap[l]
366 self.opener.unlink(b)
370 if not f and b and vfs.exists(b):
371 vfs.unlink(b)
367 self.entries = []
372 self.entries = []
368 if self.after:
373 if self.after:
369 self.after()
374 self.after()
@@ -372,8 +377,9 b' class transaction(object):'
372 if self.opener.isfile(self._backupjournal):
377 if self.opener.isfile(self._backupjournal):
373 self.opener.unlink(self._backupjournal)
378 self.opener.unlink(self._backupjournal)
374 for _l, _f, b, _c in self._backupentries:
379 for _l, _f, b, _c in self._backupentries:
375 if b and self.opener.exists(b):
380 vfs = self._vfsmap[l]
376 self.opener.unlink(b)
381 if b and vfs.exists(b):
382 vfs.unlink(b)
377 self._backupentries = []
383 self._backupentries = []
378 self.journal = None
384 self.journal = None
379 # run post close action
385 # run post close action
@@ -408,7 +414,7 b' class transaction(object):'
408 self.report(_("transaction abort!\n"))
414 self.report(_("transaction abort!\n"))
409
415
410 try:
416 try:
411 _playback(self.journal, self.report, self.opener,
417 _playback(self.journal, self.report, self.opener, self._vfsmap,
412 self.entries, self._backupentries, False)
418 self.entries, self._backupentries, False)
413 self.report(_("rollback completed\n"))
419 self.report(_("rollback completed\n"))
414 except Exception:
420 except Exception:
@@ -417,7 +423,7 b' class transaction(object):'
417 self.journal = None
423 self.journal = None
418
424
419
425
420 def rollback(opener, file, report):
426 def rollback(opener, vfsmap, file, report):
421 """Rolls back the transaction contained in the given file
427 """Rolls back the transaction contained in the given file
422
428
423 Reads the entries in the specified file, and the corresponding
429 Reads the entries in the specified file, and the corresponding
@@ -459,4 +465,4 b' def rollback(opener, file, report):'
459 report(_("journal was created by a different version of "
465 report(_("journal was created by a different version of "
460 "Mercurial"))
466 "Mercurial"))
461
467
462 _playback(file, report, opener, entries, backupentries)
468 _playback(file, report, opener, vfsmap, entries, backupentries)
General Comments 0
You need to be logged in to leave comments. Login now