diff options
author | Sascha Silbe <sascha@silbe.org> | 2009-12-20 12:56:52 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-12-20 12:56:52 (GMT) |
commit | 21c8e9c079bbe32a00a298dceecb551a3fbb1b56 (patch) | |
tree | 21a2b97412fd28e8dfa8b3c64ee835b1dab5bc2e | |
parent | 0e682f97bf60b57d6991d52be8c0b77c5b8b5b28 (diff) |
fix file descriptor leak in filestore.retrieve() and use only mkstemp()
Fix file descriptor leak in filestore.retrieve() and use only mkstemp().
Signed-off-by: Sascha Silbe <sascha@silbe.org>
-rw-r--r-- | src/carquinyol/filestore.py | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/src/carquinyol/filestore.py b/src/carquinyol/filestore.py index 5a90a8e..1e2949b 100644 --- a/src/carquinyol/filestore.py +++ b/src/carquinyol/filestore.py @@ -110,21 +110,10 @@ class FileStore(object): elif extension: extension = '.' + extension - destination_path = os.path.join(destination_dir, uid + extension) - - attempt = 1 - while os.path.exists(destination_path): - if attempt > 10: - fd_, destination_path = tempfile.mkstemp(prefix=uid, - suffix=extension, - dir=destination_dir) - del fd_ - os.unlink(destination_path) - break - else: - file_name = '%s_%s%s' % (uid, attempt, extension) - destination_path = os.path.join(destination_dir, file_name) - attempt += 1 + fd, destination_path = tempfile.mkstemp(prefix=uid, suffix=extension, + dir=destination_dir) + os.close(fd) + os.unlink(destination_path) # Try to hard link from the original file to the targetpath. This can # fail if the file is in a different filesystem. Do a symlink instead. |