From ef254ecb1271902dfde8ff4adbc29d74a64a14ff Mon Sep 17 00:00:00 2001 From: Iurii <9779955557@mail.ru> Date: Mon, 1 Apr 2024 21:51:13 +0300 Subject: [PATCH] =?UTF-8?q?fix.=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=82=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D1=82=D1=80=D0=B0=D0=BD=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index 9d4d58b..7c608cc 100644 --- a/src/main.py +++ b/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) if hysteresis < BS: hysteresis = BS 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: 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'to_be_wasted: {round(to_be_wasted/ 2**30, 3)}GB ') if to_be_wasted < -hysteresis: - to_be_trimmed = abs(to_be_wasted) - baloon_size = os.path.getsize(os.path.join(fs, baloon_filename)) - if baloon_size> to_be_trimmed: - os.truncate(os.path.join(fs, baloon_filename), baloon_size - to_be_trimmed) + to_be_trimmed = abs(to_be_wasted) + baloon_size = os.path.getsize(baloon_filename) + if baloon_size > to_be_trimmed: + os.truncate(baloon_filename, baloon_size - to_be_trimmed) 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: - with open(os.path.join(fs, baloon_filename) , 'ab') as f: + with open(baloon_filename , 'ab') as f: last = 0 writed = to_be_wasted while to_be_wasted > 0: