Skip to content

Commit

Permalink
copy checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
chinonso098 authored Aug 9, 2024
1 parent eefac8e commit 4477285
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/app/shared/system-service/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,34 +113,37 @@ export class FileService{
public async copyFileAsync(sourcePath:string, destinationPath:string):Promise<boolean>{
const fileName = this.getFileName(sourcePath);
console.log(`Destination: ${destinationPath}/${fileName}`);
return new Promise<boolean>((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<boolean>((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);
// }
// });
// }
// });
// });
}


Expand Down

0 comments on commit 4477285

Please sign in to comment.