From: Philipp Gesang Date: Thu, 24 Aug 2017 11:21:30 +0000 (+0200) Subject: convert TarInfo to index format X-Git-Tag: v2.2~7^2~52 X-Git-Url: http://developer.intra2net.com/git/?p=python-delta-tar;a=commitdiff_plain;h=2d50b7f7f80dea94f3922c6906b7a6c453a0a8d2 convert TarInfo to index format --- diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 4f9e033..cd77208 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -3333,6 +3333,43 @@ def read_tarobj_at_offset (fileobj, offset, mode, secret=None): return tarobj.next () +def idxent_of_tarinfo (tarinfo): + """ + Scrape the information relevant for the index from a *TarInfo* object. + Keys like the inode number that lack a corresponding field in a TarInfo + will be set to some neutral value. + Example output: + + { "inode" : 0 + , "uid" : 0 + , "path" : "snapshot://annotations.db" + , "offset" : 0 + , "volume" : 0 + , "mode" : 33152 + , "ctime" : 1502798115 + , "mtime" : 1502196423 + , "size" : 144 + , "type" : "file" + , "gid" : 0 + } + + """ + + return \ + { "inode" : 0 # ignored when reading the index + , "uid" : tarinfo.uid + , "gid" : tarinfo.gid + , "path" : tarinfo.name # keeping URI scheme + , "offset" : 0 # to be added by the caller + , "volume" : tarinfo.volume_offset + , "mode" : tarinfo.mode + , "ctime" : tarinfo.mtime + , "mtime" : tarinfo.mtime + , "size" : tarinfo.size + , "type" : tarinfo.type + } + + def gen_rescue_index (backup_tar_path, mode, password=None, key=None): psidx = [] # pseudo index, return value offsets = None @@ -3347,8 +3384,13 @@ def gen_rescue_index (backup_tar_path, mode, password=None, key=None): if secret is not None: offsets = crypto.reconstruct_offsets (backup_tar_path, secret) fileobj = bltn_open (backup_tar_path, "rb") - psinfos = [ read_tarobj_at_offset (fileobj, off, mode, secret=secret) + infos = [ (off, read_tarobj_at_offset (fileobj, off, mode, secret=secret)) for off in offsets ] + def aux (o, ti): + ie = idxent_of_tarinfo (ti) + ie ["offset"] = o + return ie + psidx = [ aux (o, ti) for o, ti in infos ] return psidx