mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
directory cleanup on startup
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
"express-basic-auth": "^1.2.0",
|
||||
"express-fileupload": "^1.2.0",
|
||||
"find-free-port": "^2.0.0",
|
||||
"find-remove": "^2.0.3",
|
||||
"fs-extra": "^8.1.0",
|
||||
"http": "^0.0.0",
|
||||
"line-reader": "^0.4.0",
|
||||
|
||||
11
packages/api/src/utility/cleanDirectory.js
Normal file
11
packages/api/src/utility/cleanDirectory.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const findRemoveSync = require('find-remove');
|
||||
|
||||
function cleanDirectory(directory) {
|
||||
findRemoveSync(directory, {
|
||||
age: { seconds: 3600 },
|
||||
files: '*.*',
|
||||
dir: '*',
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = cleanDirectory;
|
||||
@@ -1,11 +1,15 @@
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const cleanDirectory = require('./cleanDirectory');
|
||||
|
||||
const createDirectories = {};
|
||||
|
||||
const ensureDirectory = (dir) => {
|
||||
const ensureDirectory = (dir, clean) => {
|
||||
if (!createDirectories[dir]) {
|
||||
if (clean && fs.existsSync(dir)) {
|
||||
console.log(`Cleaning directory ${dir}`);
|
||||
cleanDirectory(dir);
|
||||
}
|
||||
if (!fs.existsSync(dir)) {
|
||||
console.log(`Creating directory ${dir}`);
|
||||
fs.mkdirSync(dir);
|
||||
@@ -21,16 +25,16 @@ function datadir() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
const dirFunc = (dirname) => () => {
|
||||
const dirFunc = (dirname, clean = false) => () => {
|
||||
const dir = path.join(datadir(), dirname);
|
||||
ensureDirectory(dir);
|
||||
ensureDirectory(dir, clean);
|
||||
|
||||
return dir;
|
||||
};
|
||||
|
||||
const jsldir = dirFunc('jsl');
|
||||
const rundir = dirFunc('run');
|
||||
const uploadsdir = dirFunc('uploads');
|
||||
const jsldir = dirFunc('jsl', true);
|
||||
const rundir = dirFunc('run', true);
|
||||
const uploadsdir = dirFunc('uploads', true);
|
||||
const archivedir = dirFunc('archive');
|
||||
|
||||
module.exports = {
|
||||
|
||||
15
yarn.lock
15
yarn.lock
@@ -5291,6 +5291,14 @@ find-free-port@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/find-free-port/-/find-free-port-2.0.0.tgz#4b22e5f6579eb1a38c41ac6bcb3efed1b6da9b1b"
|
||||
integrity sha1-SyLl9leesaOMQaxryz7+0bbamxs=
|
||||
|
||||
find-remove@^2.0.3:
|
||||
version "2.0.3"
|
||||
resolved "https://registry.yarnpkg.com/find-remove/-/find-remove-2.0.3.tgz#46e1cb12ca247963bc594c3af4c4878ba2244a79"
|
||||
integrity sha512-T7v/mSYhz2mv3ZM37BJH6Ny9tudA1qjJtH9N8MAZQKskJ546ciyMjPxsT7N/9OcbpN9+vfxMNHefzLbXOdMrhQ==
|
||||
dependencies:
|
||||
fmerge "1.2.0"
|
||||
rimraf "3.0.2"
|
||||
|
||||
find-root@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/find-root/-/find-root-1.1.0.tgz#abcfc8ba76f708c42a97b3d685b7e9450bfb9ce4"
|
||||
@@ -5379,6 +5387,11 @@ flux@^3.1.3:
|
||||
fbemitter "^2.0.0"
|
||||
fbjs "^0.8.0"
|
||||
|
||||
fmerge@1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/fmerge/-/fmerge-1.2.0.tgz#36e99d2ae255e3ee1af666b4df780553671cf692"
|
||||
integrity sha1-NumdKuJV4+4a9ma033gFU2cc9pI=
|
||||
|
||||
follow-redirects@1.5.10:
|
||||
version "1.5.10"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
|
||||
@@ -10684,7 +10697,7 @@ rimraf@2.6.3:
|
||||
dependencies:
|
||||
glob "^7.1.3"
|
||||
|
||||
rimraf@^3.0.0:
|
||||
rimraf@3.0.2, rimraf@^3.0.0:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
|
||||
integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
|
||||
|
||||
Reference in New Issue
Block a user