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
20703c69
Commit
20703c69
authored
May 27, 2015
by
Lars Gustäbel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tarfile.open() with mode 'x' created files without an end of archive marker.
parent
c30a6ce5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
3 deletions
+16
-3
Lib/tarfile.py
Lib/tarfile.py
+2
-2
Lib/test/test_tarfile.py
Lib/test/test_tarfile.py
+14
-1
No files found.
Lib/tarfile.py
View file @
20703c69
...
...
@@ -1484,7 +1484,7 @@ class TarFile(object):
except HeaderError as e:
raise ReadError(str(e))
if self.mode in
"
aw
"
:
if self.mode in
("
a
", "
w
", "
x
")
:
self._loaded = True
if self.pax_headers:
...
...
@@ -1716,7 +1716,7 @@ class TarFile(object):
self.closed = True
try:
if self.mode in
"
aw
"
:
if self.mode in
("
a
", "
w
", "
x
")
:
self.fileobj.write(NUL * (BLOCKSIZE * 2))
self.offset += (BLOCKSIZE * 2)
# fill up the end with zero-blocks
...
...
Lib/test/test_tarfile.py
View file @
20703c69
...
...
@@ -982,6 +982,19 @@ class WriteTestBase(TarTest):
self
.
assertFalse
(
fobj
.
closed
)
self
.
assertEqual
(
data
,
fobj
.
getvalue
())
def
test_eof_marker
(
self
):
# Make sure an end of archive marker is written (two zero blocks).
# tarfile insists on aligning archives to a 20 * 512 byte recordsize.
# So, we create an archive that has exactly 10240 bytes without the
# marker, and has 20480 bytes once the marker is written.
with
tarfile
.
open
(
tmpname
,
self
.
mode
)
as
tar
:
t
=
tarfile
.
TarInfo
(
"foo"
)
t
.
size
=
tarfile
.
RECORDSIZE
-
tarfile
.
BLOCKSIZE
tar
.
addfile
(
t
,
io
.
BytesIO
(
b"a"
*
t
.
size
))
with
self
.
open
(
tmpname
,
"rb"
)
as
fobj
:
self
.
assertEqual
(
len
(
fobj
.
read
()),
tarfile
.
RECORDSIZE
*
2
)
class
WriteTest
(
WriteTestBase
,
unittest
.
TestCase
):
...
...
@@ -1431,7 +1444,7 @@ class GNUWriteTest(unittest.TestCase):
(
"longlnk/"
*
127
)
+
"longlink_"
)
class
CreateTest
(
TarTest
,
unittest
.
TestCase
):
class
CreateTest
(
WriteTestBase
,
unittest
.
TestCase
):
prefix
=
"x:"
...
...
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