Skip to content

Commit 45171ac

Browse files
make ItemCache file ops threadsafe
1 parent 0017e34 commit 45171ac

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/borg/fuse.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def __init__(self, decrypted_repository):
120120
self.indirect_items = 0
121121
# Count of direct items, i.e. data is in self.fd
122122
self.direct_items = 0
123+
self.lock = threading.Lock()
123124

124125
def get(self, inode):
125126
offset = inode - self.offset
@@ -140,8 +141,9 @@ def get(self, inode):
140141
return Item(internal_dict=next(unpacker))
141142
elif self.meta[offset] == ord(b'S'):
142143
fd_offset = int.from_bytes(self.meta[offset + 1:offset + 9], 'little')
143-
self.fd.seek(fd_offset, io.SEEK_SET)
144-
return Item(internal_dict=next(msgpack.Unpacker(self.fd, read_size=1024)))
144+
with self.lock:
145+
self.fd.seek(fd_offset, io.SEEK_SET)
146+
return Item(internal_dict=next(msgpack.Unpacker(self.fd, read_size=1024)))
145147
else:
146148
raise ValueError('Invalid entry type in self.meta')
147149

@@ -218,8 +220,9 @@ def iter_archive_items(self, archive_item_ids, filter=None, consider_part_files=
218220
# ^------ offset ----------^
219221

220222
if current_spans_chunks:
221-
pos = self.fd.seek(0, io.SEEK_END)
222-
self.fd.write(current_item)
223+
with self.lock:
224+
pos = self.fd.seek(0, io.SEEK_END)
225+
self.fd.write(current_item)
223226
self.meta[self.write_offset:self.write_offset + 9] = b'S' + pos.to_bytes(8, 'little')
224227
self.direct_items += 1
225228
else:

0 commit comments

Comments
 (0)