Switched fs.renameSync to fs.copyFileSync

This commit is contained in:
Isaac McFadyen 2024-04-18 15:50:27 -04:00
parent 59bb04f1b3
commit 3822ae9356
No known key found for this signature in database
6 changed files with 16 additions and 8 deletions

View File

@ -60,7 +60,8 @@ function convertConfig() {
try { try {
console.log(color.blue('Converting config.conf to config.yaml. Your old config.conf will be renamed to config.conf.bak')); console.log(color.blue('Converting config.conf to config.yaml. Your old config.conf will be renamed to config.conf.bak'));
const config = require(path.join(process.cwd(), './config.conf')); const config = require(path.join(process.cwd(), './config.conf'));
fs.renameSync('./config.conf', './config.conf.bak'); fs.copyFileSync('./config.conf', './config.conf.bak');
fs.rmSync('./config.conf');
fs.writeFileSync('./config.yaml', yaml.stringify(config)); fs.writeFileSync('./config.yaml', yaml.stringify(config));
console.log(color.green('Conversion successful. Please check your config.yaml and fix it if necessary.')); console.log(color.green('Conversion successful. Please check your config.yaml and fix it if necessary.'));
} catch (error) { } catch (error) {

View File

@ -227,7 +227,8 @@ router.post('/download', jsonParser, async (request, response) => {
// Move into asset place // Move into asset place
console.debug('Download finished, moving file from', temp_path, 'to', file_path); console.debug('Download finished, moving file from', temp_path, 'to', file_path);
fs.renameSync(temp_path, file_path); fs.copyFileSync(temp_path, file_path);
fs.rmSync(temp_path);
response.sendStatus(200); response.sendStatus(200);
} }
catch (error) { catch (error) {

View File

@ -51,7 +51,8 @@ router.post('/rename', jsonParser, function (request, response) {
return response.sendStatus(400); return response.sendStatus(400);
} }
fs.renameSync(oldFileName, newFileName); fs.copyFileSync(oldFileName, newFileName);
fs.rmSync(oldFileName);
invalidateThumbnail(request.user.directories, 'bg', request.body.old_bg); invalidateThumbnail(request.user.directories, 'bg', request.body.old_bg);
return response.send('ok'); return response.send('ok');
}); });
@ -63,7 +64,8 @@ router.post('/upload', urlencodedParser, function (request, response) {
const filename = request.file.originalname; const filename = request.file.originalname;
try { try {
fs.renameSync(img_path, path.join(request.user.directories.backgrounds, filename)); fs.copyFileSync(img_path, path.join(request.user.directories.backgrounds, filename));
fs.rmSync(img_path);
invalidateThumbnail(request.user.directories, 'bg', filename); invalidateThumbnail(request.user.directories, 'bg', filename);
response.send(filename); response.send(filename);
} catch (err) { } catch (err) {

View File

@ -680,7 +680,8 @@ router.post('/rename', jsonParser, async function (request, response) {
// Rename chats folder // Rename chats folder
if (fs.existsSync(oldChatsPath) && !fs.existsSync(newChatsPath)) { if (fs.existsSync(oldChatsPath) && !fs.existsSync(newChatsPath)) {
fs.renameSync(oldChatsPath, newChatsPath); fs.cpSync(oldChatsPath, newChatsPath);
fs.rmSync(oldChatsPath, { recursive: true, force: true });
} }
// Remove the old character file // Remove the old character file

View File

@ -213,8 +213,9 @@ router.post('/rename', jsonParser, async function (request, response) {
return response.status(400).send({ error: true }); return response.status(400).send({ error: true });
} }
fs.copyFileSync(pathToOriginalFile, pathToRenamedFile);
fs.rmSync(pathToOriginalFile);
console.log('Successfully renamed.'); console.log('Successfully renamed.');
fs.renameSync(pathToOriginalFile, pathToRenamedFile);
return response.send({ ok: true }); return response.send({ ok: true });
}); });

View File

@ -286,12 +286,14 @@ async function migrateUserData() {
// Copy the file to the new location // Copy the file to the new location
fs.cpSync(migration.old, migration.new, { force: true }); fs.cpSync(migration.old, migration.new, { force: true });
// Move the file to the backup location // Move the file to the backup location
fs.renameSync(migration.old, path.join(backupDirectory, path.basename(migration.old))); fs.cpSync(migration.old, path.join(backupDirectory, path.basename(migration.old)));
fs.rmSync(migration.old, { recursive: true, force: true });
} else { } else {
// Copy the directory to the new location // Copy the directory to the new location
fs.cpSync(migration.old, migration.new, { recursive: true, force: true }); fs.cpSync(migration.old, migration.new, { recursive: true, force: true });
// Move the directory to the backup location // Move the directory to the backup location
fs.renameSync(migration.old, path.join(backupDirectory, path.basename(migration.old))); fs.cpSync(migration.old, path.join(backupDirectory, path.basename(migration.old)));
fs.rmSync(migration.old, { recursive: true, force: true });
} }
} catch (error) { } catch (error) {
console.error(color.red(`Error migrating ${migration.old} to ${migration.new}:`), error.message); console.error(color.red(`Error migrating ${migration.old} to ${migration.new}:`), error.message);