aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/portage/xpak.py')
-rw-r--r--lib/portage/xpak.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/portage/xpak.py b/lib/portage/xpak.py
index b20429b6f..94a07a84c 100644
--- a/lib/portage/xpak.py
+++ b/lib/portage/xpak.py
@@ -43,6 +43,8 @@ from portage import normalize_path
from portage import _encodings
from portage import _unicode_decode
from portage import _unicode_encode
+from portage.binpkg import get_binpkg_format
+from portage.exception import InvalidBinaryPackageFormat
from portage.util.file_copy import copyfile
@@ -53,7 +55,6 @@ def addtolist(mylist, curdir):
_unicode_decode(curdir, encoding=_encodings["fs"], errors="strict")
)
for parent, dirs, files in os.walk(curdir):
-
parent = _unicode_decode(parent, encoding=_encodings["fs"], errors="strict")
if parent != curdir:
mylist.append(parent[len(curdir) + 1 :] + os.sep)
@@ -103,6 +104,11 @@ def xpak(rootdir, outfile=None):
and under the name 'outfile' if it is specified. Otherwise it returns the
xpak segment."""
+ if portage.utf8_mode and not isinstance(rootdir, bytes):
+ # Since paths are encoded below, rootdir must also be encoded
+ # when _unicode_func_wrapper is not used.
+ rootdir = os.fsencode(rootdir)
+
mylist = []
addtolist(mylist, rootdir)
@@ -171,7 +177,7 @@ def xpak_mem(mydata):
def xsplit(infile):
"""(infile) -- Splits the infile into two files.
'infile.index' contains the index segment.
- 'infile.dat' contails the data segment."""
+ 'infile.dat' contains the data segment."""
infile = _unicode_decode(infile, encoding=_encodings["fs"], errors="strict")
myfile = open(
_unicode_encode(infile, encoding=_encodings["fs"], errors="strict"), "rb"
@@ -340,7 +346,7 @@ class tbz2:
the directory provided. Raises IOError if scan() fails.
Returns result of upackinfo()."""
if not self.scan():
- raise IOError
+ raise OSError
if cleanup:
self.cleanup(datadir)
if not os.path.exists(datadir):
@@ -388,7 +394,7 @@ class tbz2:
"ab+",
)
if not myfile:
- raise IOError
+ raise OSError
myfile.seek(-self.xpaksize, 2) # 0,2 or -0,2 just mean EOF.
myfile.truncate()
myfile.write(xpdata + encodeint(len(xpdata)) + b"STOP")
@@ -435,14 +441,26 @@ class tbz2:
self.infosize = 0
self.xpaksize = 0
if trailer[-4:] != b"STOP":
+ try:
+ get_binpkg_format(self.file, check_file=True)
+ except InvalidBinaryPackageFormat:
+ pass
return 0
if trailer[0:8] != b"XPAKSTOP":
+ try:
+ get_binpkg_format(self.file, check_file=True)
+ except InvalidBinaryPackageFormat:
+ pass
return 0
self.infosize = decodeint(trailer[8:12])
self.xpaksize = self.infosize + 8
a.seek(-(self.xpaksize), 2)
header = a.read(16)
if header[0:8] != b"XPAKPACK":
+ try:
+ get_binpkg_format(self.file, check_file=True)
+ except InvalidBinaryPackageFormat:
+ pass
return 0
self.indexsize = decodeint(header[8:12])
self.datasize = decodeint(header[12:16])
@@ -453,6 +471,10 @@ class tbz2:
except SystemExit:
raise
except:
+ try:
+ get_binpkg_format(self.file, check_file=True)
+ except InvalidBinaryPackageFormat:
+ pass
return 0
finally:
if a is not None: