// Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another
// program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del.
try{
if(yieldioUtil.isDirectory(inputPath,true)){
yieldexec(`rd /s /q "${inputPath}"`);
}
else{
yieldexec(`del /f /a "${inputPath}"`);
}
}
catch(err){
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if(err.code!=='ENOENT')
throwerr;
}
// Shelling out fails to remove a symlink folder with missing source, this unlink catches that
try{
yieldioUtil.unlink(inputPath);
}
catch(err){
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if(err.code!=='ENOENT')
throwerr;
}
}
else{
letisDir=false;
try{
isDir=yieldioUtil.isDirectory(inputPath);
}
catch(err){
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if(err.code!=='ENOENT')
throwerr;
return;
}
if(isDir){
yieldexec(`rm -rf "${inputPath}"`);
}
else{
yieldioUtil.unlink(inputPath);
}
}
});
}
exports.rmRF=rmRF;
/**
* Make a directory. Creates the full path with folders in between
* Will throw if it fails
*
* @param fsPath path to create
* @returns Promise<void>
*/
functionmkdirP(fsPath){
return__awaiter(this,void0,void0,function*(){
yieldioUtil.mkdirP(fsPath);
});
}
exports.mkdirP=mkdirP;
/**
* Returns path of a tool had the tool actually been invoked. Resolves via paths.
* If you check and the tool does not exist, it will throw.
*
* @param tool name of the tool
* @param check whether to check if tool exists
* @returns Promise<string> path to tool
*/
functionwhich(tool,check){
return__awaiter(this,void0,void0,function*(){
if(!tool){
thrownewError("parameter 'tool' is required");
}
// recursive when check=true
if(check){
constresult=yieldwhich(tool,false);
if(!result){
if(ioUtil.IS_WINDOWS){
thrownewError(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.`);
}
else{
thrownewError(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`);