Updated to handle removing directories

This commit is contained in:
jamelreid 2022-01-27 10:11:13 -05:00
parent bc73cf2a63
commit 68af14a26b
1 changed files with 12 additions and 5 deletions

View File

@ -152,13 +152,20 @@ const downloadZip = async ( fileUrl, downloadPath, authorizationToken ) => {
const deleteDownloadedPluginFiles = async () => {
const pluginSavePath = resolveLocalE2ePath( 'plugins' );
fs.readdir( pluginSavePath, ( err, files ) => {
fs.readdir( pluginSavePath, ( err, contents ) => {
if ( err ) throw err;
for ( const file of files ) {
fs.unlink( path.join( pluginSavePath, file ), ( error ) => {
if ( error ) throw error;
} );
for ( const content of contents ) {
const contentPath = path.join( pluginSavePath, content );
const stats = fs.lstatSync( contentPath );
if ( stats.isDirectory() ) {
fs.rmSync( contentPath, { recursive: true, force: true } );
} else {
fs.unlink( contentPath, ( error ) => {
if ( error ) throw error;
} );
}
}
} );
};