Skip to content

Commit 4e6acc7

Browse files
🐛 fix(main.py): return a boolean value from the validate_file function to indicate file validity
1 parent c187fa0 commit 4e6acc7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

main.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,22 @@ def validate_file(path):
5959
- path (str): The absolute path to the file.
6060
6161
Returns:
62-
None
62+
- bool: True if the file is valid, False otherwise.
6363
"""
6464
if not isfile(path):
65-
return
65+
return False
6666

6767
if splitext(path)[1] not in VALID_EXTENSIONS:
6868
print(f"Error: {basename(path)} has an unsupported file extension. "
6969
f"Allowed extensions: {', '.join(VALID_EXTENSIONS)}")
70-
return
70+
return False
7171

7272
if getsize(path) >= MAX_FILE_SIZE_MB * (1 << 20):
7373
print(f"Error: {basename(path)} exceeds the permitted file size limit "
7474
f"({getsize(path) / (1 << 20):.2f}MB > 40MB).")
75+
return False
76+
77+
return True
7578

7679

7780
class MonitorFolder(FileSystemEventHandler):
@@ -85,7 +88,8 @@ def on_created(self, event):
8588
Returns:
8689
None
8790
"""
88-
validate_file(event.src_path) # Attempt to validate the file; return if an issue arises
91+
if not validate_file(event.src_path):
92+
return # Exit early if validation fails
8993

9094
sleep(0.02) # Apply a small sleep time to allow for system events
9195

0 commit comments

Comments
 (0)