Skip to content

Commit

Permalink
Attempt to handle requests for items in the middle of upload
Browse files Browse the repository at this point in the history
It seems possible that this is a source of trouble in #2.  So we'll
keep a record of all documents being uploaded right now, and check
that if we don't find a document in the cloud or in the buffers.
This could go sideways very quickly if we try to do something with
this document.  But hopefully in practice it will only be setting
attributes or something similarly innocuous.
  • Loading branch information
rschroll committed Feb 21, 2021
1 parent a6f4014 commit 775888d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rmfuse/fuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 775888d

Please sign in to comment.