Commit 001ed5c5 authored by Leo Le Bouter's avatar Leo Le Bouter

xattrs dict must be created first, decode xattrs as utf-8

In Python, the JSON encoder cannot process bytes, the JSON
specification also does not define a "bytes" type. We are
constrained by this in that we cannot serialize data of bytes type.

xattrs can be either strings or bytes, in practice they're likely
representable as strings, therefore, decode as utf-8, error
otherwise. If real world situation of xattrs in true binary format
arise then we will rule out another solution.
parent 562b18bc
......@@ -64,25 +64,28 @@ def construct_fs_tree(mp_pool=None, mp_tasks=[], cur_dict=None, path="/", dev_wh
try:
entry_stat = os.stat(entry_path, follow_symlinks=False)
except:
except Exception:
traceback.print_exc()
entry_stat = None
cur_dict["childs"][entry_name] = {"stat": entry_stat,
"childs": dict()}
try:
cur_dict["childs"][entry_name]["xattrs"] = dict()
for k in os.listxattr(entry_path, follow_symlinks=False):
cur_dict["childs"][entry_name]["xattrs"][k] = str(os.getxattr(
entry_path, k))
except:
pass
cur_dict["childs"][entry_name]["xattrs"][k] = codecs.decode(
os.getxattr(entry_path, k), "utf-8")
except Exception:
traceback.print_exc()
try:
cur_dict["childs"][entry_name]["posix_acls"] = codecs.decode(posix1e.ACL(file=entry_path)
.to_any_text(options=posix1e.TEXT_ALL_EFFECTIVE),
"utf-8")
except:
pass
except Exception:
traceback.print_exc()
if stat.S_ISDIR(entry_stat.st_mode):
construct_fs_tree(mp_pool=mp_pool, mp_tasks=mp_tasks, cur_dict=cur_dict["childs"][entry_name],
......
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