Browse Source

fix issue w/ calculating size of last piece...

main
John-Mark Gurney 2 years ago
parent
commit
c2ac1018e5
2 changed files with 17 additions and 1 deletions
  1. +16
    -1
      ui/medashare/btv/__init__.py
  2. +1
    -0
      ui/medashare/btv/fixtures/40plus1.txt.torrent

+ 16
- 1
ui/medashare/btv/__init__.py View File

@@ -47,7 +47,10 @@ class Storage:
# get length
sz = length
piececnt = roundup(sz, piecelen)
self._pieceindex = [ [ dict(file=self._rootpath, offset=x * piecelen, size=piecelen if x < piececnt - 1 else sz - piececnt * x) ] for x in range(piececnt) ]
self._pieceindex = [ [ dict(file=self._rootpath,
offset=x * piecelen, size=piecelen if
x < piececnt - 1 else sz - x * piecelen) ] for x in
range(piececnt) ]
else:
self._buildindex()

@@ -391,6 +394,18 @@ class _TestCases(unittest.TestCase):
self.assertFalse(good)
self.assertEqual(hashes, {})

shutil.copy(self.fixtures / '40plus1.txt.torrent', self.basetempdir)
tor = self.basetempdir / '40plus1.txt.torrent'

with open(sd / '40plus1.txt', 'w') as fp:
fp.write('w')

good, bad, hashes = validate_file(tor, with_file_hashes=sha512)

self.assertEqual(bad, { sd / '40plus1.txt' })
self.assertFalse(good)
self.assertEqual(hashes, {})

def test_verification(self):
# Testing for "missing" files
# piece size 2 (aka 4 bytes)


+ 1
- 0
ui/medashare/btv/fixtures/40plus1.txt.torrent View File

@@ -0,0 +1 @@
d13:creation datei1663620495e4:infod6:lengthi41e4:name11:40plus1.txt12:piece lengthi4e6:pieces220:e®©ŒWÜÒ¡ÿ°Ó\¢ʯ}Ÿe®©ŒWÜÒ¡ÿ°Ó\¢ʯ}Ÿe®©ŒWÜÒ¡ÿ°Ó\¢ʯ}Ÿe®©ŒWÜÒ¡ÿ°Ó\¢ʯ}Ÿe®©ŒWÜÒ¡ÿ°Ó\¢ʯ}Ÿe®©ŒWÜÒ¡ÿ°Ó\¢ʯ}ŸÀé÷0Kp/Váè›O�ˆE Š‰k©¤Œ:m’­´äÆ34¸‚PŠm«�ÃÅo�?Ôë|»M‰Sdñ&ôs\}(=µ„kº‰*Uìâ§M|ý˜­È;ç“In ý‹FÍŸ2å’üe5:nodeslee

Loading…
Cancel
Save