Use two separate calls to assert_enough_space.
This commit is contained in:
parent
26c6fb31cf
commit
ec2bd9aa86
1 changed files with 17 additions and 15 deletions
30
rarpar.py
30
rarpar.py
|
@ -146,27 +146,22 @@ def PARCOMMAND(workdir, basename, par):
|
||||||
]
|
]
|
||||||
return command
|
return command
|
||||||
|
|
||||||
def assert_enough_space(pathsize, workdir, moveto, rec, rev, par):
|
def assert_enough_space(pathsize, drive, rec, rev, par):
|
||||||
plus_percent = (rec + rev + par) / 100
|
plus_percent = (rec + rev + par) / 100
|
||||||
needed = pathsize * (1 + plus_percent)
|
needed = pathsize * (1 + plus_percent)
|
||||||
reserve = RESERVE_SPACE_ON_DRIVE + needed
|
reserve = RESERVE_SPACE_ON_DRIVE + needed
|
||||||
|
|
||||||
workdir_drive = os.path.splitdrive(workdir.absolute_path)[0] + os.sep
|
free_space = shutil.disk_usage(drive.absolute_path).free
|
||||||
free_space = shutil.disk_usage(workdir_drive).free
|
|
||||||
|
|
||||||
if moveto is not None:
|
if reserve <= free_space:
|
||||||
moveto_drive = os.path.splitdrive(moveto.absolute_path)[0]
|
return
|
||||||
moveto_drive = pathclass.Path(moveto_drive)
|
|
||||||
free_space = min(free_space, shutil.disk_usage(moveto_drive.absolute_path).free)
|
|
||||||
|
|
||||||
message = ' '.join([
|
message = ' '.join([
|
||||||
f'For {bytestring.bytestring(pathsize)},',
|
f'For {bytestring.bytestring(pathsize)},',
|
||||||
f'reserve {bytestring.bytestring(reserve)}',
|
f'reserve {bytestring.bytestring(reserve)}.',
|
||||||
f'out of {bytestring.bytestring(free_space)}.',
|
f'Only {bytestring.bytestring(free_space)} available',
|
||||||
|
f'on {drive.absolute_path}.',
|
||||||
])
|
])
|
||||||
log.debug(message)
|
|
||||||
|
|
||||||
if reserve > free_space:
|
|
||||||
raise NotEnoughSpace(message)
|
raise NotEnoughSpace(message)
|
||||||
|
|
||||||
def move(pattern, directory):
|
def move(pattern, directory):
|
||||||
|
@ -385,8 +380,15 @@ def rarpar(
|
||||||
if RESERVE_SPACE_ON_DRIVE:
|
if RESERVE_SPACE_ON_DRIVE:
|
||||||
assert_enough_space(
|
assert_enough_space(
|
||||||
pathsize,
|
pathsize,
|
||||||
workdir=workdir,
|
drive=workdir.drive,
|
||||||
moveto=moveto,
|
rec=rec or 0,
|
||||||
|
rev=rev or 0,
|
||||||
|
par=par or 0,
|
||||||
|
)
|
||||||
|
if RESERVE_SPACE_ON_DRIVE and moveto is not None:
|
||||||
|
assert_enough_space(
|
||||||
|
pathsize,
|
||||||
|
drive=moveto.drive,
|
||||||
rec=rec or 0,
|
rec=rec or 0,
|
||||||
rev=rev or 0,
|
rev=rev or 0,
|
||||||
par=par or 0,
|
par=par or 0,
|
||||||
|
|
Loading…
Reference in a new issue