From a2b4a1f35a417047bc33a17fccae928db02f3e17 Mon Sep 17 00:00:00 2001 From: Alexander Pyhalov Date: Tue, 10 Mar 2020 20:49:46 +0300 Subject: [PATCH] More fixes for UTF-8 characters in manifests files --- src/modules/client/image.py | 12 ++++++------ src/modules/client/transport/transport.py | 4 ++-- src/modules/manifest.py | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/modules/client/image.py b/src/modules/client/image.py index 9dcdf3485..181638240 100644 --- a/src/modules/client/image.py +++ b/src/modules/client/image.py @@ -3702,9 +3702,9 @@ def _create_fast_lookups(self, progtrack=None): of, op = self.temporary_file(close=False) bf, bp = self.temporary_file(close=False) - sf = os.fdopen(sf, "w") - of = os.fdopen(of, "w") - bf = os.fdopen(bf, "w") + sf = os.fdopen(sf, "w", encoding="UTF-8") + of = os.fdopen(of, "w", encoding="UTF-8") + bf = os.fdopen(bf, "w", encoding="UTF-8") # We need to make sure the files are coordinated. timestamp = int(time.time()) @@ -3837,7 +3837,7 @@ def _load_actdict(self, progtrack): try: of = open(os.path.join(self.__action_cache_dir, - "actions.offsets"), "r") + "actions.offsets"), "r", encoding="UTF-8") except IOError as e: if e.errno != errno.ENOENT: raise @@ -3902,7 +3902,7 @@ def _get_stripped_actions_file(self, internal=False): return the corresponding file object.""" sf = open(os.path.join(self.__action_cache_dir, - "actions.stripped"), "r") + "actions.stripped"), "r", encoding="UTF-8") sversion = sf.readline().rstrip() stimestamp = sf.readline().rstrip() if internal: @@ -3917,7 +3917,7 @@ def _load_conflicting_keys(self): pth = os.path.join(self.__action_cache_dir, "keys.conflicting") try: - with open(pth, "r") as fh: + with open(pth, "r", encoding="UTF-8") as fh: version = fh.readline().rstrip() if version != "VERSION 1": return None diff --git a/src/modules/client/transport/transport.py b/src/modules/client/transport/transport.py index 08890a5e5..f8246e10b 100644 --- a/src/modules/client/transport/transport.py +++ b/src/modules/client/transport/transport.py @@ -1686,7 +1686,7 @@ def _prefetch_manifests_list(self, mxfr, mlist, excludes=misc.EmptyI): continue try: - mf = open(dl_path) + mf = open(dl_path, "r", encoding="UTF-8") mcontent = mf.read() mf.close() manifest.FactoredManifest(fmri, @@ -1776,7 +1776,7 @@ def _verify_manifest(self, fmri, mfstpath=None, content=None, pub=None): return False if mfstpath: - mf = open(mfstpath) + mf = open(mfstpath, "r", encoding="UTF-8") mcontent = mf.read() mf.close() elif content is not None: diff --git a/src/modules/manifest.py b/src/modules/manifest.py index 979cc95dd..ef629c0a5 100644 --- a/src/modules/manifest.py +++ b/src/modules/manifest.py @@ -1229,7 +1229,7 @@ def search_dict(file_path, excludes, return_line=False, log = lambda x: None try: - file_handle = open(file_path, "r") + file_handle = open(file_path, "r", encoding="UTF-8") except EnvironmentError as e: if e.errno != errno.ENOENT: raise @@ -1364,7 +1364,7 @@ def store(self, mfst_path): e.filename) raise - mfile = os.fdopen(fd, "w") + mfile = os.fdopen(fd, "w", encoding="UTF-8") # # We specifically avoid sorting manifests before writing @@ -1668,7 +1668,7 @@ def __storebytype(self): except EnvironmentError as e: raise apx._convert_error(e) - f = os.fdopen(fd, "w") + f = os.fdopen(fd, "w", encoding="UTF-8") try: for a in acts: f.write("{0}\n".format(a)) @@ -1695,7 +1695,7 @@ def create_cache(name, refs): try: fd, fn = tempfile.mkstemp(dir=t_dir, prefix=name + ".") - with os.fdopen(fd, "w") as f: + with os.fdopen(fd, "w", encoding="UTF-8") as f: f.writelines(refs()) os.chmod(fn, PKG_FILE_MODE) portable.rename(fn, self.__cache_path(name)) @@ -1745,7 +1745,7 @@ def __load_cached_data(self, name): if os.path.exists(mpath): # we have cached copy on disk; use it try: - with open(mpath, "r") as f: + with open(mpath, "r", encoding="UTF-8") as f: self._cache[name] = [ a for a in ( @@ -1830,7 +1830,7 @@ def gen_actions_by_type(self, atype, attr_match=None, excludes=EmptyI): attr_match = _compile_fnpats(attr_match) try: - with open(mpath, "r") as f: + with open(mpath, "r", encoding="UTF-8") as f: for l in f: a = actions.fromstr(l.rstrip()) if (excludes and @@ -1889,7 +1889,7 @@ def __load_attributes(self): mpath = self.__cache_path("manifest.set") if not os.path.exists(mpath): return False - with open(mpath, "r") as f: + with open(mpath, "r", encoding="UTF-8") as f: for l in f: a = actions.fromstr(l.rstrip()) if not self.excludes or \