mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 01:06:50 +00:00
debug-put-obj command
This commit is contained in:
parent
9986705760
commit
a2fc479da3
2 changed files with 36 additions and 9 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
from binascii import hexlify
|
||||
from datetime import datetime
|
||||
from hashlib import sha256
|
||||
from operator import attrgetter
|
||||
import functools
|
||||
import inspect
|
||||
|
@ -514,6 +515,19 @@ def do_debug_dump_archive_items(self, args):
|
|||
print('Done.')
|
||||
return EXIT_SUCCESS
|
||||
|
||||
def do_debug_put_obj(self, args):
|
||||
"""put file(s) contents into the repository"""
|
||||
repository = self.open_repository(args.repository)
|
||||
manifest, key = Manifest.load(repository)
|
||||
for path in args.paths:
|
||||
with open(path, "rb") as f:
|
||||
data = f.read()
|
||||
h = sha256(data) # XXX hardcoded
|
||||
repository.put(h.digest(), data)
|
||||
print("object %s put." % h.hexdigest())
|
||||
repository.commit()
|
||||
return EXIT_SUCCESS
|
||||
|
||||
def do_debug_delete_obj(self, args):
|
||||
"""delete the objects with the given IDs from the repo"""
|
||||
repository = self.open_repository(args.repository)
|
||||
|
@ -1034,6 +1048,20 @@ def build_parser(self, args=None, prog=None):
|
|||
type=location_validator(archive=True),
|
||||
help='archive to dump')
|
||||
|
||||
debug_put_obj_epilog = textwrap.dedent("""
|
||||
This command puts objects into the repository.
|
||||
""")
|
||||
subparser = subparsers.add_parser('debug-put-obj', parents=[common_parser],
|
||||
description=self.do_debug_put_obj.__doc__,
|
||||
epilog=debug_put_obj_epilog,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
subparser.set_defaults(func=self.do_debug_put_obj)
|
||||
subparser.add_argument('repository', metavar='REPOSITORY', nargs='?', default='',
|
||||
type=location_validator(archive=False),
|
||||
help='repository to use')
|
||||
subparser.add_argument('paths', metavar='PATH', nargs='+', type=str,
|
||||
help='file(s) to read and create object(s) from')
|
||||
|
||||
debug_delete_obj_epilog = textwrap.dedent("""
|
||||
This command deletes objects from the repository.
|
||||
""")
|
||||
|
|
|
@ -777,20 +777,19 @@ def test_debug_dump_archive_items(self):
|
|||
assert len(output_dir) > 0 and output_dir[0].startswith('000000_')
|
||||
assert 'Done.' in output
|
||||
|
||||
def test_debug_delete_obj(self):
|
||||
def test_debug_put_delete_obj(self):
|
||||
self.cmd('init', self.repository_location)
|
||||
repository = Repository(self.repository_location)
|
||||
data = b'some data'
|
||||
h = sha256(data)
|
||||
key, hexkey = h.digest(), h.hexdigest()
|
||||
repository.put(key, data)
|
||||
repository.commit()
|
||||
output = self.cmd('debug-delete-obj', self.repository_location, 'invalid')
|
||||
assert "is invalid" in output
|
||||
hexkey = sha256(data).hexdigest()
|
||||
self.create_regular_file('file', contents=data)
|
||||
output = self.cmd('debug-put-obj', self.repository_location, 'input/file')
|
||||
assert hexkey in output
|
||||
output = self.cmd('debug-delete-obj', self.repository_location, hexkey)
|
||||
assert "deleted" in output
|
||||
output = self.cmd('debug-delete-obj', self.repository_location, hexkey)
|
||||
assert "not found" in output
|
||||
output = self.cmd('debug-delete-obj', self.repository_location, 'invalid')
|
||||
assert "is invalid" in output
|
||||
|
||||
|
||||
@unittest.skipUnless('binary' in BORG_EXES, 'no borg.exe available')
|
||||
|
@ -902,5 +901,5 @@ def test_fuse_mount_archive(self):
|
|||
pass
|
||||
|
||||
@unittest.skip('only works locally')
|
||||
def test_debug_delete_obj(self):
|
||||
def test_debug_put_delete_obj(self):
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue