# Copy data without any metadata
await asyncio.to_thread(shutil.copyfile, src, dst)
+ async def unlink(self, path):
+ """
+ Unlinks path
+ """
+ log.debug("Unlinking %s" % path)
+
+ try:
+ await asycio.to_thread(os.unlink, path)
+ except OSError as e:
+ pass
+
def _write_tempfile(self, content):
"""
Writes the content to a temporary file and returns its path
# Return the newly created upload object
return upload
- def cleanup(self):
+ async def cleanup(self):
# Find all expired uploads
uploads = self._get_uploads("""
SELECT
# Delete them all
for upload in uploads:
- upload.delete()
+ with self.db.transaction():
+ await upload.delete()
class Upload(base.DataObject):
user = lazy_property(get_user, set_user)
- def delete(self):
+ async def delete(self):
log.info("Deleting upload %s (%s)" % (self, self.path))
# Remove the uploaded data
- try:
- os.unlink(self.path)
- except OSError:
- pass
+ await self.backend.unlink(self.path)
# Delete the upload from the database
self.db.execute("DELETE FROM uploads WHERE id = %s", self.id)