bpo-33660: Fix PosixPath to resolve a relative path on root
This commit is contained in:
parent
82e79480d6
commit
94ad6c674f
|
@ -329,7 +329,10 @@ class _PosixFlavour(_Flavour):
|
||||||
# parent dir
|
# parent dir
|
||||||
path, _, _ = path.rpartition(sep)
|
path, _, _ = path.rpartition(sep)
|
||||||
continue
|
continue
|
||||||
newpath = path + sep + name
|
if path.endswith(sep):
|
||||||
|
newpath = path + name
|
||||||
|
else:
|
||||||
|
newpath = path + sep + name
|
||||||
if newpath in seen:
|
if newpath in seen:
|
||||||
# Already seen this path
|
# Already seen this path
|
||||||
path = seen[newpath]
|
path = seen[newpath]
|
||||||
|
|
|
@ -2349,6 +2349,15 @@ class PosixPathTest(_BasePathTest, unittest.TestCase):
|
||||||
st = os.stat(join('other_new_file'))
|
st = os.stat(join('other_new_file'))
|
||||||
self.assertEqual(stat.S_IMODE(st.st_mode), 0o644)
|
self.assertEqual(stat.S_IMODE(st.st_mode), 0o644)
|
||||||
|
|
||||||
|
def test_resolve_root(self):
|
||||||
|
current_directory = os.getcwd()
|
||||||
|
try:
|
||||||
|
os.chdir('/')
|
||||||
|
p = self.cls('spam')
|
||||||
|
self.assertEqual(str(p.resolve()), '/spam')
|
||||||
|
finally:
|
||||||
|
os.chdir(current_directory)
|
||||||
|
|
||||||
def test_touch_mode(self):
|
def test_touch_mode(self):
|
||||||
old_mask = os.umask(0)
|
old_mask = os.umask(0)
|
||||||
self.addCleanup(os.umask, old_mask)
|
self.addCleanup(os.umask, old_mask)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix pathlib.PosixPath to resolve a relative path located on the root
|
||||||
|
directory properly.
|
Loading…
Reference in New Issue