@@ -442,12 +442,13 @@ def empty_head_scan_file() -> List[str]:
442442 Returns:
443443 List containing path to a temporary empty file
444444 """
445- # Create a temporary empty file
446- temp_fd , temp_path = tempfile .mkstemp (suffix = '.empty' , prefix = 'socket_baseline_' )
445+ # Create a temporary directory and then create our specific filename
446+ temp_dir = tempfile .gettempdir ()
447+ temp_path = os .path .join (temp_dir , '.socket.facts.json' )
447448
448- # Close the file descriptor since we just need the path
449- # The file is already created and empty
450- os . close ( temp_fd )
449+ # Create the empty file
450+ with open ( temp_path , 'w' ) as f :
451+ pass # Creates an empty file
451452
452453 log .debug (f"Created temporary empty file for baseline scan: { temp_path } " )
453454 return [temp_path ]
@@ -524,18 +525,42 @@ def create_full_scan_with_report_url(
524525 if save_manifest_tar_path and all_files and paths :
525526 self .save_manifest_tar (all_files , save_manifest_tar_path , paths [0 ])
526527
528+ # If no supported files found, create empty scan
527529 if not all_files :
528- return diff
529-
530- try :
531- # Create new scan
532- new_scan_start = time .time ()
533- new_full_scan = self .create_full_scan (all_files , params , base_paths = base_paths )
534- new_scan_end = time .time ()
535- log .info (f"Total time to create new full scan: { new_scan_end - new_scan_start :.2f} " )
536- except APIFailure as e :
537- log .error (f"Failed to create full scan: { e } " )
538- raise
530+ log .info ("No supported manifest files found - creating empty scan" )
531+ empty_files = Core .empty_head_scan_file ()
532+ try :
533+ # Create new scan
534+ new_scan_start = time .time ()
535+ new_full_scan = self .create_full_scan (empty_files , params , base_paths = base_paths )
536+ new_scan_end = time .time ()
537+ log .info (f"Total time to create empty full scan: { new_scan_end - new_scan_start :.2f} " )
538+
539+ # Clean up the temporary empty file
540+ for temp_file in empty_files :
541+ try :
542+ os .unlink (temp_file )
543+ log .debug (f"Cleaned up temporary file: { temp_file } " )
544+ except OSError as e :
545+ log .warning (f"Failed to clean up temporary file { temp_file } : { e } " )
546+ except Exception as e :
547+ # Clean up temp files even if scan creation fails
548+ for temp_file in empty_files :
549+ try :
550+ os .unlink (temp_file )
551+ except OSError :
552+ pass
553+ raise e
554+ else :
555+ try :
556+ # Create new scan
557+ new_scan_start = time .time ()
558+ new_full_scan = self .create_full_scan (all_files , params , base_paths = base_paths )
559+ new_scan_end = time .time ()
560+ log .info (f"Total time to create new full scan: { new_scan_end - new_scan_start :.2f} " )
561+ except APIFailure as e :
562+ log .error (f"Failed to create full scan: { e } " )
563+ raise
539564
540565 # Construct report URL
541566 base_socket = "https://socket.dev/dashboard/org"
@@ -888,8 +913,11 @@ def create_new_diff(
888913 if save_manifest_tar_path and all_files and paths :
889914 self .save_manifest_tar (all_files , save_manifest_tar_path , paths [0 ])
890915
916+ # If no supported files found, create empty scan for comparison
917+ scan_files = all_files
891918 if not all_files :
892- return Diff (id = "NO_DIFF_RAN" , diff_url = "" , report_url = "" )
919+ log .info ("No supported manifest files found - creating empty scan for diff comparison" )
920+ scan_files = Core .empty_head_scan_file ()
893921
894922 try :
895923 # Get head scan ID
@@ -932,19 +960,43 @@ def create_new_diff(
932960 raise e
933961
934962 # Create new scan
963+ temp_files_to_cleanup = []
964+ if not all_files : # We're using empty scan files
965+ temp_files_to_cleanup = scan_files
966+
935967 try :
936968 new_scan_start = time .time ()
937- new_full_scan = self .create_full_scan (all_files , params , base_paths = base_paths )
969+ new_full_scan = self .create_full_scan (scan_files , params , base_paths = base_paths )
938970 new_scan_end = time .time ()
939971 log .info (f"Total time to create new full scan: { new_scan_end - new_scan_start :.2f} " )
940972 except APIFailure as e :
941973 log .error (f"API Error: { e } " )
974+ # Clean up temp files if any
975+ for temp_file in temp_files_to_cleanup :
976+ try :
977+ os .unlink (temp_file )
978+ except OSError :
979+ pass
942980 sys .exit (1 )
943981 except Exception as e :
944982 import traceback
945983 log .error (f"Error creating new full scan: { str (e )} " )
946984 log .error (f"Stack trace:\n { traceback .format_exc ()} " )
985+ # Clean up temp files if any
986+ for temp_file in temp_files_to_cleanup :
987+ try :
988+ os .unlink (temp_file )
989+ except OSError :
990+ pass
947991 raise
992+ finally :
993+ # Clean up temporary empty files if they were created
994+ for temp_file in temp_files_to_cleanup :
995+ try :
996+ os .unlink (temp_file )
997+ log .debug (f"Cleaned up temporary file: { temp_file } " )
998+ except OSError as e :
999+ log .warning (f"Failed to clean up temporary file { temp_file } : { e } " )
9481000
9491001 # Handle diff generation - now we always have both scans
9501002 scans_ready = self .check_full_scans_status (head_full_scan_id , new_full_scan .id )
0 commit comments