diff --git a/src/app/shared/system-service/file.service.ts b/src/app/shared/system-service/file.service.ts index 7035ee7c..ee701132 100644 --- a/src/app/shared/system-service/file.service.ts +++ b/src/app/shared/system-service/file.service.ts @@ -71,8 +71,8 @@ export class FileService{ const interval = setInterval(() => { fs.readdir(dirPath, function(err, files) { if(err){ - console.log("Oops! a boo boo happened, filesystem wasn't ready:", err) - reject(err) + console.log("Oops! a boo boo happened, filesystem wasn't ready:", err); + reject(err); }else{ clearInterval(interval); resolve(files); @@ -90,7 +90,7 @@ export class FileService{ resolve(true) }else{ console.log('checkIfFileOrFolderExistsAsync :Does not exists',exits); - resolve(false) + resolve(false); } }); }) @@ -209,28 +209,33 @@ export class FileService{ return this._fileInfo; } - public async createFolderAsync(directory:string, fileName:string):Promise{ - new Promise((resolve, reject) =>{ + public async createFolderAsync(directory:string, fileName:string):Promise{ + return new Promise((resolve, reject) =>{ this._fileSystem.exists(`${directory}/${fileName}`, (exists) =>{ if(exists){ console.log('createFolderAsync: folder already exists',exists); + resolve(false); }else{ this._fileSystem.mkdir(`${directory}/${fileName}`,'0777',(err) =>{ if(err){ console.log('createFolderAsync Error: folder creation',err); - reject(err); + reject(false); } - resolve(); + this.dirFilesUpdateNotify.next(); + resolve(true); }); } }); - }).then(()=>{ - //Send update notification - this.dirFilesUpdateNotify.next(); - }); + }) + + // .then(()=>{ + // //Send update notification + // this.dirFilesUpdateNotify.next(); + // }); } + public async getFolderAsync(path: string) { await this.initBrowserFsAsync(); diff --git a/src/app/system-apps/terminal/terminal.commands.ts b/src/app/system-apps/terminal/terminal.commands.ts index d775179c..a4dd3395 100644 --- a/src/app/system-apps/terminal/terminal.commands.ts +++ b/src/app/system-apps/terminal/terminal.commands.ts @@ -477,8 +477,25 @@ ${this.addspaces(strPermission,10)} ${this.addspaces('Terminal',8)} ${this.addsp return dirPath.replace(',',''); } - async mkdir(arg0:string):Promise{ - 1 + async mkdir(arg0:string, arg1:string):Promise{ + + const forbiddenChars:string[]= [ '\\', '/',':','*','?',' "', '<', '>', '|']; + + if(arg0 && !forbiddenChars.includes(arg0)){ + const folderName = arg0; + const result = await this._fileService.createFolderAsync(this.currentDirectoryPath, folderName);//.then(()=>{ }) + if(result){ + if(arg1 && arg1 == '-v'){ + return `folder: ${arg0} successfully created`; + } + } + }else{ + return ` +usage: mkdir direcotry_name [-v] + `; + } + + return ''; } async mv(arg0:string):Promise{ diff --git a/src/app/system-apps/terminal/terminal.component.ts b/src/app/system-apps/terminal/terminal.component.ts index 9e6b943c..db6060fa 100644 --- a/src/app/system-apps/terminal/terminal.component.ts +++ b/src/app/system-apps/terminal/terminal.component.ts @@ -581,6 +581,12 @@ export class TerminalComponent implements BaseComponent, OnInit, AfterViewInit, this.fetchedDirectoryList = [...result.result]; } } + + if(rootCmd == "mkdir"){ + const result = await this._terminaCommandsImpl.mkdir(cmdStringArr[1], cmdStringArr[2]); + terminalCmd.setResponseCode = this.Success; + terminalCmd.setCommandOutput = result; + } }else{ terminalCmd.setResponseCode = this.Fail;