Skip to content

Commit

Permalink
I'll leave ZenFS for now. A bug with causing copy to some directorys …
Browse files Browse the repository at this point in the history
…to fail
  • Loading branch information
chinonso098 committed Aug 4, 2024
1 parent 18dea26 commit eefac8e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
19 changes: 11 additions & 8 deletions src/app/shared/system-service/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,21 @@ export class FileService{
})
}

public async copyFileAsync(sourcepath:string, destinationpath:string):Promise<boolean>{

const fileName = this.getFileName(sourcepath);
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('')) =>{
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) =>{
fs.writeFile(`${destinationPath}/${fileName}`, contents, {flag: 'wx'}, (err) =>{
if(err?.code === 'EEXIST' ){
console.log('copyFileAsync Error: file already exists',err);

const itrName = this.iterateFileName(`${destinationpath}/${fileName}`);
// 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);
Expand All @@ -132,7 +133,8 @@ export class FileService{
resolve(true);
});
}else{
this._fileExistsMap.set(`${destinationpath}/${fileName}`,0);
console.log('copyFileAsync Error:',err);
this._fileExistsMap.set(`${destinationPath}/${fileName}`,0);
resolve(true);
}
});
Expand All @@ -141,6 +143,7 @@ export class FileService{
});
}


public async copyFilesAsync(sourcepaths:string[], destinationpath:string):Promise<boolean>{

return new Promise<boolean>((resolve, reject) =>{
Expand Down Expand Up @@ -306,6 +309,7 @@ export class FileService{
console.log("Oops! a boo boo happened, filesystem wasn't ready:", err);
reject([]);
}else{
console.log(`${path} contents`, files);
resolve(files || []);
}
});
Expand Down Expand Up @@ -542,7 +546,6 @@ export class FileService{
}

public async writeFileAsync(directory:string, file:FileInfo):Promise<boolean>{

return new Promise<boolean>((resolve, reject) =>{
fs.writeFile(`${directory}/${file.getFileName}`, file.getContentPath, {flag: 'wx'}, (err) =>{
if(err?.code === 'EEXIST' ){
Expand Down
29 changes: 17 additions & 12 deletions src/app/system-apps/terminal/terminal.commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ ${(file.getIsFile)? '-':'d'}${this.addspaces(strPermission,10)} ${this.addspaces
return `folder: ${arg0} successfully created`;
}

this.sendDirectoryUpdateNotification();
this.sendDirectoryUpdateNotification(this.currentDirectoryPath);
}
}else{
return `
Expand All @@ -520,7 +520,13 @@ usage: mkdir direcotry_name [-v]
folderQueue.push(sourceArg);
const result = await this.mvhandler(destinationArg, folderQueue);
if(result){
this.sendDirectoryUpdateNotification();

if(destinationArg.includes('/Desktop')){
this.sendDirectoryUpdateNotification(sourceArg);
this.sendDirectoryUpdateNotification(destinationArg);
}
else
this.sendDirectoryUpdateNotification(sourceArg);
}

return ''
Expand Down Expand Up @@ -573,9 +579,9 @@ usage: mkdir direcotry_name [-v]

async cp(optionArg:any, sourceArg:string, destinationArg:string):Promise<string>{

console.log(`source ${optionArg}`);
console.log(`source ${sourceArg}`);
console.log(`destination ${destinationArg}`);
console.log(`copy-source ${optionArg}`);
console.log(`copy-destination ${sourceArg}`);
//console.log(`destination ${destinationArg}`);

const folderQueue:string[] = []
if(destinationArg === undefined){
Expand Down Expand Up @@ -629,15 +635,15 @@ Mandatory argument to long options are mandotory for short options too.
//const result = await this.cp_dir_handler(optionArg,destinationArg, folderQueue);
const result = await this.cpHandler(optionArg,sourceArg, destinationArg);
if(result){
this.sendDirectoryUpdateNotification();
this.sendDirectoryUpdateNotification(destinationArg);
}
}
}else{
// just copy regular file
//const result = await this.cp_file_handler(sourceArg,destinationArg);
const result = await this.cpHandler(optionArg,sourceArg, destinationArg);
if(result){
this.sendDirectoryUpdateNotification();
this.sendDirectoryUpdateNotification(destinationArg);
}
}
return '';
Expand Down Expand Up @@ -683,7 +689,6 @@ Mandatory argument to long options are mandotory for short options too.
return true
}


async rm(optionArg:any, sourceArg:string):Promise<string>{

console.log(`source ${optionArg}`);
Expand Down Expand Up @@ -731,14 +736,14 @@ Mandatory argument to long options are mandotory for short options too.
folderQueue.push(sourceArg);
const result = await this.rmHandler(optionArg,sourceArg);
if(result){
this.sendDirectoryUpdateNotification();
this.sendDirectoryUpdateNotification(sourceArg);
}
}
}else{
// just copy regular file
const result = await this.rmHandler(sourceArg,sourceArg);
if(result){
this.sendDirectoryUpdateNotification();
this.sendDirectoryUpdateNotification(sourceArg);
}
}
return '';
Expand Down Expand Up @@ -787,8 +792,8 @@ Mandatory argument to long options are mandotory for short options too.
return `${basename(path, extname(path))}${ extname(path)}`;
}

private sendDirectoryUpdateNotification():void{
if(this.currentDirectoryPath.includes('/Desktop')){
private sendDirectoryUpdateNotification(arg0:string):void{
if(arg0.includes('/Desktop')){
this._fileService.addEventOriginator('filemanager');
}else{
this._fileService.addEventOriginator('fileexplorer');
Expand Down

0 comments on commit eefac8e

Please sign in to comment.