comparison mercurial/util.py @ 34020:2ad028635ccd

util: use ~ as a suffix for a temp file in the same directory as a source file Tools like Buck have patterns to ignore the creation of files (in the working copy) that match certain patterns: https://github.com/facebook/buck/blob/39278a4f0701c5239eae148968dc1ed4cc8661f7/src/com/facebook/buck/cli/Main.java#L259-L299 When Buck sees a new source file (as reported by Watchman), it has to invalidate a number of caches associated with the directory that contains the file. Using a standard suffix, such as `~`, would make it easier for Buck and others to filter out these types of file creation events. The other uses of `tempfile.mkstemp()` in Hg do not appear to be problematic because they (generally speaking) do not specify the `dir` parameter, so the new file is created in the system-appropriate temp directory, which is outside the working copy. Test Plan: `make tests` Differential Revision: https://phab.mercurial-scm.org/D468
author Michael Bolin <mbolin@fb.com>
date Tue, 22 Aug 2017 00:38:38 +0000
parents cfcfbe6c96f8
children ca6a3852daf0
comparison
equal deleted inserted replaced
34019:3340efe80803 34020:2ad028635ccd
1523 can use emptyok=True as an optimization. 1523 can use emptyok=True as an optimization.
1524 1524
1525 Returns the name of the temporary file. 1525 Returns the name of the temporary file.
1526 """ 1526 """
1527 d, fn = os.path.split(name) 1527 d, fn = os.path.split(name)
1528 fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, dir=d) 1528 fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, suffix='~', dir=d)
1529 os.close(fd) 1529 os.close(fd)
1530 # Temporary files are created with mode 0600, which is usually not 1530 # Temporary files are created with mode 0600, which is usually not
1531 # what we want. If the original file already exists, just copy 1531 # what we want. If the original file already exists, just copy
1532 # its mode. Otherwise, manually obey umask. 1532 # its mode. Otherwise, manually obey umask.
1533 copymode(name, temp, createmode) 1533 copymode(name, temp, createmode)