1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-01-03 05:35:58 +00:00

Various changes

This commit is contained in:
Jonas Borgström 2010-10-31 21:55:09 +01:00
parent 1a1d8f87eb
commit 869f720be4
5 changed files with 27 additions and 21 deletions

1
.gitignore vendored
View file

@ -2,4 +2,5 @@ build
*.egg-info *.egg-info
*.pyc *.pyc
*.pyo *.pyo
*.so

View file

@ -145,10 +145,11 @@ def extract_item(self, item, dest=None):
raise Exception('Unknown archive item type %r' % item['mode']) raise Exception('Unknown archive item type %r' % item['mode'])
def restore_attrs(self, path, item, symlink=False): def restore_attrs(self, path, item, symlink=False):
if item['xattrs']: xattrs = item.get('xattrs')
if xattrs:
try: try:
xa = xattr(path, XATTR_NOFOLLOW) xa = xattr(path, XATTR_NOFOLLOW)
for k, v in item['xattrs'].items(): for k, v in xattrs.items():
xa.set(k, v) xa.set(k, v)
except IOError: except IOError:
pass pass
@ -188,17 +189,17 @@ def delete(self, cache):
cache.save() cache.save()
def stat_attrs(self, st, path): def stat_attrs(self, st, path):
try: item = {
xattrs = dict(xattr(path, XATTR_NOFOLLOW))
except IOError:
xattrs = None
return {
'mode': st.st_mode, 'mode': st.st_mode,
'uid': st.st_uid, 'user': uid2user(st.st_uid), 'uid': st.st_uid, 'user': uid2user(st.st_uid),
'gid': st.st_gid, 'group': gid2group(st.st_gid), 'gid': st.st_gid, 'group': gid2group(st.st_gid),
'atime': st.st_atime, 'mtime': st.st_mtime, 'atime': st.st_atime, 'mtime': st.st_mtime,
'xattrs': xattrs,
} }
try:
item['xattrs'] = dict(xattr(path, XATTR_NOFOLLOW))
except IOError:
pass
return item
def process_dir(self, path, st): def process_dir(self, path, st):
item = {'path': path.lstrip('/\\:')} item = {'path': path.lstrip('/\\:')}

View file

@ -150,11 +150,13 @@ def do_info(self, args):
print 'Unique data:', format_file_size(usize) print 'Unique data:', format_file_size(usize)
return self.exit_code return self.exit_code
def do_keychain_generate(self, args): def do_init_keychain(self, args):
return KeyChain.generate(args.keychain) return KeyChain.generate(args.keychain)
def do_keychain_restrict(self, args): def do_export_restricted(self, args):
return KeyChain(args.keychain).restrict(args.output) keychain = KeyChain(args.keychain)
keychain.restrict(args.output)
return self.exit_code
def do_keychain_chpass(self, args): def do_keychain_chpass(self, args):
return KeyChain(args.keychain).chpass() return KeyChain(args.keychain).chpass()
@ -172,15 +174,13 @@ def run(self, args=None):
subparsers = parser.add_subparsers(title='Available subcommands') subparsers = parser.add_subparsers(title='Available subcommands')
subparser = subparsers.add_parser('keychain') subparser = subparsers.add_parser('init-keychain')
subsubparsers = subparser.add_subparsers(title='Available subcommands') subparser.set_defaults(func=self.do_init_keychain)
subparser = subsubparsers.add_parser('generate') subparser = subparsers.add_parser('export-restricted')
subparser.set_defaults(func=self.do_keychain_generate)
subparser = subsubparsers.add_parser('restrict')
subparser.add_argument('output', metavar='OUTPUT', type=str, subparser.add_argument('output', metavar='OUTPUT', type=str,
help='Keychain to create') help='Keychain to create')
subparser.set_defaults(func=self.do_keychain_restrict) subparser.set_defaults(func=self.do_export_restricted)
subparser = subsubparsers.add_parser('change-password') subparser = subparsers.add_parser('change-password')
subparser.set_defaults(func=self.do_keychain_chpass) subparser.set_defaults(func=self.do_keychain_chpass)
subparser = subparsers.add_parser('init') subparser = subparsers.add_parser('init')

View file

@ -30,6 +30,7 @@ def open(self, path):
if fd.read(len(self.FILE_ID)) != self.FILE_ID: if fd.read(len(self.FILE_ID)) != self.FILE_ID:
raise ValueError('Not a keychain') raise ValueError('Not a keychain')
cdata = fd.read() cdata = fd.read()
self.password = ''
data = self.decrypt(cdata, '') data = self.decrypt(cdata, '')
while not data: while not data:
self.password = getpass('Keychain password: ') self.password = getpass('Keychain password: ')

View file

@ -1,6 +1,5 @@
import filecmp import filecmp
import os import os
import time
from StringIO import StringIO from StringIO import StringIO
import sys import sys
import shutil import shutil
@ -25,7 +24,7 @@ def setUp(self):
os.chdir(self.tmpdir) os.chdir(self.tmpdir)
self.keychain = '/tmp/_test_dedupstore.keychain' self.keychain = '/tmp/_test_dedupstore.keychain'
if not os.path.exists(self.keychain): if not os.path.exists(self.keychain):
self.darc('keychain', 'generate') self.darc('init-keychain')
self.darc('init', self.store_path) self.darc('init', self.store_path)
def tearDown(self): def tearDown(self):
@ -92,7 +91,6 @@ def test_basic_functionality(self):
os.symlink('somewhere', os.path.join(self.input_path, 'link1')) os.symlink('somewhere', os.path.join(self.input_path, 'link1'))
os.mkfifo(os.path.join(self.input_path, 'fifo1')) os.mkfifo(os.path.join(self.input_path, 'fifo1'))
self.darc('create', self.store_path + '::test', 'input') self.darc('create', self.store_path + '::test', 'input')
time.sleep(1)
self.darc('extract', self.store_path + '::test', 'output') self.darc('extract', self.store_path + '::test', 'output')
self.diff_dirs('input', 'output/input') self.diff_dirs('input', 'output/input')
@ -105,6 +103,11 @@ def test_corrupted_store(self):
fd.close() fd.close()
self.darc('verify', self.store_path + '::test', exit_code=1) self.darc('verify', self.store_path + '::test', exit_code=1)
def test_keychain(self):
keychain = os.path.join(self.tmpdir, 'keychain')
self.darc('-k', keychain, 'init-keychain')
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(Test)) suite.addTest(unittest.TestLoader().loadTestsFromTestCase(Test))