Skip to content

Commit

Permalink
Show current volume number in NeedFirstVolume exception
Browse files Browse the repository at this point in the history
This exposed also minor bug in main block parse,
that did not affect anything else.

Fixes: markokr#55
  • Loading branch information
markokr committed Sep 15, 2019
1 parent ab2de30 commit 505901d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,12 @@ def _parse_real(self):
# RAR 2.x does not set FIRSTVOLUME,
# so check it only if NEWNUMBERING is used
if (h.flags & RAR_MAIN_FIRSTVOLUME) == 0:
if getattr(h, 'main_volume_number', None) is not None:
# rar5 may have more info
raise NeedFirstVolume(
"Need to start from first volume (current: %r)"
% (h.main_volume_number,)
)
raise NeedFirstVolume("Need to start from first volume")
if h.flags & RAR_MAIN_PASSWORD:
self._needs_password = True
Expand Down Expand Up @@ -1698,7 +1704,7 @@ def _parse_block_common(self, h, hdata):
def _parse_main_block(self, h, hdata, pos):
h.main_flags, pos = load_vint(hdata, pos)
if h.main_flags & RAR5_MAIN_FLAG_HAS_VOLNR:
h.main_volume_number = load_vint(hdata, pos)
h.main_volume_number, pos = load_vint(hdata, pos)

h.flags |= RAR_MAIN_NEWNUMBERING
if h.main_flags & RAR5_MAIN_FLAG_SOLID:
Expand Down
6 changes: 6 additions & 0 deletions test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def test_rar3_vols():
'test/files/rar3-vols.part1.rar',
'test/files/rar3-vols.part2.rar',
'test/files/rar3-vols.part3.rar']
with pytest.raises(rarfile.NeedFirstVolume):
rarfile.RarFile('test/files/rar3-vols.part2.rar')

def test_rar3_oldvols():
r = rarfile.RarFile('test/files/rar3-old.rar')
Expand All @@ -135,6 +137,8 @@ def test_rar3_oldvols():
'test/files/rar3-old.rar',
'test/files/rar3-old.r00',
'test/files/rar3-old.r01']
with pytest.raises(rarfile.NeedFirstVolume):
rarfile.RarFile('test/files/rar3-old.r00')

def test_rar5_vols():
r = rarfile.RarFile('test/files/rar5-vols.part1.rar')
Expand All @@ -146,6 +150,8 @@ def test_rar5_vols():
'test/files/rar5-vols.part1.rar',
'test/files/rar5-vols.part2.rar',
'test/files/rar5-vols.part3.rar']
with pytest.raises(rarfile.NeedFirstVolume):
rarfile.RarFile('test/files/rar5-vols.part2.rar')

def expect_ctime(mtime, ctime):
return [mkitem(
Expand Down

0 comments on commit 505901d

Please sign in to comment.