@@ -4546,44 +4546,53 @@ def _gen_allfiles_and_tar(self, directory, smallsize=1024, is_tar=True):
45464546 if file_path == csv_path :
45474547 continue
45484548
4549- # Check if file is larger than X MB
4550- size , mtime , atime = self ._get_file_stats (file_path )
4551-
4552- # Get last modified date
4553- mdate = datetime .datetime .fromtimestamp (
4554- mtime ).strftime ('%Y-%m-%d %H:%M:%S' )
4555-
4556- # Get last accessed date
4557- adate = datetime .datetime .fromtimestamp (
4558- atime ).strftime ('%Y-%m-%d %H:%M:%S' )
4559-
4560- # Get ownership
4561- owner = self .uid2user (os .lstat (file_path ).st_uid )
4562- group = self .gid2group (os .lstat (file_path ).st_gid )
4563-
4564- # Get permissions
4565- permissions = oct (os .lstat (file_path ).st_mode )
4566-
4567- # Set tarred to No
4568- tarred = "No"
4569-
4570- # Tar the file if it's smaller than the specified size
4571- if is_tar and size < smallsize * 1024 :
4572- # add to tar file
4573- tar_file .add (file_path , arcname = file )
4574-
4575- # Set didtar to True, so we know we tarred a file
4576- didtar = True
4577-
4578- # remove original file
4579- os .remove (file_path )
4580-
4581- # Set tarred to Yes
4582- tarred = "Yes"
4583-
4584- # Write file info to the csv file
4585- writer .writerow (
4586- [file , size , mdate , adate , owner , group , permissions , tarred ])
4549+ # Check if it's a regular file or a symlink
4550+ if os .path .isfile (file_path ) or os .path .islink (file_path ):
4551+ # Check if file is larger than X MB
4552+ size , mtime , atime = self ._get_file_stats (file_path )
4553+
4554+ # Get last modified date
4555+ mdate = datetime .datetime .fromtimestamp (
4556+ mtime ).strftime ('%Y-%m-%d %H:%M:%S' )
4557+
4558+ # Get last accessed date
4559+ adate = datetime .datetime .fromtimestamp (
4560+ atime ).strftime ('%Y-%m-%d %H:%M:%S' )
4561+
4562+ # Get ownership
4563+ owner = self .uid2user (os .lstat (file_path ).st_uid )
4564+ group = self .gid2group (os .lstat (file_path ).st_gid )
4565+
4566+ # Get permissions
4567+ permissions = oct (os .lstat (file_path ).st_mode )
4568+
4569+ # Set tarred to No
4570+ tarred = "No"
4571+
4572+ # Tar the file if it's smaller than the specified size
4573+ if is_tar and size < smallsize * 1024 :
4574+ try :
4575+ # add to tar file
4576+ tar_file .add (file_path , arcname = file )
4577+
4578+ # Set didtar to True, so we know we tarred a file
4579+ didtar = True
4580+
4581+ # remove original file
4582+ os .remove (file_path )
4583+
4584+ # Set tarred to Yes
4585+ tarred = "Yes"
4586+ except FileNotFoundError :
4587+ log (f"Warning: File { file_path } disappeared before tarring/removal." )
4588+ continue # Skip writing CSV row if tarring failed
4589+ except Exception as e :
4590+ log (f"Warning: Failed to tar or remove { file_path } : { e } " )
4591+ continue # Skip writing CSV row if tarring failed
4592+
4593+ # Write file info to the csv file
4594+ writer .writerow (
4595+ [file , size , mdate , adate , owner , group , permissions , tarred ])
45874596
45884597 # Check if we tarred any files
45894598 if not didtar :
0 commit comments