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
16f344df
Kaydet (Commit)
16f344df
authored
Kas 01, 2010
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #10184: Touch directories only once when extracting a tarfile.
üst
bbea35f1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
11 deletions
+29
-11
tarfile.rst
Doc/library/tarfile.rst
+5
-2
tarfile.py
Lib/tarfile.py
+13
-9
test_tarfile.py
Lib/test/test_tarfile.py
+9
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/tarfile.rst
Dosyayı görüntüle @
16f344df
...
...
@@ -336,12 +336,13 @@ be finalized; only the internally used file object will be closed. See the
dots ``".."``.
.. method:: TarFile.extract(member, path="")
.. method:: TarFile.extract(member, path=""
, set_attrs=True
)
Extract a member from the archive to the current working directory, using its
full name. Its file information is extracted as accurately as possible. *member*
may be a filename or a :class:`TarInfo` object. You can specify a different
directory using *path*.
directory using *path*. File attributes (owner, mtime, mode) are set unless
*set_attrs* is False.
.. note::
...
...
@@ -352,6 +353,8 @@ be finalized; only the internally used file object will be closed. See the
See the warning for :meth:`extractall`.
.. versionchanged:: 3.2
Added the *set_attrs* parameter.
.. method:: TarFile.extractfile(member)
...
...
Lib/tarfile.py
Dosyayı görüntüle @
16f344df
...
...
@@ -2131,7 +2131,8 @@ class TarFile(object):
directories
.
append
(
tarinfo
)
tarinfo
=
copy
.
copy
(
tarinfo
)
tarinfo
.
mode
=
0
o700
self
.
extract
(
tarinfo
,
path
)
# Do not set_attrs directories, as we will do that further down
self
.
extract
(
tarinfo
,
path
,
set_attrs
=
not
tarinfo
.
isdir
())
# Reverse sort directories.
directories
.
sort
(
key
=
lambda
a
:
a
.
name
)
...
...
@@ -2150,11 +2151,12 @@ class TarFile(object):
else
:
self
.
_dbg
(
1
,
"tarfile:
%
s"
%
e
)
def
extract
(
self
,
member
,
path
=
""
):
def
extract
(
self
,
member
,
path
=
""
,
set_attrs
=
True
):
"""Extract a member from the archive to the current working directory,
using its full name. Its file information is extracted as accurately
as possible. `member' may be a filename or a TarInfo object. You can
specify a different directory using `path'.
specify a different directory using `path'. File attributes (owner,
mtime, mode) are set unless `set_attrs' is False.
"""
self
.
_check
(
"r"
)
...
...
@@ -2168,7 +2170,8 @@ class TarFile(object):
tarinfo
.
_link_target
=
os
.
path
.
join
(
path
,
tarinfo
.
linkname
)
try
:
self
.
_extract_member
(
tarinfo
,
os
.
path
.
join
(
path
,
tarinfo
.
name
))
self
.
_extract_member
(
tarinfo
,
os
.
path
.
join
(
path
,
tarinfo
.
name
),
set_attrs
=
set_attrs
)
except
EnvironmentError
as
e
:
if
self
.
errorlevel
>
0
:
raise
...
...
@@ -2221,7 +2224,7 @@ class TarFile(object):
# blkdev, etc.), return None instead of a file object.
return
None
def
_extract_member
(
self
,
tarinfo
,
targetpath
):
def
_extract_member
(
self
,
tarinfo
,
targetpath
,
set_attrs
=
True
):
"""Extract the TarInfo object tarinfo to a physical
file called targetpath.
"""
...
...
@@ -2258,10 +2261,11 @@ class TarFile(object):
else
:
self
.
makefile
(
tarinfo
,
targetpath
)
self
.
chown
(
tarinfo
,
targetpath
)
if
not
tarinfo
.
issym
():
self
.
chmod
(
tarinfo
,
targetpath
)
self
.
utime
(
tarinfo
,
targetpath
)
if
set_attrs
:
self
.
chown
(
tarinfo
,
targetpath
)
if
not
tarinfo
.
issym
():
self
.
chmod
(
tarinfo
,
targetpath
)
self
.
utime
(
tarinfo
,
targetpath
)
#--------------------------------------------------------------------------
# Below are the different file methods. They are called via
...
...
Lib/test/test_tarfile.py
Dosyayı görüntüle @
16f344df
...
...
@@ -377,6 +377,15 @@ class MiscReadTest(CommonReadTest):
finally
:
tar
.
close
()
def
test_extract_directory
(
self
):
dirtype
=
"ustar/dirtype"
with
tarfile
.
open
(
tarname
,
encoding
=
"iso8859-1"
)
as
tar
:
tarinfo
=
tar
.
getmember
(
dirtype
)
tar
.
extract
(
tarinfo
)
self
.
assertEqual
(
os
.
path
.
getmtime
(
dirtype
),
tarinfo
.
mtime
)
if
sys
.
platform
!=
"win32"
:
self
.
assertEqual
(
os
.
stat
(
dirtype
)
.
st_mode
&
0
o777
,
0
o755
)
def
test_init_close_fobj
(
self
):
# Issue #7341: Close the internal file object in the TarFile
# constructor in case of an error. For the test we rely on
...
...
Misc/NEWS
Dosyayı görüntüle @
16f344df
...
...
@@ -59,6 +59,8 @@ Core and Builtins
Library
-------
- Issue #10184: Touch directories only once when extracting a tarfile.
- Issue #10199: New package, ``turtledemo`` now contains selected demo
scripts that were formerly found under Demo/turtle.
...
...
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