Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
33021c5
bpo-37834: Enable os.readlink and os.path.is_link to recognize app ex…
zooba Aug 12, 2019
6b5d22d
Add reparse_tag to stat structure and add test
zooba Aug 12, 2019
658a355
Revert readlink change and only traverse actual symlinks
zooba Aug 12, 2019
75d039e
Treat junctions as links. Update tests
zooba Aug 13, 2019
3a64166
Fix NEWS item
zooba Aug 13, 2019
ec43378
Revert getfinalpathname change, add test fixes until bpo-9949 is fixed
zooba Aug 13, 2019
ebcbca2
Add link target resolution and revert test changes
zooba Aug 13, 2019
1aba497
Revert shutil test
zooba Aug 13, 2019
b65f06f
[WIP] bpo-9949: Enable symlink traversal for ntpath.realpath
zooba Aug 14, 2019
df54868
Fixes link resolution and test file creation
zooba Aug 14, 2019
f82129b
Fix x-plat handling in test_ntpath and additional error code
zooba Aug 14, 2019
8ee4046
Fix use of os.path in ntpath tests
zooba Aug 14, 2019
b93c9e8
Fix additional uses of os.path
zooba Aug 14, 2019
5f9816f
Validate that the path prefix is unnecessary before removing
zooba Aug 14, 2019
d1d0726
Don't need second call to _getfinalpathname
zooba Aug 14, 2019
c178e45
Rewrite Windows stat() implementation to let the OS traverse symlinks…
zooba Aug 14, 2019
8ed0cf6
Fix st_mode when unable to read path
zooba Aug 14, 2019
863e8c4
Fix some uninitialized values. Remove bad changes
zooba Aug 14, 2019
9bc4192
Fix test discovery mocks
zooba Aug 14, 2019
541dcf8
Remove get_target_path and fix tests
zooba Aug 15, 2019
f2d2e31
Fix special handling for non-traversable reparse points
zooba Aug 15, 2019
d93caf7
Merge branch 'bpo-37834' into bpo-9949-37834
zooba Aug 15, 2019
9dc0608
Avoid traversing a symlink cycle
zooba Aug 15, 2019
7bc2568
Merge branch 'bpo-9949' into bpo-9949-37834
zooba Aug 15, 2019
2f84d8c
Treat all unfollowable links equally.
zooba Aug 16, 2019
6139abf
Merge branch 'bpo-37834' into bpo-9949-37834
zooba Aug 16, 2019
4cb450e
Fix isdir test
zooba Aug 16, 2019
79a3f54
Merge branch 'bpo-37834' into bpo-9949-37834
zooba Aug 16, 2019
28c9bb4
Simplify and document cycle handling in os.path.realpath
zooba Aug 16, 2019
203869f
Merge branch 'bpo-9949' into bpo-9949-37834
zooba Aug 16, 2019
4ee15a8
Update docs
zooba Aug 16, 2019
ab485a5
Update whatsnew
zooba Aug 16, 2019
11e8092
Merge branch 'bpo-9949' into bpo-9949-37834
zooba Aug 16, 2019
25511ea
Merge branch 'bpo-37834' into bpo-9949-37834
zooba Aug 16, 2019
327cf57
Clarify docs
zooba Aug 16, 2019
39bec11
Update patch with implementation from Eryk Sun.
zooba Aug 19, 2019
d73d077
Swap order of tests to avoid unnecessary failed API calls
zooba Aug 19, 2019
51c338e
Merge branch 'bpo-37834' into bpo-9949-37834
zooba Aug 19, 2019
57cc198
Remove workaround for bpo20541 as NUL now exists
zooba Aug 20, 2019
0b926e1
Merge branch 'bpo-37834' into bpo-9949-37834
zooba Aug 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove get_target_path and fix tests
  • Loading branch information
zooba committed Aug 15, 2019
commit 541dcf8b92061da5902dedcd7b48b5959c289fa3
11 changes: 6 additions & 5 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -2258,12 +2258,13 @@ def assertPathEqual(self, left, right):
left = os.path.normcase(left)
right = os.path.normcase(right)
if sys.platform == 'win32':
# Stripping prefixes blindly is generally bad practice,
# but all we are doing here is comparing the paths, so
# it works out okay.
if left[:4] in ('\\\\?\\', b'\\\\?\\'):
# Bad practice to blindly strip the prefix as it may be required to
# correctly refer to the file, but we're only comparing paths here.
has_prefix = lambda p: p.startswith(
b'\\\\?\\' if isinstance(p, bytes) else '\\\\?\\')
if has_prefix(left):
left = left[4:]
if right[:4] in ('\\\\?\\', b'\\\\?\\'):
if has_prefix(right):
right = right[4:]
self.assertEqual(left, right)

Expand Down
8 changes: 6 additions & 2 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,12 @@ def test_copytree_symlinks(self):
src_stat = os.lstat(src_link)
shutil.copytree(src_dir, dst_dir, symlinks=True)
self.assertTrue(os.path.islink(os.path.join(dst_dir, 'sub', 'link')))
self.assertEqual(os.readlink(os.path.join(dst_dir, 'sub', 'link')),
os.path.join(src_dir, 'file.txt'))
actual = os.readlink(os.path.join(dst_dir, 'sub', 'link'))
# Bad practice to blindly strip the prefix as it may be required to
# correctly refer to the file, but we're only comparing paths here.
if os.name == 'nt' and actual.startswith('\\\\?\\'):
actual = actual[4:]
self.assertEqual(actual, os.path.join(src_dir, 'file.txt'))
dst_stat = os.lstat(dst_link)
if hasattr(os, 'lchmod'):
self.assertEqual(dst_stat.st_mode, src_stat.st_mode)
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_tools/test_lll.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ def test_lll_multiple_dirs(self):

with support.captured_stdout() as output:
self.lll.main([dir1, dir2])
prefix = '\\\\?\\' if os.name == 'nt' else ''
self.assertEqual(output.getvalue(),
f'{dir1}:\n'
f'symlink -> {fn1}\n'
f'symlink -> {prefix}{fn1}\n'
f'\n'
f'{dir2}:\n'
f'symlink -> {fn2}\n'
f'symlink -> {prefix}{fn2}\n'
)


Expand Down
33 changes: 0 additions & 33 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1659,39 +1659,6 @@ attributes_from_dir(LPCWSTR pszFile, BY_HANDLE_FILE_INFORMATION *info, ULONG *re
return TRUE;
}

static BOOL
get_target_path(HANDLE hdl, wchar_t **target_path)
{
int buf_size, result_length;
wchar_t *buf;

/* We have a good handle to the target, use it to determine
the target path name (then we'll call lstat on it). */
buf_size = GetFinalPathNameByHandleW(hdl, 0, 0,
VOLUME_NAME_DOS);
if(!buf_size)
return FALSE;

buf = (wchar_t *)PyMem_RawMalloc((buf_size + 1) * sizeof(wchar_t));
if (!buf) {
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}

result_length = GetFinalPathNameByHandleW(hdl,
buf, buf_size, VOLUME_NAME_DOS);

if(!result_length) {
PyMem_RawFree(buf);
return FALSE;
}

buf[result_length] = 0;

*target_path = buf;
return TRUE;
}

static int
win32_xstat_impl(const wchar_t *path, struct _Py_stat_struct *result,
BOOL traverse)
Expand Down