Skip to content

Commit

Permalink
duplication clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Rıza Kat committed Aug 14, 2024
1 parent 5492956 commit 4b81696
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions lib/countly-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,33 @@ var defaultBulkPath = "../bulk_data/"; // Default path

var setStoragePath = function(userPath) {
storagePath = userPath || defaultPath;

var dir = path.resolve(__dirname, getStoragePath());
try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}
catch (ex) {
// problem creating data dir
cc.log(cc.logLevelEnums.ERROR, `setStoragePath, Failed to create the '/data' folder: ${ex}`);
}
createDirectory(dir);
};

var setBulkDataPath = function(userPath, persistQueue) {
storagePath = userPath || defaultBulkPath;
var mainDir = path.resolve(__dirname, getStoragePath());
var dir = path.resolve(__dirname, getStoragePath());
if (persistQueue) {
try {
if (!fs.existsSync(mainDir)) {
fs.mkdirSync(mainDir);
}
}
catch (ex) {
// problem creating directory
// eslint-disable-next-line no-console
cc.log(cc.logLevelEnums.ERROR, "setBulkDataPath, Failed white creating the '/data' directory. Error: ", ex.stack);
}
createDirectory(dir);
}
};

var getStoragePath = function() {
return storagePath;
};

var createDirectory = function(dir) {
try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}
catch (ex) {
cc.log(cc.logLevelEnums.ERROR, `Failed to create directory at ${dir}: ${ex.stack}`);
}
};

var resetStorage = function() {
storagePath = undefined;
__data = {};
Expand Down

0 comments on commit 4b81696

Please sign in to comment.