Skip to content

Commit

Permalink
cp
Browse files Browse the repository at this point in the history
  • Loading branch information
chinonso098 committed Aug 5, 2024
1 parent d0bfec8 commit 7126b80
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 9 deletions.
86 changes: 77 additions & 9 deletions src/app/system-apps/terminal/terminal.commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,7 @@ ${this.addspaces(strPermission,10)} ${this.addspaces('Terminal',8)} ${this.addsp
if(arg1 && arg1 == '-v'){
return `folder: ${arg0} successfully created`;
}

this.sendDirectoryUpdateNotification();
this.sendDirectoryUpdateNotification(this.currentDirectoryPath);
}
}else{
return `
Expand All @@ -495,10 +494,79 @@ usage: mkdir direcotry_name [-v]
return '';
}

async mv(arg0:string, arg1:string):Promise<void>{
1
async mv(sourceArg:string, destinationArg:string):Promise<string>{

console.log(`sourceArg:${sourceArg}`);
console.log(`destinationArg:${destinationArg}`);

const folderQueue:string[] = [];

if(sourceArg === undefined || sourceArg.length === 0)
return 'source path required';

if(destinationArg === undefined || destinationArg.length === 0)
return 'destination path required';

folderQueue.push(sourceArg);
const result = await this.mvhandler(destinationArg, folderQueue);
if(result){

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

return ''
}

private async mvhandler(destinationArg:string, folderQueue:string[]):Promise<boolean>{

if(folderQueue.length === 0)
return true;

const sourcePath = folderQueue.shift() || '';
const folderName = this.getFileName(sourcePath);


const checkIfDirResult = await this._fileService.checkIfDirectory(`${sourcePath}`);

if(checkIfDirResult){
const loadedDirectoryEntries = await this._fileService.getEntriesFromDirectoryAsync(sourcePath);
const moveFolderResult = await this._fileService.moveAsync(sourcePath, destinationArg, false);
if(moveFolderResult){
for(const directoryEntry of loadedDirectoryEntries){
const checkIfDirResult = await this._fileService.checkIfDirectory(`${sourcePath}/${directoryEntry}`);
if(checkIfDirResult){
folderQueue.push(`${sourcePath}/${directoryEntry}`);
}else{
const result = await this._fileService.moveAsync(`${sourcePath}/${directoryEntry}`, `${destinationArg}/${folderName}`, true);
if(result){
console.log(`file:${sourcePath}/${directoryEntry} successfully moved to destination:${destinationArg}/${folderName}`);
}else{
console.log(`file:${sourcePath}/${directoryEntry} failed to move to destination:${destinationArg}/${folderName}`)
}
}
}
}else{
console.log(`folder:${destinationArg}/${folderName} creation failed`);
return false;
}
}else{
const result = await this._fileService.moveAsync(`${sourcePath}`,`${destinationArg}`, true);
if(result){
console.log(`file:${sourcePath} successfully moved to destination:${destinationArg}`);
}else{
console.log(`file:${sourcePath} failed to move to destination:${destinationArg}`)
}
}

return this.mvhandler(`${destinationArg}/${folderName}`, folderQueue);
}


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

console.log(`source ${optionArg}`);
Expand Down Expand Up @@ -557,15 +625,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 @@ -659,14 +727,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 @@ -715,7 +783,7 @@ Mandatory argument to long options are mandotory for short options too.
return `${basename(path, extname(path))}${ extname(path)}`;
}

private sendDirectoryUpdateNotification():void{
private sendDirectoryUpdateNotification(arg0:string):void{
if(this.currentDirectoryPath.includes('/osdrive/Desktop')){
this._fileService.addEventOriginator('filemanager');
}else{
Expand Down
14 changes: 14 additions & 0 deletions src/app/system-apps/terminal/terminal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,20 @@ export class TerminalComponent implements BaseComponent, OnInit, AfterViewInit,
terminalCmd.setCommandOutput = result;
}

if(rootCmd == "rm"){
const result = await this._terminaCommandsImpl.rm(cmdStringArr[1], cmdStringArr[2]);
terminalCmd.setResponseCode = this.Success;
terminalCmd.setCommandOutput = result;
}



if(rootCmd == "mv"){
const result = await this._terminaCommandsImpl.mv(cmdStringArr[1], cmdStringArr[2]);
terminalCmd.setResponseCode = this.Success;
terminalCmd.setCommandOutput = result;
}

if (rootCmd == "cp"){

const option = cmdStringArr[1];
Expand Down

0 comments on commit 7126b80

Please sign in to comment.