mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-11-10 16:30:54 +08:00
Fixes #192
Fixes noHL logic with false negatives not being caught with small files.
This commit is contained in:
parent
b36cb1263c
commit
719de5c4e0
1 changed files with 17 additions and 4 deletions
|
|
@ -264,15 +264,28 @@ def remove_empty_directories(pathlib_root_dir, pattern):
|
||||||
|
|
||||||
|
|
||||||
# will check if there are any hard links if it passes a file or folder
|
# will check if there are any hard links if it passes a file or folder
|
||||||
|
# If a folder is passed, it will take the largest file in that folder and only check for hardlinks
|
||||||
|
# of the remaining files where the file is greater size a percentage of the largest file
|
||||||
|
# This fixes the bug in #192
|
||||||
def nohardlink(file):
|
def nohardlink(file):
|
||||||
check = True
|
check = True
|
||||||
if os.path.isfile(file):
|
if os.path.isfile(file):
|
||||||
|
logger.trace(f"Checking file: {file}")
|
||||||
if os.stat(file).st_nlink > 1:
|
if os.stat(file).st_nlink > 1:
|
||||||
check = False
|
check = False
|
||||||
else:
|
else:
|
||||||
for path, subdirs, files in os.walk(file):
|
sorted_files = sorted(Path(file).rglob("*"), key=lambda x: os.stat(x).st_size, reverse=True)
|
||||||
for x in files:
|
threshold = 0.5
|
||||||
if os.stat(os.path.join(path, x)).st_nlink > 1:
|
largest_file_size = os.stat(sorted_files[0]).st_size
|
||||||
|
logger.trace(f"Largest file: {sorted_files[0]}")
|
||||||
|
logger.trace(f"Largest file size: {largest_file_size}")
|
||||||
|
for x in sorted_files:
|
||||||
|
file_size = os.stat(x).st_size
|
||||||
|
file_no_hardlinks = os.stat(x).st_nlink
|
||||||
|
logger.trace(f"Checking file: {file}")
|
||||||
|
logger.trace(f"Checking file size: {file_size}")
|
||||||
|
logger.trace(f"Checking no of hard links: {file_no_hardlinks}")
|
||||||
|
if file_no_hardlinks > 1 and file_size >= (largest_file_size * threshold):
|
||||||
check = False
|
check = False
|
||||||
return check
|
return check
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue