Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6d343e70
Commit
6d343e70
authored
Sep 23, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20912: Now directories added to ZIP file have correct Unix and MS-DOS
directory attributes.
parent
1af262c6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
4 deletions
+49
-4
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+40
-3
Lib/zipfile.py
Lib/zipfile.py
+6
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_zipfile.py
View file @
6d343e70
...
@@ -1472,11 +1472,48 @@ class TestWithDirectory(unittest.TestCase):
...
@@ -1472,11 +1472,48 @@ class TestWithDirectory(unittest.TestCase):
os
.
mkdir
(
os
.
path
.
join
(
TESTFN2
,
"a"
))
os
.
mkdir
(
os
.
path
.
join
(
TESTFN2
,
"a"
))
self
.
test_extract_dir
()
self
.
test_extract_dir
()
def
test_store_dir
(
self
):
def
test_write_dir
(
self
):
dirpath
=
os
.
path
.
join
(
TESTFN2
,
"x"
)
os
.
mkdir
(
dirpath
)
mode
=
os
.
stat
(
dirpath
).
st_mode
&
0xFFFF
with
zipfile
.
ZipFile
(
TESTFN
,
"w"
)
as
zipf
:
zipf
.
write
(
dirpath
)
zinfo
=
zipf
.
filelist
[
0
]
self
.
assertTrue
(
zinfo
.
filename
.
endswith
(
"/x/"
))
self
.
assertEqual
(
zinfo
.
external_attr
,
(
mode
<<
16
)
|
0x10
)
zipf
.
write
(
dirpath
,
"y"
)
zinfo
=
zipf
.
filelist
[
1
]
self
.
assertTrue
(
zinfo
.
filename
,
"y/"
)
self
.
assertEqual
(
zinfo
.
external_attr
,
(
mode
<<
16
)
|
0x10
)
with
zipfile
.
ZipFile
(
TESTFN
,
"r"
)
as
zipf
:
zinfo
=
zipf
.
filelist
[
0
]
self
.
assertTrue
(
zinfo
.
filename
.
endswith
(
"/x/"
))
self
.
assertEqual
(
zinfo
.
external_attr
,
(
mode
<<
16
)
|
0x10
)
zinfo
=
zipf
.
filelist
[
1
]
self
.
assertTrue
(
zinfo
.
filename
,
"y/"
)
self
.
assertEqual
(
zinfo
.
external_attr
,
(
mode
<<
16
)
|
0x10
)
target
=
os
.
path
.
join
(
TESTFN2
,
"target"
)
os
.
mkdir
(
target
)
zipf
.
extractall
(
target
)
self
.
assertTrue
(
os
.
path
.
isdir
(
os
.
path
.
join
(
target
,
"y"
)))
self
.
assertEqual
(
len
(
os
.
listdir
(
target
)),
2
)
def
test_writestr_dir
(
self
):
os
.
mkdir
(
os
.
path
.
join
(
TESTFN2
,
"x"
))
os
.
mkdir
(
os
.
path
.
join
(
TESTFN2
,
"x"
))
with
zipfile
.
ZipFile
(
TESTFN
,
"w"
)
as
zipf
:
with
zipfile
.
ZipFile
(
TESTFN
,
"w"
)
as
zipf
:
zipf
.
write
(
os
.
path
.
join
(
TESTFN2
,
"x"
),
"x"
)
zipf
.
writestr
(
"x/"
,
b''
)
self
.
assertTrue
(
zipf
.
filelist
[
0
].
filename
.
endswith
(
"x/"
))
zinfo
=
zipf
.
filelist
[
0
]
self
.
assertEqual
(
zinfo
.
filename
,
"x/"
)
self
.
assertEqual
(
zinfo
.
external_attr
,
(
0o40775
<<
16
)
|
0x10
)
with
zipfile
.
ZipFile
(
TESTFN
,
"r"
)
as
zipf
:
zinfo
=
zipf
.
filelist
[
0
]
self
.
assertTrue
(
zinfo
.
filename
.
endswith
(
"x/"
))
self
.
assertEqual
(
zinfo
.
external_attr
,
(
0o40775
<<
16
)
|
0x10
)
target
=
os
.
path
.
join
(
TESTFN2
,
"target"
)
os
.
mkdir
(
target
)
zipf
.
extractall
(
target
)
self
.
assertTrue
(
os
.
path
.
isdir
(
os
.
path
.
join
(
target
,
"x"
)))
self
.
assertEqual
(
os
.
listdir
(
target
),
[
"x"
])
def
tearDown
(
self
):
def
tearDown
(
self
):
rmtree
(
TESTFN2
)
rmtree
(
TESTFN2
)
...
...
Lib/zipfile.py
View file @
6d343e70
...
@@ -1150,6 +1150,7 @@ class ZipFile(object):
...
@@ -1150,6 +1150,7 @@ class ZipFile(object):
zinfo
.
file_size
=
0
zinfo
.
file_size
=
0
zinfo
.
compress_size
=
0
zinfo
.
compress_size
=
0
zinfo
.
CRC
=
0
zinfo
.
CRC
=
0
zinfo
.
external_attr
|=
0x10
# MS-DOS directory flag
self
.
filelist
.
append
(
zinfo
)
self
.
filelist
.
append
(
zinfo
)
self
.
NameToInfo
[
zinfo
.
filename
]
=
zinfo
self
.
NameToInfo
[
zinfo
.
filename
]
=
zinfo
self
.
fp
.
write
(
zinfo
.
FileHeader
(
False
))
self
.
fp
.
write
(
zinfo
.
FileHeader
(
False
))
...
@@ -1211,7 +1212,11 @@ class ZipFile(object):
...
@@ -1211,7 +1212,11 @@ class ZipFile(object):
date_time
=
time
.
localtime
(
time
.
time
())[:
6
])
date_time
=
time
.
localtime
(
time
.
time
())[:
6
])
zinfo
.
compress_type
=
self
.
compression
zinfo
.
compress_type
=
self
.
compression
zinfo
.
external_attr
=
0600
<<
16
if
zinfo
.
filename
[
-
1
]
==
'/'
:
zinfo
.
external_attr
=
0o40775
<<
16
# drwxrwxr-x
zinfo
.
external_attr
|=
0x10
# MS-DOS directory flag
else
:
zinfo
.
external_attr
=
0o600
<<
16
# ?rw-------
else
:
else
:
zinfo
=
zinfo_or_arcname
zinfo
=
zinfo_or_arcname
...
...
Misc/NEWS
View file @
6d343e70
...
@@ -22,6 +22,9 @@ Core and Builtins
...
@@ -22,6 +22,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
20912
:
Now
directories
added
to
ZIP
file
have
correct
Unix
and
MS
-
DOS
directory
attributes
.
-
Issue
#
21866
:
ZipFile
.
close
()
no
longer
writes
ZIP64
central
directory
-
Issue
#
21866
:
ZipFile
.
close
()
no
longer
writes
ZIP64
central
directory
records
if
allowZip64
is
false
.
records
if
allowZip64
is
false
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment