From 03242d15a208a94ecd740b1a95f4e6bc496bf7bb Mon Sep 17 00:00:00 2001 From: bakashigure Date: Thu, 25 May 2023 02:50:14 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A7=E7=89=88?= =?UTF-8?q?=E6=9C=ACwindows=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90=E9=81=97?= =?UTF-8?q?=E7=95=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/main/utils/extract.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/main/utils/extract.ts b/packages/main/utils/extract.ts index 2ad91474..9c18a2a1 100644 --- a/packages/main/utils/extract.ts +++ b/packages/main/utils/extract.ts @@ -26,7 +26,7 @@ export async function unzipFile(src: string, dest: string) { for (const file of dir.files.filter(file => file.type === 'Directory')) { const dirpath = path.join(dest, file.path) if (!fs.existsSync(dirpath)) { - logger.debug(`[Extract Helper] create directory: ${dirpath}`) + // logger.debug(`[Extract Helper] create directory: ${dirpath}`) fs.mkdirSync(dirpath, { recursive: true }) } } @@ -40,10 +40,19 @@ export async function unzipFile(src: string, dest: string) { new Promise((resolve, reject) => { const dirpath = path.join(dest, path.dirname(file.path)) if (!fs.existsSync(dirpath)) { - logger.debug(`[Extract Helper] create directory: ${dirpath}`) + // logger.debug(`[Extract Helper] create directory: ${dirpath}`) fs.mkdirSync(dirpath, { recursive: true }) } - logger.debug(`[Extract Helper] create file: ${file.path}`) + // logger.debug(`[Extract Helper] create file: ${file.path}`) + const destFilePath = path.join(dest, file.path) + if (fs.existsSync(destFilePath)) { + try { + fs.accessSync(destFilePath, fs.constants.W_OK) + } catch (e) { + fs.unlinkSync(destFilePath) + logger.info(`[Extract Helper] no write access, remove file: ${destFilePath}`) + } + } const writeStream = fs.createWriteStream( path.join(dest, file.path), platform === 'windows'