Patchwork [6,of,9] vfs: add "mkstemp()"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 8, 2014, 4:07 p.m.
Message ID <478805e9633b292ce173.1394294831@juju>
Download mbox | patch
Permalink /patch/3895/
State Accepted
Commit 6fb4c94ae300365541b28a26bc08b02966e2b297
Headers show

Comments

Katsunori FUJIWARA - March 8, 2014, 4:07 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1394294608 -32400
#      Sun Mar 09 01:03:28 2014 +0900
# Node ID 478805e9633b292ce1734dded800b9c4f42cd96f
# Parent  dea46560b9fb70b49611ed868528deb35457de88
vfs: add "mkstemp()"

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -10,7 +10,7 @@ 
 import util, error, osutil, revset, similar, encoding, phases, parsers
 import pathutil
 import match as matchmod
-import os, errno, re, glob
+import os, errno, re, glob, tempfile
 
 if os.name == 'nt':
     import scmwindows as scmplatform
@@ -193,6 +193,15 @@ 
     def mkdir(self, path=None):
         return os.mkdir(self.join(path))
 
+    def mkstemp(self, suffix='', prefix='tmp', dir=None, text=False):
+        fd, name = tempfile.mkstemp(suffix=suffix, prefix=prefix,
+                                    dir=self.join(dir), text=text)
+        dname, fname = util.split(name)
+        if dir:
+            return fd, os.path.join(dir, fname)
+        else:
+            return fd, fname
+
     def readdir(self, path=None, stat=None, skip=None):
         return osutil.listdir(self.join(path), stat, skip)