Skip to content

Commit

Permalink
Don’t create temp directory if file isn’t compressed
Browse files Browse the repository at this point in the history
  • Loading branch information
t-wright committed Oct 20, 2023
1 parent eaa9bb2 commit a77cc7a
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/commands/dev-env-import-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,30 @@ export class DevEnvImportSQLCommand {
this.fileName = fileName;
this.options = options;
this.slug = slug;
this.tmpDir = makeTempDir();
}

get sqlFile() {
return `${ this.tmpDir }/sql-import.sql`;
}

async run( silent = false ) {
const fileMeta = await getFileMeta( this.fileName );
const lando = await bootstrapLando();
await validateDependencies( lando, this.slug, silent );

validateImportFileExtension( this.fileName );

// Check if file is compressed and if so, extract the
const fileMeta = await getFileMeta( this.fileName );
if ( fileMeta.isCompressed ) {
const tmpDir = makeTempDir();
const sqlFile = `${ tmpDir }/sql-import.sql`;

try {
console.log( `Extracting the compressed file ${ this.fileName }...` );
await unzipFile( this.fileName, this.sqlFile );
console.log( `${ chalk.green( '✓' ) } Extracted to ${ this.sqlFile }` );
this.fileName = this.sqlFile;
await unzipFile( this.fileName, sqlFile );
console.log( `${ chalk.green( '✓' ) } Extracted to ${ sqlFile }` );
this.fileName = sqlFile;
} catch ( err ) {
exit.withError( `Error extracting the SQL file: ${ err.message }` );
}
}

const lando = await bootstrapLando();
await validateDependencies( lando, this.slug, silent );

const { searchReplace, inPlace } = this.options;
const resolvedPath = await resolveImportPath(
this.slug,
Expand Down

0 comments on commit a77cc7a

Please sign in to comment.