vfs: add "mkstemp()"
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Sun, 09 Mar 2014 01:03:28 +0900
changeset 20980 6fb4c94ae300
parent 20979 ad5b61370514
child 20981 4fdd1172d37e
vfs: add "mkstemp()"
mercurial/scmutil.py
--- a/mercurial/scmutil.py	Sun Mar 09 01:03:28 2014 +0900
+++ b/mercurial/scmutil.py	Sun Mar 09 01:03:28 2014 +0900
@@ -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)