diff --git a/src/app/system-apps/terminal/terminal.commands.ts b/src/app/system-apps/terminal/terminal.commands.ts index b169bc9a..dc10c523 100644 --- a/src/app/system-apps/terminal/terminal.commands.ts +++ b/src/app/system-apps/terminal/terminal.commands.ts @@ -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 ` @@ -495,10 +494,79 @@ usage: mkdir direcotry_name [-v] return ''; } - async mv(arg0:string, arg1:string):Promise{ - 1 + async mv(sourceArg:string, destinationArg:string):Promise{ + + 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{ + + 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{ console.log(`source ${optionArg}`); @@ -557,7 +625,7 @@ 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{ @@ -565,7 +633,7 @@ Mandatory argument to long options are mandotory for short options too. //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 ''; @@ -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 ''; @@ -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{ diff --git a/src/app/system-apps/terminal/terminal.component.ts b/src/app/system-apps/terminal/terminal.component.ts index 17c2bd88..0e0a6fc6 100644 --- a/src/app/system-apps/terminal/terminal.component.ts +++ b/src/app/system-apps/terminal/terminal.component.ts @@ -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];