mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Issue #17222: Raise FileExistsError when py_compile.compile would
overwrite a symlink or non-regular file with a regular file.
This commit is contained in:
parent
3fe35e6503
commit
33915eba7c
5 changed files with 52 additions and 1 deletions
|
|
@ -36,6 +36,26 @@ class PyCompileTests(unittest.TestCase):
|
|||
self.assertTrue(os.path.exists(self.pyc_path))
|
||||
self.assertFalse(os.path.exists(self.cache_path))
|
||||
|
||||
def test_do_not_overwrite_symlinks(self):
|
||||
# In the face of a cfile argument being a symlink, bail out.
|
||||
# Issue #17222
|
||||
try:
|
||||
os.symlink(self.pyc_path + '.actual', self.pyc_path)
|
||||
except OSError:
|
||||
self.skipTest('need to be able to create a symlink for a file')
|
||||
else:
|
||||
assert os.path.islink(self.pyc_path)
|
||||
with self.assertRaises(FileExistsError):
|
||||
py_compile.compile(self.source_path, self.pyc_path)
|
||||
|
||||
@unittest.skipIf(not os.path.exists(os.devnull) or os.path.isfile(os.devnull),
|
||||
'requires os.devnull and for it to be a non-regular file')
|
||||
def test_do_not_overwrite_nonregular_files(self):
|
||||
# In the face of a cfile argument being a non-regular file, bail out.
|
||||
# Issue #17222
|
||||
with self.assertRaises(FileExistsError):
|
||||
py_compile.compile(self.source_path, os.devnull)
|
||||
|
||||
def test_cache_path(self):
|
||||
py_compile.compile(self.source_path)
|
||||
self.assertTrue(os.path.exists(self.cache_path))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue