Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c2ea8c6c
Kaydet (Commit)
c2ea8c6c
authored
Nis 14, 2008
tarafından
Lars Gustäbel
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #2058: Remove the buf attribute and add __slots__ to the
TarInfo class in order to reduce tarfile's memory usage.
üst
13d4a610
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
34 deletions
+46
-34
tarfile.py
Lib/tarfile.py
+43
-34
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/tarfile.py
Dosyayı görüntüle @
c2ea8c6c
...
...
@@ -767,7 +767,7 @@ class ExFileObject(object):
self
.
fileobj
=
_FileInFile
(
tarfile
.
fileobj
,
tarinfo
.
offset_data
,
tarinfo
.
size
,
getattr
(
tarinfo
,
"sparse"
,
None
)
)
tarinfo
.
sparse
)
self
.
name
=
tarinfo
.
name
self
.
mode
=
"r"
self
.
closed
=
False
...
...
@@ -906,6 +906,12 @@ class TarInfo(object):
usually created internally.
"""
__slots__
=
(
"name"
,
"mode"
,
"uid"
,
"gid"
,
"size"
,
"mtime"
,
"chksum"
,
"type"
,
"linkname"
,
"uname"
,
"gname"
,
"devmajor"
,
"devminor"
,
"offset"
,
"offset_data"
,
"pax_headers"
,
"sparse"
,
"tarfile"
,
"_sparse_structs"
,
"_link_target"
)
def
__init__
(
self
,
name
=
""
):
"""Construct a TarInfo object. name is the optional name
of the member.
...
...
@@ -927,6 +933,7 @@ class TarInfo(object):
self
.
offset
=
0
# the tar header starts here
self
.
offset_data
=
0
# the file's data starts here
self
.
sparse
=
None
# sparse member information
self
.
pax_headers
=
{}
# pax header information
# In pax headers the "name" and "linkname" field are called
...
...
@@ -1181,7 +1188,6 @@ class TarInfo(object):
raise
HeaderError
(
"bad checksum"
)
obj
=
cls
()
obj
.
buf
=
buf
obj
.
name
=
nts
(
buf
[
0
:
100
],
encoding
,
errors
)
obj
.
mode
=
nti
(
buf
[
100
:
108
])
obj
.
uid
=
nti
(
buf
[
108
:
116
])
...
...
@@ -1202,6 +1208,24 @@ class TarInfo(object):
if
obj
.
type
==
AREGTYPE
and
obj
.
name
.
endswith
(
"/"
):
obj
.
type
=
DIRTYPE
# The old GNU sparse format occupies some of the unused
# space in the buffer for up to 4 sparse structures.
# Save the them for later processing in _proc_sparse().
if
obj
.
type
==
GNUTYPE_SPARSE
:
pos
=
386
structs
=
[]
for
i
in
range
(
4
):
try
:
offset
=
nti
(
buf
[
pos
:
pos
+
12
])
numbytes
=
nti
(
buf
[
pos
+
12
:
pos
+
24
])
except
ValueError
:
break
structs
.
append
((
offset
,
numbytes
))
pos
+=
24
isextended
=
bool
(
buf
[
482
])
origsize
=
nti
(
buf
[
483
:
495
])
obj
.
_sparse_structs
=
(
structs
,
isextended
,
origsize
)
# Remove redundant slashes from directories.
if
obj
.
isdir
():
obj
.
name
=
obj
.
name
.
rstrip
(
"/"
)
...
...
@@ -1288,31 +1312,11 @@ class TarInfo(object):
def
_proc_sparse
(
self
,
tarfile
):
"""Process a GNU sparse header plus extra headers.
"""
buf
=
self
.
buf
sp
=
_ringbuffer
()
pos
=
386
lastpos
=
0
realpos
=
0
# There are 4 possible sparse structs in the
# first header.
for
i
in
range
(
4
):
try
:
offset
=
nti
(
buf
[
pos
:
pos
+
12
])
numbytes
=
nti
(
buf
[
pos
+
12
:
pos
+
24
])
except
ValueError
:
break
if
offset
>
lastpos
:
sp
.
append
(
_hole
(
lastpos
,
offset
-
lastpos
))
sp
.
append
(
_data
(
offset
,
numbytes
,
realpos
))
realpos
+=
numbytes
lastpos
=
offset
+
numbytes
pos
+=
24
isextended
=
bool
(
buf
[
482
])
origsize
=
nti
(
buf
[
483
:
495
])
# We already collected some sparse structures in frombuf().
structs
,
isextended
,
origsize
=
self
.
_sparse_structs
del
self
.
_sparse_structs
# If the isextended flag is given,
# there are extra headers to process.
# Collect sparse structures from extended header blocks.
while
isextended
:
buf
=
tarfile
.
fileobj
.
read
(
BLOCKSIZE
)
pos
=
0
...
...
@@ -1322,18 +1326,23 @@ class TarInfo(object):
numbytes
=
nti
(
buf
[
pos
+
12
:
pos
+
24
])
except
ValueError
:
break
if
offset
>
lastpos
:
sp
.
append
(
_hole
(
lastpos
,
offset
-
lastpos
))
sp
.
append
(
_data
(
offset
,
numbytes
,
realpos
))
realpos
+=
numbytes
lastpos
=
offset
+
numbytes
structs
.
append
((
offset
,
numbytes
))
pos
+=
24
isextended
=
bool
(
buf
[
504
])
# Transform the sparse structures to something we can use
# in ExFileObject.
self
.
sparse
=
_ringbuffer
()
lastpos
=
0
realpos
=
0
for
offset
,
numbytes
in
structs
:
if
offset
>
lastpos
:
self
.
sparse
.
append
(
_hole
(
lastpos
,
offset
-
lastpos
))
self
.
sparse
.
append
(
_data
(
offset
,
numbytes
,
realpos
))
realpos
+=
numbytes
lastpos
=
offset
+
numbytes
if
lastpos
<
origsize
:
sp
.
append
(
_hole
(
lastpos
,
origsize
-
lastpos
))
self
.
sparse
=
sp
self
.
sparse
.
append
(
_hole
(
lastpos
,
origsize
-
lastpos
))
self
.
offset_data
=
tarfile
.
fileobj
.
tell
()
tarfile
.
offset
=
self
.
offset_data
+
self
.
_block
(
self
.
size
)
...
...
Misc/NEWS
Dosyayı görüntüle @
c2ea8c6c
...
...
@@ -29,6 +29,9 @@ Extension Modules
Library
-------
- Issue #2058: Remove the buf attribute and add __slots__ to the TarInfo
class in order to reduce tarfile's memory usage.
- Bug #2606: Avoid calling .sort() on a dict_keys object.
- The bundled libffi copy is now in sync with the recently released
...
...
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