MCPcopy Create free account
hub / github.com/GraphiteEditor/Graphite / garbage_collect_document_files

Function garbage_collect_document_files

desktop/src/persist.rs:59–80  ·  view source on GitHub ↗
(state: &PersistedState)

Source from the content-addressed store, hash-verified

57}
58
59fn garbage_collect_document_files(state: &PersistedState) {
60 let valid_paths: std::collections::HashSet<_> = state.documents.iter().map(|doc| document_content_path(&doc.id)).collect();
61
62 let directory = crate::dirs::app_autosave_documents_dir();
63 let entries = match std::fs::read_dir(&directory) {
64 Ok(entries) => entries,
65 Err(e) if e.kind() == std::io::ErrorKind::NotFound => return,
66 Err(e) => {
67 tracing::error!("Failed to read autosave documents directory: {e}");
68 return;
69 }
70 };
71
72 for entry in entries.flatten() {
73 let path = entry.path();
74 if path.is_file() && !valid_paths.contains(&path) {
75 if let Err(e) = std::fs::remove_file(&path) {
76 tracing::error!("Failed to remove orphaned document file {path:?}: {e}");
77 }
78 }
79 }
80}
81
82fn state_file_path() -> std::path::PathBuf {
83 let mut path = crate::dirs::app_data_dir();

Callers 2

read_stateFunction · 0.85
write_stateFunction · 0.85

Calls 8

document_content_pathFunction · 0.85
remove_fileFunction · 0.85
kindMethod · 0.80
flattenMethod · 0.80
iterMethod · 0.45
pathMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected