Skip to content

Commit 9063a9a

Browse files
Y-RyuZUclaude
andcommitted
fix: apply clippy uninlined_format_args fixes
- Fixed all format string to use inline arguments (e.g., format!("{var}") instead of format!("{}", var)) - This is required by newer versions of Clippy in CI - Applied automatically using cargo clippy --fix Co-Authored-By: Claude <[email protected]>
1 parent fdd4b84 commit 9063a9a

File tree

5 files changed

+141
-161
lines changed

5 files changed

+141
-161
lines changed

src-tauri/src/backup.rs

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ pub fn create_backup(
7070

7171
// Create backup directory
7272
if let Err(e) = fs::create_dir_all(&backup_dir) {
73-
let error_msg = format!("Failed to create backup directory: {}", e);
73+
let error_msg = format!("Failed to create backup directory: {e}");
7474
logger.error(&error_msg, Some("BACKUP"));
7575
return Err(error_msg);
7676
}
7777

7878
// Create original_files subdirectory
7979
let original_files_dir = backup_dir.join("original_files");
8080
if let Err(e) = fs::create_dir_all(&original_files_dir) {
81-
let error_msg = format!("Failed to create original files directory: {}", e);
81+
let error_msg = format!("Failed to create original files directory: {e}");
8282
logger.error(&error_msg, Some("BACKUP"));
8383
return Err(error_msg);
8484
}
@@ -92,13 +92,13 @@ pub fn create_backup(
9292
// Create destination path maintaining relative structure
9393
let file_name = source_path
9494
.file_name()
95-
.ok_or_else(|| format!("Invalid file path: {}", file_path))?;
95+
.ok_or_else(|| format!("Invalid file path: {file_path}"))?;
9696
let dest_path = original_files_dir.join(file_name);
9797

9898
// Copy file
9999
if let Err(e) = fs::copy(source_path, &dest_path) {
100100
logger.warning(
101-
&format!("Failed to backup file {}: {}", file_path, e),
101+
&format!("Failed to backup file {file_path}: {e}"),
102102
Some("BACKUP"),
103103
);
104104
} else {
@@ -110,7 +110,7 @@ pub fn create_backup(
110110
}
111111
} else {
112112
logger.warning(
113-
&format!("Source file not found for backup: {}", file_path),
113+
&format!("Source file not found for backup: {file_path}"),
114114
Some("BACKUP"),
115115
);
116116
}
@@ -119,10 +119,10 @@ pub fn create_backup(
119119
// Save metadata
120120
let metadata_path = backup_dir.join("metadata.json");
121121
let metadata_json = serde_json::to_string_pretty(&metadata)
122-
.map_err(|e| format!("Failed to serialize backup metadata: {}", e))?;
122+
.map_err(|e| format!("Failed to serialize backup metadata: {e}"))?;
123123

124124
fs::write(&metadata_path, metadata_json)
125-
.map_err(|e| format!("Failed to write backup metadata: {}", e))?;
125+
.map_err(|e| format!("Failed to write backup metadata: {e}"))?;
126126

127127
let backup_path = backup_dir.to_string_lossy().to_string();
128128
logger.info(
@@ -157,11 +157,11 @@ pub fn list_backups(
157157

158158
// Iterate through session directories
159159
let session_dirs =
160-
fs::read_dir(&logs_dir).map_err(|e| format!("Failed to read logs directory: {}", e))?;
160+
fs::read_dir(&logs_dir).map_err(|e| format!("Failed to read logs directory: {e}"))?;
161161

162162
for session_entry in session_dirs {
163163
let session_entry =
164-
session_entry.map_err(|e| format!("Failed to read session directory entry: {}", e))?;
164+
session_entry.map_err(|e| format!("Failed to read session directory entry: {e}"))?;
165165

166166
let session_path = session_entry.path();
167167
if !session_path.is_dir() {
@@ -188,11 +188,11 @@ pub fn list_backups(
188188

189189
// Iterate through backup directories
190190
let backup_entries = fs::read_dir(&backups_dir)
191-
.map_err(|e| format!("Failed to read backups directory: {}", e))?;
191+
.map_err(|e| format!("Failed to read backups directory: {e}"))?;
192192

193193
for backup_entry in backup_entries {
194194
let backup_entry =
195-
backup_entry.map_err(|e| format!("Failed to read backup entry: {}", e))?;
195+
backup_entry.map_err(|e| format!("Failed to read backup entry: {e}"))?;
196196

197197
let backup_path = backup_entry.path();
198198
if !backup_path.is_dir() {
@@ -206,10 +206,10 @@ pub fn list_backups(
206206
}
207207

208208
let metadata_content = fs::read_to_string(&metadata_path)
209-
.map_err(|e| format!("Failed to read backup metadata: {}", e))?;
209+
.map_err(|e| format!("Failed to read backup metadata: {e}"))?;
210210

211211
let metadata: BackupMetadata = serde_json::from_str(&metadata_content)
212-
.map_err(|e| format!("Failed to parse backup metadata: {}", e))?;
212+
.map_err(|e| format!("Failed to parse backup metadata: {e}"))?;
213213

214214
// Filter by type if specified
215215
if let Some(ref filter_type) = r#type {
@@ -256,7 +256,7 @@ pub fn restore_backup(
256256
logger: State<Arc<AppLogger>>,
257257
) -> Result<(), String> {
258258
logger.info(
259-
&format!("Restoring backup: {} to {}", backup_id, target_path),
259+
&format!("Restoring backup: {backup_id} to {target_path}"),
260260
Some("BACKUP"),
261261
);
262262

@@ -265,7 +265,7 @@ pub fn restore_backup(
265265
let backup = backups
266266
.iter()
267267
.find(|b| b.metadata.id == backup_id)
268-
.ok_or_else(|| format!("Backup not found: {}", backup_id))?;
268+
.ok_or_else(|| format!("Backup not found: {backup_id}"))?;
269269

270270
let backup_path = Path::new(&backup.backup_path);
271271
let original_files_dir = backup_path.join("original_files");
@@ -278,19 +278,19 @@ pub fn restore_backup(
278278

279279
// Create target directory if it doesn't exist
280280
if let Err(e) = fs::create_dir_all(target_dir) {
281-
let error_msg = format!("Failed to create target directory: {}", e);
281+
let error_msg = format!("Failed to create target directory: {e}");
282282
logger.error(&error_msg, Some("BACKUP"));
283283
return Err(error_msg);
284284
}
285285

286286
// Copy files from backup to target
287287
let backup_files = fs::read_dir(&original_files_dir)
288-
.map_err(|e| format!("Failed to read backup files: {}", e))?;
288+
.map_err(|e| format!("Failed to read backup files: {e}"))?;
289289

290290
let mut restored_count = 0;
291291
for backup_file in backup_files {
292292
let backup_file =
293-
backup_file.map_err(|e| format!("Failed to read backup file entry: {}", e))?;
293+
backup_file.map_err(|e| format!("Failed to read backup file entry: {e}"))?;
294294

295295
let source_path = backup_file.path();
296296
let file_name = source_path
@@ -318,8 +318,7 @@ pub fn restore_backup(
318318

319319
logger.info(
320320
&format!(
321-
"Backup restoration completed: {} files restored",
322-
restored_count
321+
"Backup restoration completed: {restored_count} files restored"
323322
),
324323
Some("BACKUP"),
325324
);
@@ -329,28 +328,28 @@ pub fn restore_backup(
329328
/// Delete a specific backup
330329
#[tauri::command]
331330
pub fn delete_backup(backup_id: String, logger: State<Arc<AppLogger>>) -> Result<(), String> {
332-
logger.info(&format!("Deleting backup: {}", backup_id), Some("BACKUP"));
331+
logger.info(&format!("Deleting backup: {backup_id}"), Some("BACKUP"));
333332

334333
// Find the backup by ID
335334
let backups = list_backups(None, None, None, logger.clone())?;
336335
let backup = backups
337336
.iter()
338337
.find(|b| b.metadata.id == backup_id)
339-
.ok_or_else(|| format!("Backup not found: {}", backup_id))?;
338+
.ok_or_else(|| format!("Backup not found: {backup_id}"))?;
340339

341340
let backup_path = Path::new(&backup.backup_path);
342341

343342
if backup_path.exists() {
344343
fs::remove_dir_all(backup_path)
345-
.map_err(|e| format!("Failed to delete backup directory: {}", e))?;
344+
.map_err(|e| format!("Failed to delete backup directory: {e}"))?;
346345

347346
logger.info(
348-
&format!("Backup deleted successfully: {}", backup_id),
347+
&format!("Backup deleted successfully: {backup_id}"),
349348
Some("BACKUP"),
350349
);
351350
} else {
352351
logger.warning(
353-
&format!("Backup directory not found for deletion: {}", backup_id),
352+
&format!("Backup directory not found for deletion: {backup_id}"),
354353
Some("BACKUP"),
355354
);
356355
}
@@ -365,7 +364,7 @@ pub fn prune_old_backups(
365364
logger: State<Arc<AppLogger>>,
366365
) -> Result<u32, String> {
367366
logger.info(
368-
&format!("Pruning backups older than {} days", retention_days),
367+
&format!("Pruning backups older than {retention_days} days"),
369368
Some("BACKUP"),
370369
);
371370

@@ -390,8 +389,7 @@ pub fn prune_old_backups(
390389

391390
logger.info(
392391
&format!(
393-
"Backup pruning completed: {} backups removed",
394-
deleted_count
392+
"Backup pruning completed: {deleted_count} backups removed"
395393
),
396394
Some("BACKUP"),
397395
);
@@ -436,21 +434,21 @@ pub fn get_backup_storage_size(logger: State<Arc<AppLogger>>) -> Result<u64, Str
436434

437435
// Iterate through session directories looking for backup subdirectories
438436
let session_dirs =
439-
fs::read_dir(&logs_dir).map_err(|e| format!("Failed to read logs directory: {}", e))?;
437+
fs::read_dir(&logs_dir).map_err(|e| format!("Failed to read logs directory: {e}"))?;
440438

441439
for session_entry in session_dirs {
442440
let session_entry =
443-
session_entry.map_err(|e| format!("Failed to read session directory: {}", e))?;
441+
session_entry.map_err(|e| format!("Failed to read session directory: {e}"))?;
444442

445443
let backups_dir = session_entry.path().join("backups");
446444
if backups_dir.exists() {
447445
total_size += calculate_dir_size(&backups_dir)
448-
.map_err(|e| format!("Failed to calculate backup size: {}", e))?;
446+
.map_err(|e| format!("Failed to calculate backup size: {e}"))?;
449447
}
450448
}
451449

452450
logger.debug(
453-
&format!("Total backup storage size: {} bytes", total_size),
451+
&format!("Total backup storage size: {total_size} bytes"),
454452
Some("BACKUP"),
455453
);
456454
Ok(total_size)

src-tauri/src/config.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub fn load_config() -> std::result::Result<String, String> {
153153
// Get the config file path
154154
let config_path = match get_config_path() {
155155
Ok(path) => path,
156-
Err(e) => return Err(format!("Failed to get config path: {}", e)),
156+
Err(e) => return Err(format!("Failed to get config path: {e}")),
157157
};
158158

159159
// Check if the config file exists
@@ -164,18 +164,18 @@ pub fn load_config() -> std::result::Result<String, String> {
164164
// Serialize the default config
165165
let config_json = match serde_json::to_string_pretty(&default_config) {
166166
Ok(json) => json,
167-
Err(e) => return Err(format!("Failed to serialize default config: {}", e)),
167+
Err(e) => return Err(format!("Failed to serialize default config: {e}")),
168168
};
169169

170170
// Create the config file
171171
let mut config_file = match File::create(&config_path) {
172172
Ok(file) => file,
173-
Err(e) => return Err(format!("Failed to create config file: {}", e)),
173+
Err(e) => return Err(format!("Failed to create config file: {e}")),
174174
};
175175

176176
// Write the default config
177177
if let Err(e) = config_file.write_all(config_json.as_bytes()) {
178-
return Err(format!("Failed to write default config: {}", e));
178+
return Err(format!("Failed to write default config: {e}"));
179179
}
180180

181181
return Ok(config_json);
@@ -184,27 +184,27 @@ pub fn load_config() -> std::result::Result<String, String> {
184184
// Open the config file
185185
let mut config_file = match File::open(&config_path) {
186186
Ok(file) => file,
187-
Err(e) => return Err(format!("Failed to open config file: {}", e)),
187+
Err(e) => return Err(format!("Failed to open config file: {e}")),
188188
};
189189

190190
// Read the config file
191191
let mut config_json = String::new();
192192
if let Err(e) = config_file.read_to_string(&mut config_json) {
193-
return Err(format!("Failed to read config file: {}", e));
193+
return Err(format!("Failed to read config file: {e}"));
194194
}
195195

196196
// Parse the config
197197
let config: AppConfig = match serde_json::from_str(&config_json) {
198198
Ok(config) => config,
199-
Err(e) => return Err(format!("Failed to parse config: {}", e)),
199+
Err(e) => return Err(format!("Failed to parse config: {e}")),
200200
};
201201

202202
// TODO: Update the config with any missing fields from default_config()
203203

204204
// Serialize the updated config
205205
let updated_config_json = match serde_json::to_string_pretty(&config) {
206206
Ok(json) => json,
207-
Err(e) => return Err(format!("Failed to serialize updated config: {}", e)),
207+
Err(e) => return Err(format!("Failed to serialize updated config: {e}")),
208208
};
209209

210210
Ok(updated_config_json)
@@ -218,30 +218,30 @@ pub fn save_config(config_json: &str) -> std::result::Result<bool, String> {
218218
// Parse the config
219219
let config: AppConfig = match serde_json::from_str(config_json) {
220220
Ok(config) => config,
221-
Err(e) => return Err(format!("Failed to parse config: {}", e)),
221+
Err(e) => return Err(format!("Failed to parse config: {e}")),
222222
};
223223

224224
// Get the config file path
225225
let config_path = match get_config_path() {
226226
Ok(path) => path,
227-
Err(e) => return Err(format!("Failed to get config path: {}", e)),
227+
Err(e) => return Err(format!("Failed to get config path: {e}")),
228228
};
229229

230230
// Create the config file
231231
let mut config_file = match File::create(&config_path) {
232232
Ok(file) => file,
233-
Err(e) => return Err(format!("Failed to create config file: {}", e)),
233+
Err(e) => return Err(format!("Failed to create config file: {e}")),
234234
};
235235

236236
// Serialize the config
237237
let config_json = match serde_json::to_string_pretty(&config) {
238238
Ok(json) => json,
239-
Err(e) => return Err(format!("Failed to serialize config: {}", e)),
239+
Err(e) => return Err(format!("Failed to serialize config: {e}")),
240240
};
241241

242242
// Write the config
243243
if let Err(e) = config_file.write_all(config_json.as_bytes()) {
244-
return Err(format!("Failed to write config: {}", e));
244+
return Err(format!("Failed to write config: {e}"));
245245
}
246246

247247
Ok(true)

0 commit comments

Comments
 (0)