File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -2088,6 +2088,7 @@ def close(self):
20882088 blocks , remainder = divmod (self .offset , RECORDSIZE )
20892089 if remainder > 0 :
20902090 self .fileobj .write (NUL * (RECORDSIZE - remainder ))
2091+ self .offset += (RECORDSIZE - remainder )
20912092 finally :
20922093 if not self ._extfileobj :
20932094 self .fileobj .close ()
Original file line number Diff line number Diff line change @@ -1358,6 +1358,17 @@ def test_eof_marker(self):
13581358 with self .open (tmpname , "rb" ) as fobj :
13591359 self .assertEqual (len (fobj .read ()), tarfile .RECORDSIZE * 2 )
13601360
1361+ def test_offset_on_close (self ):
1362+ # Check the offset after calling close matches the total number of
1363+ # bytes written.
1364+ tar = tarfile .open (tmpname , self .mode )
1365+ t = tarfile .TarInfo ("foo" )
1366+ tar .addfile (t )
1367+ tar .close ()
1368+
1369+ with self .open (tmpname , "rb" ) as fobj :
1370+ self .assertEqual (len (fobj .read ()), tar .offset )
1371+
13611372
13621373class WriteTest (WriteTestBase , unittest .TestCase ):
13631374
You can’t perform that action at this time.
0 commit comments