Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
TreeStabilizer.prototype.rebuild = function () {
fs.rmdirSync(this.outputPath);
// TODO: investigate if we can use rename the directory instead to improve performance on
// Windows
symlinkOrCopy.sync(this.inputPath, this.outputPath);
};
TreeStabilizer.prototype.cleanup = function () { };
var rmAllDirs = (path) => {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file) {
var curPath = path + '/' + file;
if (fs.lstatSync(curPath).isDirectory()) { // recurse
rmAllDirs(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
var deleteDirectory = function(path) {
var files = [];
if( fs.existsSync(path) ) {
files = fs.readdirSync(path);
files.forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteDirectory(curPath);
}
else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
const removeDirectory = (dirPath: string): void => {
if (!existsSync(dirPath)) {
return
}
const files = readdirSync(dirPath)
for (const file of files) {
const filePath = join(dirPath, file)
statSync(filePath).isFile() ? unlinkSync(filePath) : removeDirectory(filePath)
}
rmdirSync(dirPath)
}
function rimraf(dir_path) {
if (fs.existsSync(dir_path)) {
fs.readdirSync(dir_path).forEach(function(entry) {
let entry_path = path.join(dir_path, entry);
if (fs.lstatSync(entry_path).isDirectory()) {
rimraf(entry_path);
} else {
fs.unlinkSync(entry_path);
console.log("delete file : " + entry_path);
}
});
fs.rmdirSync(dir_path);
}
}
try {
files = fs.readdirSync(dirPath);
} catch (e) {
return;
}
if (files.length > 0) {
for (var i = 0; i < files.length; i++) {
var filePath = dirPath + '/' + files[i];
if (fs.statSync(filePath).isFile()) {
fs.unlinkSync(filePath);
} else {
cleanDirectory(filePath);
}
}
}
fs.rmdirSync(dirPath);
}
_rmDir = function (dirPath) {
var dir = path.normalize(dirPath)
, paths = [];
paths = fs.readdirSync(dir);
paths.forEach(function (p) {
var curr = path.join(dir, p);
var stat = fs.statSync(curr);
if (stat.isDirectory()) {
_rmDir(curr);
}
else {
fs.unlinkSync(curr);
}
});
fs.rmdirSync(dir);
};
filenames = fs.readdirSync(dirPath);
} catch (err) {
return;
}
for (const filename of filenames) {
const filePath = path.join(dirPath, filename);
if (fs.statSync(filePath).isFile()) {
fs.unlinkSync(filePath);
} else {
rmDirSync(filePath);
}
}
fs.rmdirSync(dirPath);
}
destroy: function() {
if (this.localStorage) {
this.localStorage.clear();
if (corbel.Config.isNode) {
var fs = require('fs');
try {
fs.rmdirSync(corbel.Session.SESSION_PATH_DIR + '/' + this.driver.guid);
} catch (ex) {}
} else {
this.sessionStorage.clear();
}
this.localStorage = null;
}
}
}, {
function deleteFolderRecursive(path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file) {
var curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}