Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 963cd2d

Browse files
committed
Andrew Kuchling: changed so the '_path_created' dictionary is keyed on
absolute pathnames; this lets it keep working in the face of chdir'ing around.
1 parent 3e6d438 commit 963cd2d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Lib/distutils/dir_util.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
4444
created_dirs = []
4545
if os.path.isdir(name) or name == '':
4646
return created_dirs
47-
if _path_created.get(name):
47+
if _path_created.get(os.path.abspath(name)):
4848
return created_dirs
4949

5050
(head, tail) = os.path.split(name)
@@ -64,7 +64,9 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
6464
for d in tails:
6565
#print "head = %s, d = %s: " % (head, d),
6666
head = os.path.join(head, d)
67-
if _path_created.get(head):
67+
abs_head = os.path.abspath(head)
68+
69+
if _path_created.get(abs_head):
6870
continue
6971

7072
if verbose:
@@ -78,7 +80,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
7880
raise DistutilsFileError, \
7981
"could not create '%s': %s" % (head, exc[-1])
8082

81-
_path_created[head] = 1
83+
_path_created[abs_head] = 1
8284
return created_dirs
8385

8486
# mkpath ()
@@ -208,8 +210,9 @@ def remove_tree (directory, verbose=0, dry_run=0):
208210
try:
209211
apply(cmd[0], (cmd[1],))
210212
# remove dir from cache if it's already there
211-
if _path_created.has_key(cmd[1]):
212-
del _path_created[cmd[1]]
213+
abspath = os.path.abspath(cmd[1])
214+
if _path_created.has_key(abspath):
215+
del _path_created[abspath]
213216
except (IOError, OSError), exc:
214217
if verbose:
215218
print grok_environment_error(

0 commit comments

Comments
 (0)