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
ad5ae045
Kaydet (Commit)
ad5ae045
authored
Tem 15, 2012
tarafından
Larry Hastings
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
- Issue #15238: shutil.copystat now copies Linux "extended attributes".
üst
7c6309c6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
24 deletions
+37
-24
shutil.rst
Doc/library/shutil.rst
+3
-2
shutil.py
Lib/shutil.py
+22
-22
test_shutil.py
Lib/test/test_shutil.py
+10
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/shutil.rst
Dosyayı görüntüle @
ad5ae045
...
@@ -86,10 +86,11 @@ Directory and files operations
...
@@ -86,10 +86,11 @@ Directory and files operations
from *src* to *dst*. The file contents, owner, and group are unaffected. *src*
from *src* to *dst*. The file contents, owner, and group are unaffected. *src*
and *dst* are path names given as strings. If *src* and *dst* are both
and *dst* are path names given as strings. If *src* and *dst* are both
symbolic links and *symlinks* true, the stats of the link will be copied as
symbolic links and *symlinks* true, the stats of the link will be copied as
far as the platform allows.
far as the platform allows. On Linux, :func:`copystat` also copies the
"extended attributes" where possible.
.. versionchanged:: 3.3
.. versionchanged:: 3.3
Added *symlinks* argument.
Added *symlinks* argument
and support for Linux extended attributes
.
.. function:: copy(src, dst, symlinks=False)
.. function:: copy(src, dst, symlinks=False)
...
...
Lib/shutil.py
Dosyayı görüntüle @
ad5ae045
...
@@ -132,6 +132,27 @@ def copymode(src, dst, symlinks=False):
...
@@ -132,6 +132,27 @@ def copymode(src, dst, symlinks=False):
st
=
stat_func
(
src
)
st
=
stat_func
(
src
)
chmod_func
(
dst
,
stat
.
S_IMODE
(
st
.
st_mode
))
chmod_func
(
dst
,
stat
.
S_IMODE
(
st
.
st_mode
))
if
hasattr
(
os
,
'listxattr'
):
def
_copyxattr
(
src
,
dst
,
symlinks
=
False
):
"""Copy extended filesystem attributes from `src` to `dst`.
Overwrite existing attributes.
If the optional flag `symlinks` is set, symlinks won't be followed.
"""
for
name
in
os
.
listxattr
(
src
,
follow_symlinks
=
symlinks
):
try
:
value
=
os
.
getxattr
(
src
,
name
,
follow_symlinks
=
symlinks
)
os
.
setxattr
(
dst
,
name
,
value
,
follow_symlinks
=
symlinks
)
except
OSError
as
e
:
if
e
.
errno
not
in
(
errno
.
EPERM
,
errno
.
ENOTSUP
,
errno
.
ENODATA
):
raise
else
:
def
_copyxattr
(
*
args
,
**
kwargs
):
pass
def
copystat
(
src
,
dst
,
symlinks
=
False
):
def
copystat
(
src
,
dst
,
symlinks
=
False
):
"""Copy all stat info (mode bits, atime, mtime, flags) from src to dst.
"""Copy all stat info (mode bits, atime, mtime, flags) from src to dst.
...
@@ -184,27 +205,7 @@ def copystat(src, dst, symlinks=False):
...
@@ -184,27 +205,7 @@ def copystat(src, dst, symlinks=False):
break
break
else
:
else
:
raise
raise
_copyxattr
(
src
,
dst
,
symlinks
=
follow
)
if
hasattr
(
os
,
'listxattr'
):
def
_copyxattr
(
src
,
dst
,
symlinks
=
False
):
"""Copy extended filesystem attributes from `src` to `dst`.
Overwrite existing attributes.
If the optional flag `symlinks` is set, symlinks won't be followed.
"""
for
name
in
os
.
listxattr
(
src
,
follow_symlinks
=
symlinks
):
try
:
value
=
os
.
getxattr
(
src
,
name
,
follow_symlinks
=
symlinks
)
os
.
setxattr
(
dst
,
name
,
value
,
follow_symlinks
=
symlinks
)
except
OSError
as
e
:
if
e
.
errno
not
in
(
errno
.
EPERM
,
errno
.
ENOTSUP
,
errno
.
ENODATA
):
raise
else
:
def
_copyxattr
(
*
args
,
**
kwargs
):
pass
def
copy
(
src
,
dst
,
symlinks
=
False
):
def
copy
(
src
,
dst
,
symlinks
=
False
):
"""Copy data and mode bits ("cp src dst"). Return the file's destination.
"""Copy data and mode bits ("cp src dst"). Return the file's destination.
...
@@ -235,7 +236,6 @@ def copy2(src, dst, symlinks=False):
...
@@ -235,7 +236,6 @@ def copy2(src, dst, symlinks=False):
dst
=
os
.
path
.
join
(
dst
,
os
.
path
.
basename
(
src
))
dst
=
os
.
path
.
join
(
dst
,
os
.
path
.
basename
(
src
))
copyfile
(
src
,
dst
,
symlinks
=
symlinks
)
copyfile
(
src
,
dst
,
symlinks
=
symlinks
)
copystat
(
src
,
dst
,
symlinks
=
symlinks
)
copystat
(
src
,
dst
,
symlinks
=
symlinks
)
_copyxattr
(
src
,
dst
,
symlinks
=
symlinks
)
return
dst
return
dst
def
ignore_patterns
(
*
patterns
):
def
ignore_patterns
(
*
patterns
):
...
...
Lib/test/test_shutil.py
Dosyayı görüntüle @
ad5ae045
...
@@ -410,6 +410,16 @@ class TestShutil(unittest.TestCase):
...
@@ -410,6 +410,16 @@ class TestShutil(unittest.TestCase):
finally
:
finally
:
os
.
setxattr
=
orig_setxattr
os
.
setxattr
=
orig_setxattr
# test that shutil.copystat copies xattrs
src
=
os
.
path
.
join
(
tmp_dir
,
'the_original'
)
write_file
(
src
,
src
)
os
.
setxattr
(
src
,
'user.the_value'
,
b
'fiddly'
)
dst
=
os
.
path
.
join
(
tmp_dir
,
'the_copy'
)
write_file
(
dst
,
dst
)
shutil
.
copystat
(
src
,
dst
)
self
.
assertEqual
(
os
.
listxattr
(
src
),
[
'user.the_value'
])
self
.
assertEqual
(
os
.
getxattr
(
src
,
'user.the_value'
),
b
'fiddly'
)
@support.skip_unless_symlink
@support.skip_unless_symlink
@support.skip_unless_xattr
@support.skip_unless_xattr
@unittest.skipUnless
(
hasattr
(
os
,
'geteuid'
)
and
os
.
geteuid
()
==
0
,
@unittest.skipUnless
(
hasattr
(
os
,
'geteuid'
)
and
os
.
geteuid
()
==
0
,
...
...
Misc/NEWS
Dosyayı görüntüle @
ad5ae045
...
@@ -35,6 +35,8 @@ Core and Builtins
...
@@ -35,6 +35,8 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
15238
:
shutil
.
copystat
now
copies
Linux
"extended attributes"
.
-
Issue
#
15230
:
runpy
.
run_path
now
correctly
sets
__package__
as
described
-
Issue
#
15230
:
runpy
.
run_path
now
correctly
sets
__package__
as
described
in
the
documentation
in
the
documentation
...
...
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