From 4477285583421352a98efa7e81d629717b6b15e5 Mon Sep 17 00:00:00 2001 From: Chinonso Date: Fri, 9 Aug 2024 11:55:38 -0400 Subject: [PATCH] copy checkin --- src/app/shared/system-service/file.service.ts | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/app/shared/system-service/file.service.ts b/src/app/shared/system-service/file.service.ts index 421b21a5..edd3aab3 100644 --- a/src/app/shared/system-service/file.service.ts +++ b/src/app/shared/system-service/file.service.ts @@ -113,34 +113,37 @@ export class FileService{ public async copyFileAsync(sourcePath:string, destinationPath:string):Promise{ const fileName = this.getFileName(sourcePath); console.log(`Destination: ${destinationPath}/${fileName}`); - return new Promise((resolve, reject) =>{ - fs.readFile(sourcePath,(err, contents = Buffer.from('')) =>{ - if(err){ - console.log('copyFileAsync error:',err) - reject(false) - }else{ - fs.writeFile(`${destinationPath}/${fileName}`, contents, {flag: 'wx'}, (err) =>{ - if(err?.code === 'EEXIST' ){ - console.log('copyFileAsync Error: file already exists',err); + const result = await fs.promises.copyFile(sourcePath, `${destinationPath}/${fileName}`); + + return true; + // return new Promise((resolve, reject) =>{ + // fs.readFile(sourcePath,(err, contents = Buffer.from('')) =>{ + // if(err){ + // console.log('copyFileAsync error:',err) + // reject(false) + // }else{ + // fs.writeFile(`${destinationPath}/${fileName}`, contents, {flag: 'wx'}, (err) =>{ + // if(err?.code === 'EEXIST' ){ + // console.log('copyFileAsync Error: file already exists',err); - // if file exists, increment it simple.txt, simple(1).txt ... - const itrName = this.iterateFileName(`${destinationPath}/${fileName}`); - fs.writeFile(itrName,contents,(err) =>{ - if(err){ - console.log('copyFileAsync Iterate Error:',err); - reject(false); - } - resolve(true); - }); - }else{ - console.log('copyFileAsync Error:',err); - this._fileExistsMap.set(`${destinationPath}/${fileName}`,0); - resolve(true); - } - }); - } - }); - }); + // // if file exists, increment it simple.txt, simple(1).txt ... + // const itrName = this.iterateFileName(`${destinationPath}/${fileName}`); + // fs.writeFile(itrName,contents,(err) =>{ + // if(err){ + // console.log('copyFileAsync Iterate Error:',err); + // reject(false); + // } + // resolve(true); + // }); + // }else{ + // console.log('copyFileAsync Error:',err); + // this._fileExistsMap.set(`${destinationPath}/${fileName}`,0); + // resolve(true); + // } + // }); + // } + // }); + // }); }