Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-10-01 17:37:31 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-10-01 17:37:31 (GMT)
commitd60c7bb62a97c9e099aced2fb402c864e9c775c2 (patch)
tree45e50fade86652b6058aa134f42d73c145ee9162
parent6790cbf040d09137a2fd3018179363c2cf972808 (diff)
Screenshot file is not deleted #1445
-rw-r--r--src/carquinyol/filestore.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/carquinyol/filestore.py b/src/carquinyol/filestore.py
index 71d6344..5a90a8e 100644
--- a/src/carquinyol/filestore.py
+++ b/src/carquinyol/filestore.py
@@ -52,11 +52,12 @@ class FileStore(object):
except OSError, e:
if e.errno == errno.EXDEV:
self._async_copy(file_path, destination_path,
- completion_cb)
+ completion_cb, unlink_src=True)
else:
raise
else:
- self._async_copy(file_path, destination_path, completion_cb)
+ self._async_copy(file_path, destination_path, completion_cb,
+ unlink_src=False)
"""
TODO: How can we support deleting the file of an entry?
elif not file_path and os.path.exists(destination_path):
@@ -68,13 +69,15 @@ class FileStore(object):
logging.debug('FileStore: Nothing to do')
completion_cb()
- def _async_copy(self, file_path, destination_path, completion_cb):
+ def _async_copy(self, file_path, destination_path, completion_cb,
+ unlink_src):
"""Start copying a file asynchronously.
"""
logging.debug('FileStore copying from %r to %r', file_path,
destination_path)
- async_copy = AsyncCopy(file_path, destination_path, completion_cb)
+ async_copy = AsyncCopy(file_path, destination_path, completion_cb,
+ unlink_src)
async_copy.start()
def retrieve(self, uid, user_id, extension):
@@ -171,10 +174,11 @@ class AsyncCopy(object):
"""
CHUNK_SIZE = 65536
- def __init__(self, src, dest, completion):
+ def __init__(self, src, dest, completion, unlink_src=False):
self.src = src
self.dest = dest
self.completion = completion
+ self._unlink_src = unlink_src
self.src_fp = -1
self.dest_fp = -1
self.written = 0
@@ -194,8 +198,7 @@ class AsyncCopy(object):
if count < len(data):
logging.error('AC: Error writing %s -> %s: wrote less than '
'expected', self.src, self.dest)
- self._cleanup()
- self.completion(RuntimeError(
+ self._complete(RuntimeError(
'Error writing data to destination file'))
return False
@@ -203,18 +206,22 @@ class AsyncCopy(object):
# done?
if len(data) < AsyncCopy.CHUNK_SIZE:
- self._cleanup()
- self.completion(None)
+ self._complete(None)
return False
except Exception, err:
logging.error('AC: Error copying %s -> %s: %r', self.src, self.
dest, err)
- self._cleanup()
- self.completion(err)
+ self._complete(err)
return False
return True
+ def _complete(self, *args):
+ self._cleanup()
+ if self._unlink_src:
+ os.unlink(self.src)
+ self.completion(*args)
+
def start(self):
self.src_fp = os.open(self.src, os.O_RDONLY)
self.dest_fp = os.open(self.dest, os.O_RDWR | os.O_TRUNC | os.O_CREAT,