Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

fix: resolves broken device settings

towfiqif05d704dcd86
diff --git a/backend/src/managers/BaseSystemManager.ts b/backend/src/managers/BaseSystemManager.ts
index 022c0be..7f773b6 100644
--- a/backend/src/managers/BaseSystemManager.ts
+++ b/backend/src/managers/BaseSystemManager.ts
@@ -13,7 +13,11 @@ import { DeviceSettings, DiscoveredFilesystem, LsblkDevice, LsblkOutput } from '
import { BaseStorageManager } from './BaseStorageManager';
import { runCommand } from '../utils/runCommand';
import { appPaths } from '../utils/AppPaths';
-import { saveRcloneGlobalSettings, saveResticGlobalSettings } from '../utils/globalSettings';
+import {
+ saveGeneralDeviceSettings,
+ saveRcloneGlobalSettings,
+ saveResticGlobalSettings,
+} from '../utils/globalSettings';
import { isLinuxInstalledRuntime, runHelper } from '../utils/linuxHelper';
const execAsync = promisify(exec);
@@ -710,6 +714,11 @@ export class BaseSystemManager {
saveRcloneGlobalSettings(deviceSettings.rclone);
}
+ // Persist general device settings to data/config/device_settings.json
+ if (deviceSettings.general) {
+ saveGeneralDeviceSettings(deviceSettings.general);
+ }
+
return {
success: true,
result: 'Global rclone/restic settings updated successfully!',
diff --git a/backend/src/services/DeviceService.ts b/backend/src/services/DeviceService.ts
index 2b7d0ff..9ccd50f 100644
--- a/backend/src/services/DeviceService.ts
+++ b/backend/src/services/DeviceService.ts
@@ -143,7 +143,7 @@ export class DeviceService {
}
if (data.settings) {
- if (existingDevice.id !== 'main') {
+ if (existingDevice.id === 'main') {
try {
const strategy = this.getSystemStrategy(id);
const updateResp = await strategy.updateSettings(data.settings);
diff --git a/backend/src/types/devices.ts b/backend/src/types/devices.ts
index bac5c3d..fa132c9 100644
--- a/backend/src/types/devices.ts
+++ b/backend/src/types/devices.ts
@@ -1,5 +1,7 @@
export interface DeviceSettings {
- tempDir: string;
+ general?: {
+ tempDir: string; // Temporary directory for both restic and rclone. If set, it overrides the individual tempDir settings for restic and rclone.
+ };
restic?: {
maxProcessor: number; // GOMAXPROCS
cacheDir: string; // RESTIC_CACHE_DIR
diff --git a/backend/src/utils/AppPaths.ts b/backend/src/utils/AppPaths.ts
index 7b9cbab..64dca2f 100644
--- a/backend/src/utils/AppPaths.ts
+++ b/backend/src/utils/AppPaths.ts
@@ -2,6 +2,7 @@ import path from 'path';
import os from 'os';
import fs from 'fs'; // Use the synchronous fs module
import { isLinuxInstalledRuntime } from './linuxHelper';
+import { DeviceSettings } from '../types/devices';
/**
* Defines the structure for all application paths.
@@ -109,7 +110,9 @@ class AppPaths {
}
const baseDir = this.getTheBaseDir();
- const tempBase = this.isLinuxRuntime ? baseDir : os.tmpdir();
+ const deviceTempDir = this.loadGeneralDeviceSettings(baseDir)?.tempDir;
+ const defaultTempDir = this.isLinuxRuntime ? baseDir : os.tmpdir();
+ const tempBase = deviceTempDir || defaultTempDir;
this.paths = {
base: baseDir,
@@ -119,7 +122,7 @@ class AppPaths {
logs: path.join(baseDir, 'logs'),
progress: path.join(baseDir, 'progress'),
stats: path.join(baseDir, 'stats'),
- temp: this.isLinuxRuntime ? path.join(baseDir, 'temp') : path.join(tempBase, 'pluton'),
+ temp: path.join(tempBase, 'pluton'),
cache: path.join(tempBase, 'pluton', 'cache'),
downloads: path.join(tempBase, 'pluton', 'downloads'),
restores: path.join(tempBase, 'pluton', 'restores'),
@@ -179,6 +182,22 @@ class AppPaths {
}
}
+ private loadGeneralDeviceSettings(baseDir: string): DeviceSettings['general'] | undefined {
+ if (this.isInitialized) {
+ return;
+ }
+ const filePath = path.join(baseDir, 'config', 'device_settings.json'); // ← use baseDir
+ try {
+ if (fs.existsSync(filePath)) {
+ const raw = fs.readFileSync(filePath, 'utf-8');
+ const parsed = JSON.parse(raw) as DeviceSettings['general'];
+ return parsed;
+ }
+ } catch (error) {
+ // console.error('[globalSettings] Failed to read device_settings.json:', error);
+ }
+ return undefined;
+ }
// --- GETTER METHODS ---
public getBaseDir(): string {
this.checkInitialized();
diff --git a/backend/src/utils/globalSettings.ts b/backend/src/utils/globalSettings.ts
index c7281bb..1f635d7 100644
--- a/backend/src/utils/globalSettings.ts
+++ b/backend/src/utils/globalSettings.ts
@@ -16,6 +16,7 @@ import { DeviceSettings } from '../types/devices';
const getRcloneSettingsPath = () => path.join(appPaths.getConfigDir(), 'rclone_global.json');
const getResticSettingsPath = () => path.join(appPaths.getConfigDir(), 'restic_global.json');
+const getGeneralSettingsPath = () => path.join(appPaths.getConfigDir(), 'device_settings.json');
// ---------- In-memory caches ----------
@@ -46,6 +47,15 @@ export function saveResticGlobalSettings(settings: DeviceSettings['restic']): vo
resticSettingsCache = settings ?? null;
}
+/**
+ * Persist general device settings to `data/config/device_settings.json`.
+ * Only creates the file when the user explicitly changes settings.
+ */
+export function saveGeneralDeviceSettings(settings: DeviceSettings['general']): void {
+ const filePath = getGeneralSettingsPath();
+ fs.writeFileSync(filePath, JSON.stringify(settings, null, 2), { mode: 0o600 });
+}
+
// ---------- Read helpers (called from runRcloneCommand / runResticCommand) ----------
/**
@@ -96,6 +106,24 @@ export function loadResticGlobalSettings(): DeviceSettings['restic'] | undefined
return undefined;
}
+/**
+ * Load general device settings. Returns `undefined` if no settings file exists.
+ * This is not cached in memory because it's only used for initial device setup and is expected to be small.
+ */
+export function loadGeneralDeviceSettings(): DeviceSettings['general'] | undefined {
+ const filePath = getGeneralSettingsPath();
+ try {
+ if (fs.existsSync(filePath)) {
+ const raw = fs.readFileSync(filePath, 'utf-8');
+ const parsed = JSON.parse(raw) as DeviceSettings['general'];
+ return parsed;
+ }
+ } catch (error) {
+ // console.error('[globalSettings] Failed to read device_settings.json:', error);
+ }
+ return undefined;
+}
+
// ---------- Env / args builders for command runners ----------
/**
diff --git a/frontend/src/@types/devices.ts b/frontend/src/@types/devices.ts
index f3b0691..a2ee03c 100644
--- a/frontend/src/@types/devices.ts
+++ b/frontend/src/@types/devices.ts
@@ -34,9 +34,7 @@ export interface Device {
plans: PlanChildItem[];
tags: string[];
metrics: DeviceMetrics | null;
- settings: {
- tempDir: string;
- };
+ settings: DeviceSettings | null;
}
export interface DeviceMetrics {
@@ -195,7 +193,9 @@ export interface DeviceMetrics {
}
export interface DeviceSettings {
- tempDir?: string;
+ general?: {
+ tempDir?: string; // Temporary directory for both restic and rclone. If set, it overrides the individual tempDir settings for restic and rclone.
+ };
restic?: {
maxProcessor?: number | ''; // GOMAXPROCS
cacheDir?: string; // RESTIC_CACHE_DIR
diff --git a/frontend/src/components/Device/EditDevice/EditDevice.tsx b/frontend/src/components/Device/EditDevice/EditDevice.tsx
index bf7632c..10c6125 100644
--- a/frontend/src/components/Device/EditDevice/EditDevice.tsx
+++ b/frontend/src/components/Device/EditDevice/EditDevice.tsx
@@ -107,8 +107,13 @@ const EditDevice = ({ close, device }: EditDeviceProps) => {
<div className={classes.field}>
<Input
label="Temporary Working Directory"
- fieldValue={newDevice.settings?.tempDir || ''}
- onUpdate={(val) => setNewDevice({ ...newDevice, settings: { ...newDevice.settings, tempDir: val } })}
+ fieldValue={newDevice.settings?.general?.tempDir || ''}
+ onUpdate={(val) =>
+ setNewDevice({
+ ...newDevice,
+ settings: { ...newDevice.settings, general: { ...newDevice.settings?.general, tempDir: val } },
+ })
+ }
full={true}
hint="Where the backup, restores and downloads will be temporarily stored."
/>
@@ -142,9 +147,11 @@ const EditDevice = ({ close, device }: EditDeviceProps) => {
<FolderPicker
deviceId={device.id}
title="Select Temporary Working Directory"
- selected={newDevice.settings?.tempDir || ''}
+ selected={newDevice.settings?.general?.tempDir || ''}
close={() => setShowFileManager(false)}
- onSelect={(val) => setNewDevice({ ...newDevice, settings: { ...newDevice.settings, tempDir: val } })}
+ onSelect={(val) =>
+ setNewDevice({ ...newDevice, settings: { ...newDevice.settings, general: { ...newDevice.settings?.general, tempDir: val } } })
+ }
/>
)}
</SidePanel>