1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-13 07:33:47 +00:00

Avoid filesystem snapshot related race condition with mtimes

This commit is contained in:
Jonas Borgström 2012-03-01 22:35:11 +01:00
parent 4ddbf0d02a
commit 9d508c9d18

View file

@ -60,6 +60,7 @@ class Cache(object):
def _read_files(self): def _read_files(self):
self.files = {} self.files = {}
self._newest_mtime = 0
with open(os.path.join(self.path, 'files'), 'rb') as fd: with open(os.path.join(self.path, 'files'), 'rb') as fd:
u = msgpack.Unpacker() u = msgpack.Unpacker()
while True: while True:
@ -90,7 +91,10 @@ class Cache(object):
if self.files is not None: if self.files is not None:
with open(os.path.join(self.path, 'files'), 'wb') as fd: with open(os.path.join(self.path, 'files'), 'wb') as fd:
for item in self.files.iteritems(): for item in self.files.iteritems():
msgpack.pack(item, fd) # Discard cached files with the newest mtime to avoid
# issues with filesystem snapshots and mtime precision
if item[1][3] < self._newest_mtime:
msgpack.pack(item, fd)
self.config.set('cache', 'manifest', self.manifest.id.encode('hex')) self.config.set('cache', 'manifest', self.manifest.id.encode('hex'))
with open(os.path.join(self.path, 'config'), 'w') as fd: with open(os.path.join(self.path, 'config'), 'w') as fd:
self.config.write(fd) self.config.write(fd)
@ -206,4 +210,5 @@ class Cache(object):
def memorize_file(self, path_hash, st, ids): def memorize_file(self, path_hash, st, ids):
# Entry: Age, inode, size, mtime, chunk ids # Entry: Age, inode, size, mtime, chunk ids
self.files[path_hash] = 0, st.st_ino, st.st_size, st.st_mtime, ids self.files[path_hash] = 0, st.st_ino, st.st_size, st.st_mtime, ids
self._newest_mtime = max(self._newest_mtime, st.st_mtime)