Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 15058:81f33be0ea79
util: postpone and reorder parent calculation in makedirs
author | Adrian Buehlmann <adrian@cadifra.com> |
---|---|
date | Thu, 25 Aug 2011 11:03:16 +0200 |
parents | 774da7121fc9 |
children | cc16323e748d |
comparison
equal
deleted
inserted
replaced
15057:774da7121fc9 | 15058:81f33be0ea79 |
---|---|
777 if safehasattr(self, '_fp'): # constructor actually did something | 777 if safehasattr(self, '_fp'): # constructor actually did something |
778 self.discard() | 778 self.discard() |
779 | 779 |
780 def makedirs(name, mode=None): | 780 def makedirs(name, mode=None): |
781 """recursive directory creation with parent mode inheritance""" | 781 """recursive directory creation with parent mode inheritance""" |
782 parent = os.path.abspath(os.path.dirname(name)) | |
783 try: | 782 try: |
784 os.mkdir(name) | 783 os.mkdir(name) |
785 except OSError, err: | 784 except OSError, err: |
786 if err.errno == errno.EEXIST: | 785 if err.errno == errno.EEXIST: |
787 return | 786 return |
788 if not name or parent == name or err.errno != errno.ENOENT: | 787 if err.errno != errno.ENOENT or not name: |
788 raise | |
789 parent = os.path.dirname(os.path.abspath(name)) | |
790 if parent == name: | |
789 raise | 791 raise |
790 makedirs(parent, mode) | 792 makedirs(parent, mode) |
791 os.mkdir(name) | 793 os.mkdir(name) |
792 if mode is not None: | 794 if mode is not None: |
793 os.chmod(name, mode) | 795 os.chmod(name, mode) |