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
40d9304d
Kaydet (Commit)
40d9304d
authored
Eki 21, 1990
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use 'stat' module instead of hardcoding information from <sys/stat.h>.
üst
6b47ed1f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
36 deletions
+17
-36
cmpcache.py
Lib/cmpcache.py
+3
-9
dircmp.py
Lib/dircmp.py
+5
-15
posixpath.py
Lib/posixpath.py
+3
-2
statcache.py
Lib/statcache.py
+6
-10
No files found.
Lib/cmpcache.py
Dosyayı görüntüle @
40d9304d
...
...
@@ -8,10 +8,9 @@
# - Files with different type or size cannot be identical
# - We keep a cache of outcomes of earlier comparisons
# - We don't fork a process to run 'cmp' but read the files ourselves
#
# XXX There is a dependency on constants in <sys/stat.h> here.
import
posix
import
stat
import
statcache
...
...
@@ -27,7 +26,7 @@ def cmp(f1, f2):
# Return 1 for identical files, 0 for different.
# Raise exceptions if either file could not be statted, read, etc.
s1
,
s2
=
sig
(
statcache
.
stat
(
f1
)),
sig
(
statcache
.
stat
(
f2
))
if
s1
[
0
]
<>
8
or
s2
[
0
]
<>
8
:
# XXX 8 is S_IFREG in <sys/stat.h>
if
not
stat
.
S_ISREG
(
s1
[
0
])
or
not
stat
.
S_ISREG
(
s2
[
0
]):
# Either is a not a plain file -- always report as different
return
0
if
s1
=
s2
:
...
...
@@ -53,12 +52,7 @@ def cmp(f1, f2):
# Return signature (i.e., type, size, mtime) from raw stat data.
#
def
sig
(
st
):
# 0-5: st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid
# 6-9: st_size, st_atime, st_mtime, st_ctime
type
=
st
[
0
]
/
4096
# XXX dependent on S_IFMT in <sys/stat.h>
size
=
st
[
6
]
mtime
=
st
[
8
]
return
type
,
size
,
mtime
return
stat
.
S_IFMT
(
st
[
ST_MODE
]),
st
[
stat
.
ST_SIZE
],
st
[
stat
.
ST_MTIME
]
# Compare two files, really.
#
...
...
Lib/dircmp.py
Dosyayı görüntüle @
40d9304d
...
...
@@ -9,17 +9,7 @@ import path
import
dircache
import
cmpcache
import
statcache
# File type constants from <sys/stat.h>.
#
S_IFDIR
=
4
S_IFREG
=
8
# Extract the file type from a stat buffer.
#
def
S_IFMT
(
st
):
return
st
[
0
]
/
4096
from
stat
import
*
# Directory comparison class.
#
...
...
@@ -79,13 +69,13 @@ class dircmp():
ok
=
0
#
if
ok
:
a_type
=
S_IFMT
(
a_stat
)
b_type
=
S_IFMT
(
b_stat
)
a_type
=
S_IFMT
(
a_stat
[
ST_MODE
]
)
b_type
=
S_IFMT
(
b_stat
[
ST_MODE
]
)
if
a_type
<>
b_type
:
dd
.
common_funny
.
append
(
x
)
elif
a_type
=
S_IFDIR
:
elif
S_ISDIR
(
a_type
)
:
dd
.
common_dirs
.
append
(
x
)
elif
a_type
=
S_IFREG
:
elif
S_ISREG
(
a_type
)
:
dd
.
common_files
.
append
(
x
)
else
:
dd
.
common_funny
.
append
(
x
)
...
...
Lib/posixpath.py
Dosyayı görüntüle @
40d9304d
# Module 'path' -- common operations on POSIX pathnames
import
posix
import
stat
# Intelligent pathname concatenation.
...
...
@@ -63,7 +64,7 @@ def isdir(path):
st
=
posix
.
stat
(
path
)
except
posix
.
error
:
return
0
return
st
[
0
]
/
4096
=
4
# S_IFDIR
return
st
at
.
S_ISDIR
(
st
[
stat
.
ST_MODE
])
# Is a path a symbolic link?
...
...
@@ -74,7 +75,7 @@ def islink(path):
st
=
posix
.
lstat
(
path
)
except
(
posix
.
error
,
NameError
):
return
0
return
st
[
0
]
/
4096
=
10
# S_IFLNK
return
st
at
.
S_ISLNK
(
st
[
stat
.
ST_MODE
])
_mounts
=
[]
...
...
Lib/statcache.py
Dosyayı görüntüle @
40d9304d
...
...
@@ -4,7 +4,7 @@
# There are functions to reset the cache or to selectively remove items.
import
posix
from
stat
import
*
# The cache.
# Keys are pathnames, values are `posix.stat' outcomes.
...
...
@@ -15,10 +15,8 @@ cache = {}
# Stat a file, possibly out of the cache.
#
def
stat
(
path
):
try
:
if
cache
.
has_key
(
path
)
:
return
cache
[
path
]
except
RuntimeError
:
pass
cache
[
path
]
=
ret
=
posix
.
stat
(
path
)
return
ret
...
...
@@ -37,10 +35,8 @@ def reset():
# Remove a given item from the cache, if it exists.
#
def
forget
(
path
):
try
:
if
cache
.
has_key
(
path
)
:
del
cache
[
path
]
except
RuntimeError
:
pass
# Remove all pathnames with a given prefix.
...
...
@@ -84,7 +80,7 @@ def forget_except_prefix(prefix):
#
def
isdir
(
path
):
try
:
# mode is st[0]; type is mode/4096; S_IFDIR is 4
return
stat
(
path
)[
0
]
/
4096
=
4
except
RuntimeError
:
st
=
stat
(
path
)
except
posix
.
error
:
return
0
return
S_ISDIR
(
st
[
ST_MODE
])
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