summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2004-10-20 11:48:42 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2004-10-20 11:48:42 (GMT)
commit8bc462fcafe9f11094f0185813f95c0f569b112e (patch)
tree0bd2b911dd798fe396ddf9f8ad6531cd744bcd00 /Lib/tarfile.py
parentd4f2552ef87b4298486aafc529dff7c5b64916b3 (diff)
downloadcpython-8bc462fcafe9f11094f0185813f95c0f569b112e.zip
cpython-8bc462fcafe9f11094f0185813f95c0f569b112e.tar.gz
cpython-8bc462fcafe9f11094f0185813f95c0f569b112e.tar.bz2
[Patch #1043972, for bug #1017553] filemode() returns an incorrect value for the mode 07111
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py61
1 files changed, 34 insertions, 27 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 1396967..b85f117 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -174,39 +174,46 @@ def copyfileobj(src, dst, length=None):
return
filemode_table = (
- (S_IFLNK, "l",
- S_IFREG, "-",
- S_IFBLK, "b",
- S_IFDIR, "d",
- S_IFCHR, "c",
- S_IFIFO, "p"),
- (TUREAD, "r"),
- (TUWRITE, "w"),
- (TUEXEC, "x", TSUID, "S", TUEXEC|TSUID, "s"),
- (TGREAD, "r"),
- (TGWRITE, "w"),
- (TGEXEC, "x", TSGID, "S", TGEXEC|TSGID, "s"),
- (TOREAD, "r"),
- (TOWRITE, "w"),
- (TOEXEC, "x", TSVTX, "T", TOEXEC|TSVTX, "t"))
+ ((S_IFLNK, "l"),
+ (S_IFREG, "-"),
+ (S_IFBLK, "b"),
+ (S_IFDIR, "d"),
+ (S_IFCHR, "c"),
+ (S_IFIFO, "p")),
+
+ ((TUREAD, "r"),),
+ ((TUWRITE, "w"),),
+ ((TUEXEC|TSUID, "s"),
+ (TSUID, "S"),
+ (TUEXEC, "x")),
+
+ ((TGREAD, "r"),),
+ ((TGWRITE, "w"),),
+ ((TGEXEC|TSGID, "s"),
+ (TSGID, "S"),
+ (TGEXEC, "x")),
+
+ ((TOREAD, "r"),),
+ ((TOWRITE, "w"),),
+ ((TOEXEC|TSVTX, "t"),
+ (TSVTX, "T"),
+ (TOEXEC, "x"))
+)
def filemode(mode):
"""Convert a file's mode to a string of the form
-rwxrwxrwx.
Used by TarFile.list()
"""
- s = ""
- for t in filemode_table:
- while True:
- if mode & t[0] == t[0]:
- s += t[1]
- elif len(t) > 2:
- t = t[2:]
- continue
- else:
- s += "-"
- break
- return s
+ perm = []
+ for table in filemode_table:
+ for bit, char in table:
+ if mode & bit == bit:
+ perm.append(char)
+ break
+ else:
+ perm.append("-")
+ return "".join(perm)
if os.sep != "/":
normpath = lambda path: os.path.normpath(path).replace(os.sep, "/")