##// END OF EJS Templates
transaction: allow generating file outside of store...
Pierre-Yves David -
r22663:4c619873 default
parent child Browse files
Show More
@@ -144,7 +144,7 b' class transaction(object):'
144 self.file.flush()
144 self.file.flush()
145
145
146 @active
146 @active
147 def addbackup(self, file, hardlink=True):
147 def addbackup(self, file, hardlink=True, vfs=None):
148 """Adds a backup of the file to the transaction
148 """Adds a backup of the file to the transaction
149
149
150 Calling addbackup() creates a hardlink backup of the specified file
150 Calling addbackup() creates a hardlink backup of the specified file
@@ -158,8 +158,10 b' class transaction(object):'
158 if file in self.map or file in self.backupmap:
158 if file in self.map or file in self.backupmap:
159 return
159 return
160 backupfile = "%s.backup.%s" % (self.journal, file)
160 backupfile = "%s.backup.%s" % (self.journal, file)
161 if self.opener.exists(file):
161 if vfs is None:
162 filepath = self.opener.join(file)
162 vfs = self.opener
163 if vfs.exists(file):
164 filepath = vfs.join(file)
163 backuppath = self.opener.join(backupfile)
165 backuppath = self.opener.join(backupfile)
164 util.copyfiles(filepath, backuppath, hardlink=hardlink)
166 util.copyfiles(filepath, backuppath, hardlink=hardlink)
165 else:
167 else:
@@ -176,7 +178,7 b' class transaction(object):'
176 self.backupsfile.flush()
178 self.backupsfile.flush()
177
179
178 @active
180 @active
179 def addfilegenerator(self, genid, filenames, genfunc, order=0):
181 def addfilegenerator(self, genid, filenames, genfunc, order=0, vfs=None):
180 """add a function to generates some files at transaction commit
182 """add a function to generates some files at transaction commit
181
183
182 The `genfunc` argument is a function capable of generating proper
184 The `genfunc` argument is a function capable of generating proper
@@ -195,7 +197,10 b' class transaction(object):'
195 The `order` argument may be used to control the order in which multiple
197 The `order` argument may be used to control the order in which multiple
196 generator will be executed.
198 generator will be executed.
197 """
199 """
198 self._filegenerators[genid] = (order, filenames, genfunc)
200 # For now, we are unable to do proper backup and restore of custom vfs
201 # but for bookmarks that are handled outside this mechanism.
202 assert vfs is None or filenames == ('bookmarks',)
203 self._filegenerators[genid] = (order, filenames, genfunc, vfs)
199
204
200 @active
205 @active
201 def find(self, file):
206 def find(self, file):
@@ -239,16 +244,19 b' class transaction(object):'
239 def close(self):
244 def close(self):
240 '''commit the transaction'''
245 '''commit the transaction'''
241 # write files registered for generation
246 # write files registered for generation
242 for order, filenames, genfunc in sorted(self._filegenerators.values()):
247 for entry in sorted(self._filegenerators.values()):
248 order, filenames, genfunc, vfs = entry
249 if vfs is None:
250 vfs = self.opener
243 files = []
251 files = []
244 try:
252 try:
245 for name in filenames:
253 for name in filenames:
246 # Some files are already backed up when creating the
254 # Some files are already backed up when creating the
247 # localrepo. Until this is properly fixed we disable the
255 # localrepo. Until this is properly fixed we disable the
248 # backup for them.
256 # backup for them.
249 if name not in ('phaseroots',):
257 if name not in ('phaseroots', 'bookmarks'):
250 self.addbackup(name)
258 self.addbackup(name)
251 files.append(self.opener(name, 'w', atomictemp=True))
259 files.append(vfs(name, 'w', atomictemp=True))
252 genfunc(*files)
260 genfunc(*files)
253 finally:
261 finally:
254 for f in files:
262 for f in files:
General Comments 0
You need to be logged in to leave comments. Login now