Merge pull request #2105 from isaac-mcfadyen/fs-renamefile-fix

Changed fs.renameSync() to fs.copyFileSync()
This commit is contained in:
Cohee 2024-04-19 01:13:50 +03:00 committed by GitHub
commit d6fd351330
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 24 additions and 8 deletions

View File

@ -60,7 +60,8 @@ function convertConfig() {
try {
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'));
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));
console.log(color.green('Conversion successful. Please check your config.yaml and fix it if necessary.'));
} catch (error) {

View File

@ -227,7 +227,8 @@ router.post('/download', jsonParser, async (request, response) => {
// Move into asset place
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);
}
catch (error) {

View File

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

View File

@ -680,7 +680,8 @@ router.post('/rename', jsonParser, async function (request, response) {
// Rename chats folder
if (fs.existsSync(oldChatsPath) && !fs.existsSync(newChatsPath)) {
fs.renameSync(oldChatsPath, newChatsPath);
fs.cpSync(oldChatsPath, newChatsPath, { recursive: true });
fs.rmSync(oldChatsPath, { recursive: true, force: true });
}
// 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 });
}
fs.copyFileSync(pathToOriginalFile, pathToRenamedFile);
fs.rmSync(pathToOriginalFile);
console.log('Successfully renamed.');
fs.renameSync(pathToOriginalFile, pathToRenamedFile);
return response.send({ ok: true });
});

View File

@ -286,12 +286,22 @@ async function migrateUserData() {
// Copy the file to the new location
fs.cpSync(migration.old, migration.new, { force: true });
// 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)),
{ recursive: true, force: true }
);
fs.rmSync(migration.old, { recursive: true, force: true });
} else {
// Copy the directory to the new location
fs.cpSync(migration.old, migration.new, { recursive: true, force: true });
// 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)),
{ recursive: true, force: true }
);
fs.rmSync(migration.old, { recursive: true, force: true });
}
} catch (error) {
console.error(color.red(`Error migrating ${migration.old} to ${migration.new}:`), error.message);