Browse Source

if container is already present and complete, skip it..

main
John-Mark Gurney 2 years ago
parent
commit
f4fd04ec10
2 changed files with 23 additions and 9 deletions
  1. +5
    -0
      ui/fixtures/cmd.container.json
  2. +18
    -9
      ui/medashare/cli.py

+ 5
- 0
ui/fixtures/cmd.container.json View File

@@ -69,5 +69,10 @@
"special": "verify store object cnt",
"comment": "should only have one container and six files files, and a metadata",
"count": 9
},
{
"title": "that it gets skipped when complete",
"cmd": [ "container", "somedir.torrent" ],
"stderr": "Warning, container already complete, skipping 'somedir.torrent'.\n"
}
]

+ 18
- 9
ui/medashare/cli.py View File

@@ -1261,6 +1261,24 @@ def cmd_list(options, persona, objstr, cache):
@init_datastructs
def cmd_container(options, persona, objstr, cache):
for i in options.files:
with open(i, 'rb') as fp:
torrent = bencode.bdecode(fp.read())
bencodedinfo = bencode.bencode(torrent['info'])
infohash = hashlib.sha1(bencodedinfo).hexdigest()

# XXX - not entirely happy w/ URI
uri = 'magnet:?xt=urn:btih:%s&dn=%s' % (infohash,
torrent['info']['name'].decode('utf-8'))

try:
cont = objstr.by_id(Container.make_id(uri))
except KeyError:
pass
else:
if not 'incomplete' in cont:
print('Warning, container already complete, skipping %s.' % repr(i), file=sys.stderr)
continue

good, bad = validate_file(i)

if bad:
@@ -1283,15 +1301,6 @@ def cmd_container(options, persona, objstr, cache):
# XXX - ensure only one is added?
hashes.extend(fobj.hashes)

with open(i, 'rb') as fp:
torrent = bencode.bdecode(fp.read())
bencodedinfo = bencode.bencode(torrent['info'])
infohash = hashlib.sha1(bencodedinfo).hexdigest()

# XXX - not entirely happy w/ URI
uri = 'magnet:?xt=urn:btih:%s&dn=%s' % (infohash,
torrent['info']['name'].decode('utf-8'))

kwargs = dict(files=files, hashes=hashes,
uri=uri)



Loading…
Cancel
Save