mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Move setPermissionsSync to util
This commit is contained in:
@@ -7,7 +7,7 @@ import fetch from 'node-fetch';
|
|||||||
import sanitize from 'sanitize-filename';
|
import sanitize from 'sanitize-filename';
|
||||||
import { sync as writeFileAtomicSync } from 'write-file-atomic';
|
import { sync as writeFileAtomicSync } from 'write-file-atomic';
|
||||||
|
|
||||||
import { getConfigValue, color } from '../util.js';
|
import { getConfigValue, color, setPermissionsSync } from '../util.js';
|
||||||
import { write } from '../character-card-parser.js';
|
import { write } from '../character-card-parser.js';
|
||||||
import { serverDirectory } from '../server-directory.js';
|
import { serverDirectory } from '../server-directory.js';
|
||||||
|
|
||||||
@@ -149,29 +149,6 @@ async function seedContentForUser(contentIndex, directories, forceCategories) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fs.cpSync(contentPath, targetPath, { recursive: true, force: false });
|
fs.cpSync(contentPath, targetPath, { recursive: true, force: false });
|
||||||
function setPermissionsSync(targetPath_) {
|
|
||||||
|
|
||||||
function appendWritablePermission(filepath, stats) {
|
|
||||||
const currentMode = stats.mode;
|
|
||||||
const newMode = currentMode | 0o200;
|
|
||||||
if (newMode != currentMode) {
|
|
||||||
fs.chmodSync(filepath, newMode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const stats = fs.statSync(targetPath_);
|
|
||||||
|
|
||||||
if (stats.isDirectory()) {
|
|
||||||
appendWritablePermission(targetPath_, stats);
|
|
||||||
const files = fs.readdirSync(targetPath_);
|
|
||||||
|
|
||||||
files.forEach((file) => {
|
|
||||||
setPermissionsSync(path.join(targetPath_, file));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
appendWritablePermission(targetPath_, stats);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setPermissionsSync(targetPath);
|
setPermissionsSync(targetPath);
|
||||||
console.info(`Content file ${contentItem.filename} copied to ${contentTarget}`);
|
console.info(`Content file ${contentItem.filename} copied to ${contentTarget}`);
|
||||||
anyContentAdded = true;
|
anyContentAdded = true;
|
||||||
|
36
src/util.js
36
src/util.js
@@ -1087,3 +1087,39 @@ export function mutateJsonString(jsonString, mutation) {
|
|||||||
return jsonString;
|
return jsonString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the permissions of a file or directory to be writable.
|
||||||
|
* @param {string} targetPath Path to the file or directory
|
||||||
|
*/
|
||||||
|
export function setPermissionsSync(targetPath) {
|
||||||
|
/**
|
||||||
|
* Appends writable permission to the file mode.
|
||||||
|
* @param {string} filePath Path to the file
|
||||||
|
* @param {fs.Stats} stats File stats
|
||||||
|
*/
|
||||||
|
function appendWritablePermission(filePath, stats) {
|
||||||
|
const currentMode = stats.mode;
|
||||||
|
const newMode = currentMode | 0o200;
|
||||||
|
if (newMode != currentMode) {
|
||||||
|
fs.chmodSync(filePath, newMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const stats = fs.statSync(targetPath);
|
||||||
|
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
appendWritablePermission(targetPath, stats);
|
||||||
|
const files = fs.readdirSync(targetPath);
|
||||||
|
|
||||||
|
files.forEach((file) => {
|
||||||
|
setPermissionsSync(path.join(targetPath, file));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
appendWritablePermission(targetPath, stats);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error setting write permissions for ${targetPath}:`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user