mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-03 05:35:58 +00:00
Various changes
This commit is contained in:
parent
1a1d8f87eb
commit
869f720be4
5 changed files with 27 additions and 21 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,4 +2,5 @@ build
|
|||
*.egg-info
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.so
|
||||
|
||||
|
|
|
@ -145,10 +145,11 @@ def extract_item(self, item, dest=None):
|
|||
raise Exception('Unknown archive item type %r' % item['mode'])
|
||||
|
||||
def restore_attrs(self, path, item, symlink=False):
|
||||
if item['xattrs']:
|
||||
xattrs = item.get('xattrs')
|
||||
if xattrs:
|
||||
try:
|
||||
xa = xattr(path, XATTR_NOFOLLOW)
|
||||
for k, v in item['xattrs'].items():
|
||||
for k, v in xattrs.items():
|
||||
xa.set(k, v)
|
||||
except IOError:
|
||||
pass
|
||||
|
@ -188,17 +189,17 @@ def delete(self, cache):
|
|||
cache.save()
|
||||
|
||||
def stat_attrs(self, st, path):
|
||||
try:
|
||||
xattrs = dict(xattr(path, XATTR_NOFOLLOW))
|
||||
except IOError:
|
||||
xattrs = None
|
||||
return {
|
||||
item = {
|
||||
'mode': st.st_mode,
|
||||
'uid': st.st_uid, 'user': uid2user(st.st_uid),
|
||||
'gid': st.st_gid, 'group': gid2group(st.st_gid),
|
||||
'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):
|
||||
item = {'path': path.lstrip('/\\:')}
|
||||
|
|
|
@ -150,11 +150,13 @@ def do_info(self, args):
|
|||
print 'Unique data:', format_file_size(usize)
|
||||
return self.exit_code
|
||||
|
||||
def do_keychain_generate(self, args):
|
||||
def do_init_keychain(self, args):
|
||||
return KeyChain.generate(args.keychain)
|
||||
|
||||
def do_keychain_restrict(self, args):
|
||||
return KeyChain(args.keychain).restrict(args.output)
|
||||
def do_export_restricted(self, args):
|
||||
keychain = KeyChain(args.keychain)
|
||||
keychain.restrict(args.output)
|
||||
return self.exit_code
|
||||
|
||||
def do_keychain_chpass(self, args):
|
||||
return KeyChain(args.keychain).chpass()
|
||||
|
@ -172,15 +174,13 @@ def run(self, args=None):
|
|||
|
||||
|
||||
subparsers = parser.add_subparsers(title='Available subcommands')
|
||||
subparser = subparsers.add_parser('keychain')
|
||||
subsubparsers = subparser.add_subparsers(title='Available subcommands')
|
||||
subparser = subsubparsers.add_parser('generate')
|
||||
subparser.set_defaults(func=self.do_keychain_generate)
|
||||
subparser = subsubparsers.add_parser('restrict')
|
||||
subparser = subparsers.add_parser('init-keychain')
|
||||
subparser.set_defaults(func=self.do_init_keychain)
|
||||
subparser = subparsers.add_parser('export-restricted')
|
||||
subparser.add_argument('output', metavar='OUTPUT', type=str,
|
||||
help='Keychain to create')
|
||||
subparser.set_defaults(func=self.do_keychain_restrict)
|
||||
subparser = subsubparsers.add_parser('change-password')
|
||||
subparser.set_defaults(func=self.do_export_restricted)
|
||||
subparser = subparsers.add_parser('change-password')
|
||||
subparser.set_defaults(func=self.do_keychain_chpass)
|
||||
|
||||
subparser = subparsers.add_parser('init')
|
||||
|
|
|
@ -30,6 +30,7 @@ def open(self, path):
|
|||
if fd.read(len(self.FILE_ID)) != self.FILE_ID:
|
||||
raise ValueError('Not a keychain')
|
||||
cdata = fd.read()
|
||||
self.password = ''
|
||||
data = self.decrypt(cdata, '')
|
||||
while not data:
|
||||
self.password = getpass('Keychain password: ')
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import filecmp
|
||||
import os
|
||||
import time
|
||||
from StringIO import StringIO
|
||||
import sys
|
||||
import shutil
|
||||
|
@ -25,7 +24,7 @@ def setUp(self):
|
|||
os.chdir(self.tmpdir)
|
||||
self.keychain = '/tmp/_test_dedupstore.keychain'
|
||||
if not os.path.exists(self.keychain):
|
||||
self.darc('keychain', 'generate')
|
||||
self.darc('init-keychain')
|
||||
self.darc('init', self.store_path)
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -92,7 +91,6 @@ def test_basic_functionality(self):
|
|||
os.symlink('somewhere', os.path.join(self.input_path, 'link1'))
|
||||
os.mkfifo(os.path.join(self.input_path, 'fifo1'))
|
||||
self.darc('create', self.store_path + '::test', 'input')
|
||||
time.sleep(1)
|
||||
self.darc('extract', self.store_path + '::test', 'output')
|
||||
self.diff_dirs('input', 'output/input')
|
||||
|
||||
|
@ -105,6 +103,11 @@ def test_corrupted_store(self):
|
|||
fd.close()
|
||||
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():
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(Test))
|
||||
|
|
Loading…
Reference in a new issue