"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Tardis/Regenerate.py" between
Tardis-1.1.5.tar.gz and Tardis-1.2.1.tar.gz

About: Tardis is a system for making encrypted, incremental backups of filesystems.

Regenerate.py  (Tardis-1.1.5):Regenerate.py  (Tardis-1.2.1)
skipping to change at line 45 skipping to change at line 45
import argparse import argparse
import logging import logging
import time import time
import base64 import base64
import json import json
import parsedatetime import parsedatetime
import xattr import xattr
import hmac import hmac
import posix1e import posix1e
import queue
import threading
import Tardis import Tardis
from Tardis import TardisDB from Tardis import TardisDB
from Tardis import Regenerator from Tardis import Regenerator
from Tardis import Util from Tardis import Util
from Tardis import Config from Tardis import Config
from Tardis import Defaults from Tardis import Defaults
logger = None logger = None
crypt = None crypt = None
skipping to change at line 140 skipping to change at line 143
return target return target
else: else:
return outname return outname
def notSame(a, b, string): def notSame(a, b, string):
if a == b: if a == b:
return '' return ''
else: else:
return string return string
def setAttributes(regenerator, info, outname):
if outname:
if args.setperm:
try:
logger.debug("Setting permissions on %s to %o", outname, info['m
ode'])
os.chmod(outname, info['mode'])
except Exception as e:
logger.warning("Unable to set permissions for %s", outname)
try:
# Change the group, then the owner.
# Change the group first, as only root can change owner, and tha
t might fail.
os.chown(outname, -1, info['gid'])
os.chown(outname, info['uid'], -1)
except Exception as e:
logger.warning("Unable to set owner and group of %s", outname)
if args.settime:
try:
logger.debug("Setting times on %s to %d %d", outname, info['atim
e'], info['mtime'])
os.utime(outname, (info['atime'], info['mtime']))
except Exception as e:
logger.warning("Unable to set times on %s", outname)
if args.setattrs and 'attr' in info and info['attr']:
try:
f = regenerator.recoverChecksum(info['attr'], authenticate)
xattrs = json.loads(f.read())
x = xattr.xattr(outname)
for attr in xattrs.keys():
value = base64.b64decode(xattrs[attr])
try:
x.set(attr, value)
except IOError:
logger.warning("Unable to set extended attribute %s on %
s", attr, outname)
except Exception as e:
logger.warning("Unable to process extended attributes for %s", o
utname)
if args.setacl and 'acl' in info and info['acl']:
try:
f = regenerator.recoverChecksum(info['acl'], authenticate)
acl = json.loads(f.read())
a = posix1e.ACL(text=acl)
a.applyto(outname)
except Exception as e:
logger.warning("Unable to process extended attributes for %s", o
utname)
def doRecovery(regenerator, info, authenticate, path, outname):
myname = outname if outname else "stdout"
logger.info("Recovering file %s %s", Util.shortPath(path), notSame(path, myn
ame, " => " + Util.shortPath(myname)))
checksum = info['checksum']
i = regenerator.recoverChecksum(checksum, authenticate)
if i:
if authenticate:
hasher = crypt.getHash()
if info['link']:
# read and make a link
i.seek(0)
x = i.read(16 * 1024)
if outname:
os.symlink(x, outname)
else:
logger.warning("No name specified for link: %s", x)
if hasher:
hasher.update(x)
else:
if outname:
# Generate an output name
logger.debug("Writing output to %s", outname)
output = open(outname, "wb")
else:
output = sys.stdout.buffer
try:
x = i.read(16 * 1024)
while x:
output.write(x)
if hasher:
hasher.update(x)
x = i.read(16 * 1024)
except Exception as e:
logger.error("Unable to read file: {}: {}".format(i, repr(e)))
raise
finally:
i.close()
if output is not sys.stdout.buffer:
output.close()
if authenticate:
outname = doAuthenticate(outname, checksum, hasher.hexdigest())
setAttributes(regenerator, info, outname)
def recoverObject(regenerator, info, bset, outputdir, path, linkDB, name=None, a uthenticate=True): def recoverObject(regenerator, info, bset, outputdir, path, linkDB, name=None, a uthenticate=True):
""" """
Main recovery routine. Recover an object, based on the info object, and put it in outputdir. Main recovery routine. Recover an object, based on the info object, and put it in outputdir.
""" """
retCode = 0 retCode = 0
outname = None outname = None
skip = False skip = False
hasher = None hasher = None
try: try:
if info: if info:
skipping to change at line 192 skipping to change at line 287
logger.info("Processing directory %s", Util.shortPath(path)) logger.info("Processing directory %s", Util.shortPath(path))
except Exception: except Exception:
pass pass
contents = list(tardis.readDirectory((info['inode'], info['devic e']), bset)) contents = list(tardis.readDirectory((info['inode'], info['devic e']), bset))
# Make sure an output directory is specified (really only useful at the top level) # Make sure an output directory is specified (really only useful at the top level)
if not os.path.exists(outname): if not os.path.exists(outname):
os.mkdir(outname) os.mkdir(outname)
setAttributes(regenerator, info, outname)
dirInode = (info['inode'], info['device']) dirInode = (info['inode'], info['device'])
# For each file in the directory, regenerate it. # For each file in the directory, regenerate it.
for i in contents: for i in contents:
name = crypt.decryptFilename(i['name']) name = crypt.decryptFilename(i['name'])
logger.debug("Processing file %s", name) logger.debug("Processing file %s", name)
# Get the Info # Get the Info
childInfo = tardis.getFileInfoByName(i['name'], dirInode, bs et) childInfo = tardis.getFileInfoByName(i['name'], dirInode, bs et)
logger.debug("Info on %s: %s", name, childInfo) logger.debug("Info on %s: %s", name, childInfo)
# Recurse into the child, if it exists. # Recurse into the child, if it exists.
skipping to change at line 214 skipping to change at line 311
if args.recurse or not childInfo['dir']: if args.recurse or not childInfo['dir']:
recoverObject(regenerator, childInfo, bset, outn ame, os.path.join(path, name), linkDB, authenticate=authenticate) recoverObject(regenerator, childInfo, bset, outn ame, os.path.join(path, name), linkDB, authenticate=authenticate)
except Exception as e: except Exception as e:
logger.error("Could not recover %s in %s", name, pat h) logger.error("Could not recover %s in %s", name, pat h)
if args.exceptions: if args.exceptions:
logger.exception(e) logger.exception(e)
else: else:
logger.warning("No info on %s", name) logger.warning("No info on %s", name)
retCode += 1 retCode += 1
elif not skip: elif not skip:
myname = outname if outname else "stdout" doRecovery(regenerator, info, authenticate, path, outname)
logger.info("Recovering file %s %s", Util.shortPath(path), notSa
me(path, myname, " => " + Util.shortPath(myname)))
checksum = info['checksum']
i = regenerator.recoverChecksum(checksum, authenticate)
if i:
if authenticate:
hasher = crypt.getHash()
if info['link']:
# read and make a link
i.seek(0)
x = i.read(16 * 1024)
if outname:
os.symlink(x, outname)
else:
logger.warning("No name specified for link: %s", x)
if hasher:
hasher.update(x)
else:
if outname:
# Generate an output name
logger.debug("Writing output to %s", outname)
output = open(outname, "wb")
else:
output = sys.stdout.buffer
try:
x = i.read(16 * 1024)
while x:
output.write(x)
if hasher:
hasher.update(x)
x = i.read(16 * 1024)
except Exception as e:
logger.error("Unable to read file: {}: {}".format(i,
repr(e)))
raise
finally:
i.close()
if output is not sys.stdout.buffer:
output.close()
if authenticate:
outname = doAuthenticate(outname, checksum, hasher.h
exdigest())
if outname and not skip:
if args.setperm:
try:
logger.debug("Setting permissions on %s to %o", outname,
info['mode'])
os.chmod(outname, info['mode'])
except Exception as e:
logger.warning("Unable to set permissions for %s", outna
me)
try:
# Change the group, then the owner.
# Change the group first, as only root can change owner,
and that might fail.
os.chown(outname, -1, info['gid'])
os.chown(outname, info['uid'], -1)
except Exception as e:
logger.warning("Unable to set owner and group of %s", ou
tname)
if args.settime:
try:
logger.debug("Setting times on %s to %d %d", outname, in
fo['atime'], info['mtime'])
os.utime(outname, (info['atime'], info['mtime']))
except Exception as e:
logger.warning("Unable to set times on %s", outname)
if args.setattrs and 'attr' in info and info['attr']:
try:
f = regenerator.recoverChecksum(info['attr'], authentica
te)
xattrs = json.loads(f.read())
x = xattr.xattr(outname)
for attr in xattrs.keys():
value = base64.b64decode(xattrs[attr])
try:
x.set(attr, value)
except IOError:
logger.warning("Unable to set extended attribute
%s on %s", attr, outname)
except Exception as e:
logger.warning("Unable to process extended attributes fo
r %s", outname)
if args.setacl and 'acl' in info and info['acl']:
try:
f = regenerator.recoverChecksum(info['acl'], authenticat
e)
acl = json.loads(f.read())
a = posix1e.ACL(text=acl)
a.applyto(outname)
except Exception as e:
logger.warning("Unable to process extended attributes fo
r %s", outname)
except Exception as e: except Exception as e:
logger.error("Recovery of %s failed. %s", outname, e) logger.error("Recovery of %s failed. %s", outname, e)
if args.exceptions: if args.exceptions:
logger.exception(e) logger.exception(e)
retCode += 1 retCode += 1
return retCode return retCode
def setupPermissionChecks(): def setupPermissionChecks():
uid = os.getuid() uid = os.getuid()
 End of changes. 5 change blocks. 
99 lines changed or deleted 105 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)