##// END OF EJS Templates
util: factor new function copymode out of mktempcopy
Adrian Buehlmann -
r15010:c3114acd default
parent child Browse files
Show More
@@ -701,6 +701,21 b' def gui():'
701 701 else:
702 702 return os.name == "nt" or os.environ.get("DISPLAY")
703 703
704 def copymode(src, dst, mode=None):
705 '''Copy the file mode from the file at path src to dst.
706 If src doesn't exist, we're using mode instead. If mode is None, we're
707 using umask.'''
708 try:
709 st_mode = os.lstat(src).st_mode & 0777
710 except OSError, inst:
711 if inst.errno != errno.ENOENT:
712 raise
713 st_mode = mode
714 if st_mode is None:
715 st_mode = ~umask
716 st_mode &= 0666
717 os.chmod(dst, st_mode)
718
704 719 def mktempcopy(name, emptyok=False, createmode=None):
705 720 """Create a temporary file with the same contents from name
706 721
@@ -717,16 +732,7 b' def mktempcopy(name, emptyok=False, crea'
717 732 # Temporary files are created with mode 0600, which is usually not
718 733 # what we want. If the original file already exists, just copy
719 734 # its mode. Otherwise, manually obey umask.
720 try:
721 st_mode = os.lstat(name).st_mode & 0777
722 except OSError, inst:
723 if inst.errno != errno.ENOENT:
724 raise
725 st_mode = createmode
726 if st_mode is None:
727 st_mode = ~umask
728 st_mode &= 0666
729 os.chmod(temp, st_mode)
735 copymode(name, temp, createmode)
730 736 if emptyok:
731 737 return temp
732 738 try:
General Comments 0
You need to be logged in to leave comments. Login now