From: Joerg Jaspert Date: Fri, 23 Jan 2009 23:06:54 +0000 (+0100) Subject: temp_filename X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=158e9baf0e519d1af426df73b693008abacb3c26;p=dak 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 --- diff --git a/daklib/utils.py b/daklib/utils.py index 0fa3eaa6..83079483 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) ################################################################################