Skip to content

Commit

Permalink
Adjusted backup folder to be inside profiles folder
Browse files Browse the repository at this point in the history
Adjusted writer code to save profiles into subfolder
  • Loading branch information
Chomp committed Dec 13, 2024
1 parent def0e29 commit e6d070c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion project/assets/configs/backup.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"enabled": true,
"maxBackups": 10,
"directory": "./user/backups/profiles",
"directory": "./user/profiles/backups",
"dateFormat": "YYYY-MM-DD_HH-MM-SS",
"backupInterval": {
"enabled": true,
Expand Down
13 changes: 9 additions & 4 deletions project/src/services/BackupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export class BackupService {

let currentProfiles: string[] = [];
try {
currentProfiles = await fs.readdir(this.profileDir);
// Ensure only JSON files are being backed up
currentProfiles = currentProfiles.filter((profileName: string) => profileName.endsWith(".json"));
// Get profiles that end in .json
currentProfiles = (await fs.readdir(this.profileDir)).filter((profileName: string) =>
profileName.endsWith(".json"),
);
} catch (error) {
this.logger.error(`Unable to read profiles directory: ${error.message}`);
return;
Expand All @@ -45,7 +46,11 @@ export class BackupService {
}

try {
await fs.copy(this.profileDir, targetDir);
// iterate over each profile found and save it into backup folder
for (const profileToCopy of currentProfiles) {
await fs.copy(path.join(this.profileDir, profileToCopy), path.join(targetDir, profileToCopy));
}
// TODO - write json with list of active mods to same folder as profile
} catch (error) {
this.logger.error(`Unable to write to backup profile directory: ${error.message}`);
return;
Expand Down

0 comments on commit e6d070c

Please sign in to comment.