fix. Удаление файла при возврате пространства
This commit is contained in:
parent
6e80f9fba2
commit
ef254ecb12
14
src/main.py
14
src/main.py
|
|
@ -16,19 +16,23 @@ def set_utilization(fs, utilization_percent=0.6, baloon_filename='baloon', hyste
|
||||||
hysteresis = int(du.total * hysteresis_percent)
|
hysteresis = int(du.total * hysteresis_percent)
|
||||||
if hysteresis < BS: hysteresis = BS
|
if hysteresis < BS: hysteresis = BS
|
||||||
to_be_wasted = int(((du.used+du.free) * utilization_percent) - ((du.used+du.free) - du.free))
|
to_be_wasted = int(((du.used+du.free) * utilization_percent) - ((du.used+du.free) - du.free))
|
||||||
|
baloon_filename = os.path.join(fs, baloon_filename)
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print(f'hysteresis: {hysteresis}bytes')
|
print(f'hysteresis: {hysteresis}bytes')
|
||||||
print(f'total: {round(du.total/ 2**30, 3)}GB, used: {round(du.used/ 2**30, 3)}GB, free: {round(du.free/ 2**30, 3)}GB usage: {round(du.used * 100 / (du.used+du.free), 3)}%')
|
print(f'total: {round(du.total/ 2**30, 3)}GB, used: {round(du.used/ 2**30, 3)}GB, free: {round(du.free/ 2**30, 3)}GB usage: {round(du.used * 100 / (du.used+du.free), 3)}%')
|
||||||
print(f'to_be_wasted: {round(to_be_wasted/ 2**30, 3)}GB ')
|
print(f'to_be_wasted: {round(to_be_wasted/ 2**30, 3)}GB ')
|
||||||
if to_be_wasted < -hysteresis:
|
if to_be_wasted < -hysteresis:
|
||||||
to_be_trimmed = abs(to_be_wasted)
|
to_be_trimmed = abs(to_be_wasted)
|
||||||
baloon_size = os.path.getsize(os.path.join(fs, baloon_filename))
|
baloon_size = os.path.getsize(baloon_filename)
|
||||||
if baloon_size> to_be_trimmed:
|
if baloon_size > to_be_trimmed:
|
||||||
os.truncate(os.path.join(fs, baloon_filename), baloon_size - to_be_trimmed)
|
os.truncate(baloon_filename, baloon_size - to_be_trimmed)
|
||||||
if not quiet: print(f'trimmed {to_be_trimmed} Bytes')
|
if not quiet: print(f'trimmed {to_be_trimmed} Bytes')
|
||||||
elif not quiet: print(f'can\'t trim {baloon_size} < {to_be_trimmed}Bytes')
|
else:
|
||||||
|
if os.path.exists(baloon_filename):
|
||||||
|
os.remove(baloon_filename)
|
||||||
|
if not quiet and to_be_trimmed > baloon_size: print(f'can\'t trim {to_be_trimmed - baloon_size} Bytes')
|
||||||
elif to_be_wasted > hysteresis:
|
elif to_be_wasted > hysteresis:
|
||||||
with open(os.path.join(fs, baloon_filename) , 'ab') as f:
|
with open(baloon_filename , 'ab') as f:
|
||||||
last = 0
|
last = 0
|
||||||
writed = to_be_wasted
|
writed = to_be_wasted
|
||||||
while to_be_wasted > 0:
|
while to_be_wasted > 0:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue