Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function Storage(dir, filters) {
var self = this;
if (!(self instanceof Storage)) {
return new Storage(dir, filters);
}
var backupDir = path.join(dir, '.backup');
fse.ensureDirSync(dir);
fse.ensureDirSync(backupDir);
self._backupDir = backupDir;
self._files = path.join(dir, 'files');
self._properties = path.join(dir, 'properties');
self._backupProps = path.join(backupDir, 'properties');
fse.ensureDirSync(self._files);
fse.ensureFileSync(self._properties);
var maxIndex = -1;
var files = {};
var fileNames = { properties: true };
filters = filters || {};
fs.readdirSync(self._files).forEach(function(file) {
if (!/^(\d+)\.(.+)$/.test(file)) {
return;
}
var index = parseInt(RegExp.$1, 10);
var filename = RegExp.$2;
try {
filename = decodeURIComponent(filename);
} catch(e) {
logger.error(e);