diff --git a/rmfuse/fuse.py b/rmfuse/fuse.py index 32dd72b..f86c3bc 100644 --- a/rmfuse/fuse.py +++ b/rmfuse/fuse.py @@ -120,6 +120,7 @@ def __init__(self, mode): self.mode_file = ModeFile(self) self.inode_map[self.next_inode()] = self.mode_file.id self.buffers = dict() + self.uploading = dict() self._prev_read_fail_count = 0 def next_inode(self): @@ -145,6 +146,12 @@ async def get_by_id(self, id_): for item, _ in self.buffers.values(): if item.id == id_: return item + # Or it may be uploading right now. This may lead to tears. + for item in self.uploading.values(): + if item.id == id_: + logging.warning(f'Getting Item {id_} during upload. ' + 'This may lead to odd behavior!') + return item logging.error(f'Attempt to get non-existent Item {id_}') raise fuse.FUSEError(errno.ENOENT) @@ -368,11 +375,15 @@ async def release(self, fh): else: log.error(f'Error: Not a PDF or EPUB file (file was {document.name})') raise fuse.FUSEError(errno.EIO) # Unfortunately, this will be ignored + + self.uploading[fh] = document try: await document.upload(io.BytesIO(data), type_) except ApiError as error: log.error(f'API Error: {error}') raise fuse.FUSEError(errno.EREMOTEIO) # Unfortunately, this will be ignored + finally: + del self.uploading[fh] @async_op async def rename(self, p_inode_old, name_old, p_inode_new, name_new, flags, ctx=None):