1
0
Fork 0
forked from svrjs/svrjs

Replace __dirname with process.dirname (declared as __dirname in index.js)

This commit is contained in:
Dorian Niemiec 2024-08-24 19:29:12 +02:00
parent 24b161b0ed
commit 11e7247869
4 changed files with 20 additions and 18 deletions

View file

@ -15,10 +15,12 @@ try {
// Don't use inspector
}
process.dirname = __dirname;
// Create log, mods and temp directories, if they don't exist.
if (!fs.existsSync(__dirname + "/log")) fs.mkdirSync(__dirname + "/log");
if (!fs.existsSync(__dirname + "/mods")) fs.mkdirSync(__dirname + "/mods");
if (!fs.existsSync(__dirname + "/temp")) fs.mkdirSync(__dirname + "/temp");
if (!fs.existsSync(process.dirname + "/log")) fs.mkdirSync(process.dirname + "/log");
if (!fs.existsSync(process.dirname + "/mods")) fs.mkdirSync(process.dirname + "/mods");
if (!fs.existsSync(process.dirname + "/temp")) fs.mkdirSync(process.dirname + "/temp");
// TODO: process.singleThreaded flag
process.singleThreaded = true;
@ -102,7 +104,7 @@ if (!process.stdout.isTTY && !inspectorURL) {
var wwwrootError = null;
try {
if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(process.serverConfig.wwwroot != undefined ? process.serverConfig.wwwroot : __dirname);
if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(process.serverConfig.wwwroot != undefined ? process.serverConfig.wwwroot : process.dirname);
} catch (err) {
wwwrootError = err;
}

View file

@ -10,7 +10,7 @@ function getInitializePath(to) {
}
const absoluteTo = path.isAbsolute(to)
? to
: __dirname + (os.platform() == "win32" ? "\\" : "/") + to;
: process.dirname + (os.platform() == "win32" ? "\\" : "/") + to;
if (os.platform() == "win32" && cwd[0] != absoluteTo[0]) return "";
const relative = path.relative(cwd, absoluteTo);
if (os.platform() == "win32") {
@ -95,9 +95,9 @@ if (process.serverConfig.secure) {
}
forbiddenPaths.svrjs = getInitializePath(
"./" +
(__dirname[__dirname.length - 1] != "/"
? __filename.replace(__dirname + "/", "")
: __filename.replace(__dirname, "")),
(process.dirname[process.dirname.length - 1] != "/"
? __filename.replace(process.dirname + "/", "")
: __filename.replace(process.dirname, "")),
);
forbiddenPaths.serverSideScripts = [];
if (process.serverConfig.useWebRootServerSideScript) {

View file

@ -52,10 +52,10 @@ if (!process.singleThreaded) {
os.platform() === "win32"
? path.join(
"\\\\?\\pipe",
__dirname,
process.dirname,
"temp/.W" + process.pid + ".ipc",
)
: __dirname + "/temp/.W" + process.pid + ".ipc",
: process.dirname + "/temp/.W" + process.pid + ".ipc",
);
process.send = function (message) {
@ -64,10 +64,10 @@ if (!process.singleThreaded) {
os.platform() === "win32"
? path.join(
"\\\\?\\pipe",
__dirname,
process.dirname,
"temp/.P" + process.pid + ".ipc",
)
: __dirname + "/temp/.P" + process.pid + ".ipc",
: process.dirname + "/temp/.P" + process.pid + ".ipc",
function () {
fakeIPCConnection.end(message);
},
@ -159,10 +159,10 @@ if (!process.singleThreaded) {
os.platform() === "win32"
? path.join(
"\\\\?\\pipe",
__dirname,
process.dirname,
"temp/.P" + newWorker.process.pid + ".ipc",
)
: __dirname + "/temp/.P" + newWorker.process.pid + ".ipc",
: process.dirname + "/temp/.P" + newWorker.process.pid + ".ipc",
);
// Cleanup when worker process exits
@ -186,10 +186,10 @@ if (!process.singleThreaded) {
os.platform() === "win32"
? path.join(
"\\\\?\\pipe",
__dirname,
process.dirname,
"temp/.W" + newWorker.process.pid + ".ipc",
)
: __dirname + "/temp/.W" + newWorker.process.pid + ".ipc",
: process.dirname + "/temp/.W" + newWorker.process.pid + ".ipc",
function () {
fakeWorkerIPCConnection.end(message);
},

View file

@ -13,7 +13,7 @@ function LOG(s) {
if (enableLoggingIntoFile) {
if (logSync) {
fs.appendFileSync(
__dirname +
process.dirname +
"/log/" +
(cluster.isPrimary
? "master"
@ -28,7 +28,7 @@ function LOG(s) {
} else {
if (!logFile) {
logFile = fs.createWriteStream(
__dirname +
process.dirname +
"/log/" +
(cluster.isPrimary
? "master"