[dak/master] temp_filename
stop using mktemp and use mkstemp. Also use the functions with all their
features, like setting prefix, instead of trying to do that ourself.
Yikes, one-liner now, could remove the function alltogether and instead
use mkstemp directly, but *maybe* we want to get more code into here,
so lets keep it for now.
Signed-off-by: Joerg Jaspert <joerg@debian.org>
---
daklib/utils.py | 22 ++++++----------------
1 files changed, 6 insertions(+), 16 deletions(-)
diff --git a/daklib/utils.py b/daklib/utils.py
index 0fa3eaa..8307948 100755
--- a/daklib/utils.py
+++ b/daklib/utils.py
@@ -1358,26 +1358,16 @@ def clean_symlink (src, dest, root):
################################################################################
-def temp_filename(directory=None, dotprefix=None, perms=0700):
+def temp_filename(directory=None, prefix="dak", suffix=""):
"""Return a secure and unique filename by pre-creating it.
If 'directory' is non-null, it will be the directory the file is pre-created in.
-If 'dotprefix' is non-null, the filename will be prefixed with a '.'."""
+If 'prefix' is non-null, the filename will be prefixed with it, default is dak.
+If 'suffix' is non-null, the filename will end with it.
- if directory:
- old_tempdir = tempfile.tempdir
- tempfile.tempdir = directory
-
- filename = tempfile.mktemp()
-
- if dotprefix:
- filename = "%s/.%s" % (os.path.dirname(filename), os.path.basename(filename))
- fd = os.open(filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, perms)
- os.close(fd)
-
- if directory:
- tempfile.tempdir = old_tempdir
+Returns a pair (fd, name).
+"""
- return filename
+ return tempfile.mkstemp(suffix, prefix, directory)
################################################################################
--
1.5.6.5
Reply to: