Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-82367: UseFindFirstFile
Win32 API inntpath.realpath()
#110298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,6 +2,7 @@ | ||
import ntpath | ||
import os | ||
import string | ||
import subprocess | ||
import sys | ||
import unittest | ||
import warnings | ||
@@ -637,6 +638,48 @@ def test_realpath_cwd(self): | ||
with os_helper.change_cwd(test_dir_short): | ||
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt")) | ||
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname') | ||
def test_realpath_permission(self): | ||
# Test whether python can resolve the real filename of a | ||
# shortened file name even if it does not have permission to access it. | ||
ABSTFN = ntpath.realpath(os_helper.TESTFN) | ||
os_helper.unlink(ABSTFN) | ||
os_helper.rmtree(ABSTFN) | ||
os.mkdir(ABSTFN) | ||
self.addCleanup(os_helper.rmtree, ABSTFN) | ||
test_file = ntpath.join(ABSTFN, "LongFileName123.txt") | ||
test_file_short = ntpath.join(ABSTFN, "LONGFI~1.TXT") | ||
with open(test_file, "wb") as f: | ||
f.write(b"content") | ||
moonsikpark marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
# Automatic generation of short names may be disabled on | ||
# NTFS volumes for the sake of performance. | ||
# They're not supported at all on ReFS and exFAT. | ||
subprocess.run( | ||
# Try to set the short name manually. | ||
['fsutil.exe', 'file', 'setShortName', test_file, 'LONGFI~1.TXT'], | ||
creationflags=subprocess.DETACHED_PROCESS | ||
) | ||
try: | ||
self.assertPathEqual(test_file, ntpath.realpath(test_file_short)) | ||
except AssertionError: | ||
raise unittest.SkipTest('the filesystem seems to lack support for short filenames') | ||
# Deny the right to [S]YNCHRONIZE on the file to | ||
# force nt._getfinalpathname to fail with ERROR_ACCESS_DENIED. | ||
p = subprocess.run( | ||
['icacls.exe', test_file, '/deny', '*S-1-5-32-545:(S)'], | ||
creationflags=subprocess.DETACHED_PROCESS | ||
) | ||
if p.returncode: | ||
raise unittest.SkipTest('failed to deny access to the test file') | ||
self.assertPathEqual(test_file, ntpath.realpath(test_file_short)) | ||
def test_expandvars(self): | ||
with os_helper.EnvironmentVarGuard() as env: | ||
env.clear() | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:func:`os.path.realpath` now resolves MS-DOS style file names even if | ||
the file is not accessible. Patch by Moonsik Park. |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.