File tree 1 file changed +8
-4
lines changed
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -59,19 +59,22 @@ def validate_file(path):
59
59
- path (str): The absolute path to the file.
60
60
61
61
Returns:
62
- None
62
+ - bool: True if the file is valid, False otherwise.
63
63
"""
64
64
if not isfile (path ):
65
- return
65
+ return False
66
66
67
67
if splitext (path )[1 ] not in VALID_EXTENSIONS :
68
68
print (f"Error: { basename (path )} has an unsupported file extension. "
69
69
f"Allowed extensions: { ', ' .join (VALID_EXTENSIONS )} " )
70
- return
70
+ return False
71
71
72
72
if getsize (path ) >= MAX_FILE_SIZE_MB * (1 << 20 ):
73
73
print (f"Error: { basename (path )} exceeds the permitted file size limit "
74
74
f"({ getsize (path ) / (1 << 20 ):.2f} MB > 40MB)." )
75
+ return False
76
+
77
+ return True
75
78
76
79
77
80
class MonitorFolder (FileSystemEventHandler ):
@@ -85,7 +88,8 @@ def on_created(self, event):
85
88
Returns:
86
89
None
87
90
"""
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
89
93
90
94
sleep (0.02 ) # Apply a small sleep time to allow for system events
91
95
You can’t perform that action at this time.
0 commit comments