Skip to content

Commit

Permalink
Remove unreliable settings backup
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Nov 15, 2024
1 parent 6f00252 commit 752ae0e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
15 changes: 2 additions & 13 deletions src/config/comfyConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,12 @@ export class ComfyConfigManager {
}
this.createComfyDirectories(localComfyDirectory);
const userSettingsPath = path.join(localComfyDirectory, 'user', 'default');
this.createComfyConfigFile(userSettingsPath, true);
this.createComfyConfigFile(userSettingsPath);
}

public static createComfyConfigFile(userSettingsPath: string, overwrite: boolean = false): void {
public static createComfyConfigFile(userSettingsPath: string): void {
const configFilePath = path.join(userSettingsPath, 'comfy.settings.json');

if (fs.existsSync(configFilePath) && overwrite) {
const backupFilePath = path.join(userSettingsPath, 'old_comfy.settings.json');
try {
fs.renameSync(configFilePath, backupFilePath);
log.info(`Renaming existing user settings file to: ${backupFilePath}`);
} catch (error) {
log.error(`Failed to backup existing user settings file: ${error}`);
return;
}
}

try {
fs.writeFileSync(configFilePath, JSON.stringify(this.DEFAULT_CONFIG, null, 2));
log.info(`Created new ComfyUI config file at: ${configFilePath}`);
Expand Down
24 changes: 1 addition & 23 deletions tests/unit/comfyConfigManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,11 @@ describe('ComfyConfigManager', () => {
it('should create new config file when none exists', () => {
(fs.existsSync as jest.Mock).mockReturnValue(false);

ComfyConfigManager.createComfyConfigFile('/fake/path', false);
ComfyConfigManager.createComfyConfigFile('/fake/path');

expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
expect(fs.renameSync).not.toHaveBeenCalled();
});

it('should backup existing config file when overwrite is true', () => {
(fs.existsSync as jest.Mock).mockImplementation((path: string) => {
return path === '/user/default/comfy.settings.json';
});

ComfyConfigManager.createComfyConfigFile('/user/default', true);

expect(fs.renameSync).toHaveBeenCalledTimes(1);
expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
});

it('should handle backup failure gracefully', () => {
(fs.existsSync as jest.Mock).mockReturnValue(true);
(fs.renameSync as jest.Mock).mockImplementation(() => {
throw new Error('Backup failed');
});

ComfyConfigManager.createComfyConfigFile('/fake/path', true);

expect(fs.writeFileSync).not.toHaveBeenCalled();
});
});

describe('createNestedDirectories', () => {
Expand Down

0 comments on commit 752ae0e

Please sign in to comment.