Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-68164: Set the "regular file" bit in zipfile's writestr#134232

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

Open
thatch wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromthatch:file-mode
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
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
6 changes: 3 additions & 3 deletionsLib/test/test_zipfile/test_core.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -496,7 +496,7 @@ def zip_test_writestr_permissions(self, f, compression):
self.make_test_archive(f, compression)
with zipfile.ZipFile(f, "r") as zipfp:
zinfo = zipfp.getinfo('strfile')
self.assertEqual(zinfo.external_attr,0o600 << 16)
self.assertEqual(zinfo.external_attr,0o100600 << 16)

zinfo2 = zipfp.getinfo('written-open-w')
self.assertEqual(zinfo2.external_attr, 0o600 << 16)
Expand DownExpand Up@@ -2271,8 +2271,8 @@ def test_for_archive(self):
zi = zipfile.ZipInfo(base_filename)._for_archive(zf)
self.assertEqual(zi.compress_level, 1)
self.assertEqual(zi.compress_type, zipfile.ZIP_STORED)
#?rw- --- ---
filemode = stat.S_IRUSR | stat.S_IWUSR
#-rw- --- ---
filemode = stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR
# filemode is stored as the highest 16 bits of external_attr
self.assertEqual(zi.external_attr >> 16, filemode)
self.assertEqual(zi.external_attr & 0xFF, 0) # no MS-DOS flag
Expand Down
6 changes: 3 additions & 3 deletionsLib/zipfile/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -630,10 +630,10 @@ def _for_archive(self, archive):
self.compress_type = archive.compression
self.compress_level = archive.compresslevel
if self.filename.endswith('/'): # pragma: no cover
self.external_attr =0o40775 << 16 # drwxrwxr-x
self.external_attr =(stat.S_IFDIR | 0o775) << 16 # drwxrwxr-x
self.external_attr |= 0x10 # MS-DOS directory flag
else:
self.external_attr = 0o600 << 16 #?rw-------
self.external_attr =(stat.S_IFREG |0o600) << 16 #-rw-------
return self

def is_dir(self):
Expand DownExpand Up@@ -2012,7 +2012,7 @@ def mkdir(self, zinfo_or_directory_name, mode=511):
zinfo = ZipInfo(directory_name)
zinfo.compress_size = 0
zinfo.CRC = 0
zinfo.external_attr = ((0o40000 | mode) & 0xFFFF) << 16
zinfo.external_attr = ((stat.S_IFDIR | mode) & 0xFFFF) << 16
zinfo.file_size = 0
zinfo.external_attr |= 0x10
else:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Fix :func:`zipfile.ZipFile.writestr` so it sets the "regular file" bit by
default.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp