From 21c8e9c079bbe32a00a298dceecb551a3fbb1b56 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Sun, 20 Dec 2009 12:56:52 +0000 Subject: 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 --- 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. -- cgit v0.9.1