Kaydet (Commit) 8bc462fc authored tarafından Andrew M. Kuchling's avatar Andrew M. Kuchling

[Patch #1043972, for bug #1017553] filemode() returns an incorrect value for the mode 07111

üst d4f2552e
...@@ -174,39 +174,46 @@ def copyfileobj(src, dst, length=None): ...@@ -174,39 +174,46 @@ def copyfileobj(src, dst, length=None):
return return
filemode_table = ( filemode_table = (
(S_IFLNK, "l", ((S_IFLNK, "l"),
S_IFREG, "-", (S_IFREG, "-"),
S_IFBLK, "b", (S_IFBLK, "b"),
S_IFDIR, "d", (S_IFDIR, "d"),
S_IFCHR, "c", (S_IFCHR, "c"),
S_IFIFO, "p"), (S_IFIFO, "p")),
(TUREAD, "r"),
(TUWRITE, "w"), ((TUREAD, "r"),),
(TUEXEC, "x", TSUID, "S", TUEXEC|TSUID, "s"), ((TUWRITE, "w"),),
(TGREAD, "r"), ((TUEXEC|TSUID, "s"),
(TGWRITE, "w"), (TSUID, "S"),
(TGEXEC, "x", TSGID, "S", TGEXEC|TSGID, "s"), (TUEXEC, "x")),
(TOREAD, "r"),
(TOWRITE, "w"), ((TGREAD, "r"),),
(TOEXEC, "x", TSVTX, "T", TOEXEC|TSVTX, "t")) ((TGWRITE, "w"),),
((TGEXEC|TSGID, "s"),
(TSGID, "S"),
(TGEXEC, "x")),
((TOREAD, "r"),),
((TOWRITE, "w"),),
((TOEXEC|TSVTX, "t"),
(TSVTX, "T"),
(TOEXEC, "x"))
)
def filemode(mode): def filemode(mode):
"""Convert a file's mode to a string of the form """Convert a file's mode to a string of the form
-rwxrwxrwx. -rwxrwxrwx.
Used by TarFile.list() Used by TarFile.list()
""" """
s = "" perm = []
for t in filemode_table: for table in filemode_table:
while True: for bit, char in table:
if mode & t[0] == t[0]: if mode & bit == bit:
s += t[1] perm.append(char)
elif len(t) > 2: break
t = t[2:] else:
continue perm.append("-")
else: return "".join(perm)
s += "-"
break
return s
if os.sep != "/": if os.sep != "/":
normpath = lambda path: os.path.normpath(path).replace(os.sep, "/") normpath = lambda path: os.path.normpath(path).replace(os.sep, "/")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment