add remove sessions

This commit is contained in:
Julian Freeman
2026-04-17 14:04:44 -04:00
parent ad838086ed
commit d724db6f0f
7 changed files with 76 additions and 6 deletions

View File

@@ -148,6 +148,28 @@ fn cleanup_profile_history_files(profile_path: &Path, profile_id: &str) -> Clean
remove_sidecar_files(&file_path);
}
let sessions_directory = profile_path.join("Sessions");
match cleanup_sessions_directory(&sessions_directory) {
Ok(session_deleted) => {
if session_deleted {
deleted_files.push("Sessions".to_string());
} else {
skipped_files.push("Sessions".to_string());
}
}
Err(error) => {
return CleanupHistoryResult {
profile_id: profile_id.to_string(),
deleted_files,
skipped_files,
error: Some(format!(
"Failed to clean {}: {error}",
sessions_directory.display()
)),
};
}
}
CleanupHistoryResult {
profile_id: profile_id.to_string(),
deleted_files,
@@ -164,3 +186,21 @@ fn remove_sidecar_files(path: &Path) {
}
}
}
fn cleanup_sessions_directory(path: &Path) -> Result<bool, std::io::Error> {
if !path.is_dir() {
return Ok(false);
}
let mut deleted_any = false;
for entry in path.read_dir()? {
let entry = entry?;
let entry_path = entry.path();
if entry_path.is_file() {
fs::remove_file(&entry_path)?;
deleted_any = true;
}
}
Ok(deleted_any)
}

View File

@@ -83,6 +83,7 @@ pub struct HistoryCleanupSummary {
pub history: CleanupFileStatus,
pub top_sites: CleanupFileStatus,
pub visited_links: CleanupFileStatus,
pub sessions: CleanupFileStatus,
}
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]

View File

@@ -101,6 +101,7 @@ fn scan_browser(config: BrowserConfigEntry) -> Option<BrowserView> {
cleanup.history == CleanupFileStatus::Found
|| cleanup.top_sites == CleanupFileStatus::Found
|| cleanup.visited_links == CleanupFileStatus::Found
|| cleanup.sessions == CleanupFileStatus::Found
})
.count();
@@ -195,6 +196,7 @@ fn scan_history_cleanup_status(profile_path: &Path) -> HistoryCleanupSummary {
history: cleanup_file_status(&profile_path.join("History")),
top_sites: cleanup_file_status(&profile_path.join("Top Sites")),
visited_links: cleanup_file_status(&profile_path.join("Visited Links")),
sessions: cleanup_sessions_status(&profile_path.join("Sessions")),
}
}
@@ -206,6 +208,18 @@ fn cleanup_file_status(path: &Path) -> CleanupFileStatus {
}
}
fn cleanup_sessions_status(path: &Path) -> CleanupFileStatus {
let Ok(entries) = path.read_dir() else {
return CleanupFileStatus::Missing;
};
if entries.flatten().any(|entry| entry.path().is_file()) {
CleanupFileStatus::Found
} else {
CleanupFileStatus::Missing
}
}
fn resolve_profile_avatar(
_root: &Path,
profile_path: &Path,