##// END OF EJS Templates
util: refactor opener...
Adrian Buehlmann -
r12927:b6245c24 default
parent child Browse files
Show More
@@ -858,23 +858,34 b' class opener(object):'
858 mode += "b" # for that other OS
858 mode += "b" # for that other OS
859
859
860 nlink = -1
860 nlink = -1
861 if mode not in ("r", "rb"):
861 st_mode = None
862 dirname, basename = os.path.split(f)
863 # If basename is empty, then the path is malformed because it points
864 # to a directory. Let the posixfile() call below raise IOError.
865 if basename and mode not in ('r', 'rb'):
866 if atomictemp:
867 if not os.path.isdir(dirname):
868 makedirs(dirname, self.createmode)
869 return atomictempfile(f, mode, self.createmode)
862 try:
870 try:
863 nlink = nlinks(f)
871 if 'w' in mode:
872 st_mode = os.lstat(f).st_mode & 0777
873 os.unlink(f)
874 nlink = 0
875 else:
876 nlink = nlinks(f)
864 except OSError:
877 except OSError:
865 nlink = 0
878 nlink = 0
866 dirname, basename = os.path.split(f)
879 if not os.path.isdir(dirname):
867 # Avoid calling makedirs when the path points to a
868 # directory -- the open will raise IOError below.
869 if basename and not os.path.isdir(dirname):
870 makedirs(dirname, self.createmode)
880 makedirs(dirname, self.createmode)
871 if atomictemp:
872 return atomictempfile(f, mode, self.createmode)
873 if nlink > 1:
881 if nlink > 1:
874 rename(mktempcopy(f), f)
882 rename(mktempcopy(f), f)
875 fp = posixfile(f, mode)
883 fp = posixfile(f, mode)
876 if nlink == 0:
884 if nlink == 0:
877 self._fixfilemode(f)
885 if st_mode is None:
886 self._fixfilemode(f)
887 else:
888 os.chmod(f, st_mode)
878 return fp
889 return fp
879
890
880 def symlink(self, src, dst):
891 def symlink(self, src, dst):
General Comments 0
You need to be logged in to leave comments. Login now