@@ -340,6 +340,9 @@ class ImportTask {
340340 // Import the database using magerun2 db:import
341341 await this . importDatabase ( task , config , sqlFilePath , sqlFileSize ) ;
342342
343+ // Store the imported file path for cleanup
344+ ctx . importedSqlFile = sqlFilePath ;
345+
343346 const duration = Date . now ( ) - startTime ;
344347 const formattedDuration = ProgressDisplay . formatDuration ( duration ) ;
345348
@@ -356,18 +359,24 @@ class ImportTask {
356359 const logger = this . services . getLogger ( ) ;
357360 task . output = 'Removing temporary SQL files...' ;
358361
359- // Clean up SQL files (both compressed and uncompressed)
360- const cleanupFiles = `${ config . serverVariables . databaseName } .sql ${ config . serverVariables . databaseName } .sql.gz` ;
361-
362- await localhostMagentoRootExec (
363- `rm -f ${ cleanupFiles } ` ,
364- config ,
365- true
366- ) ;
367-
368- logger . info ( 'Cleanup complete' , {
369- removed : cleanupFiles
370- } ) ;
362+ // Clean up the actual imported SQL file
363+ if ( ctx . importedSqlFile && fs . existsSync ( ctx . importedSqlFile ) ) {
364+ fs . unlinkSync ( ctx . importedSqlFile ) ;
365+ logger . info ( 'Cleanup complete' , {
366+ removed : ctx . importedSqlFile
367+ } ) ;
368+ } else {
369+ // Fallback: try to clean up based on database name (legacy behavior)
370+ const cleanupFiles = `${ config . serverVariables . databaseName } .sql ${ config . serverVariables . databaseName } .sql.gz` ;
371+ await localhostMagentoRootExec (
372+ `rm -f ${ cleanupFiles } ` ,
373+ config ,
374+ true
375+ ) ;
376+ logger . info ( 'Cleanup complete (fallback)' , {
377+ removed : cleanupFiles
378+ } ) ;
379+ }
371380
372381 task . output = 'Cleanup complete ✓' ;
373382 }
0 commit comments