File System Operations
Relevant source files
The following files were used as context for generating this wiki page:
File System Operations in Augenblick manage the lifecycle of notes as physical files on the user's disk. The system distinguishes between internal application drafts and user-selected external files, employing a dual-storage strategy to balance convenience with data permanence.
The architecture relies on a Rust backend for heavy-duty file I/O and security-scoped access, while the frontend coordinates user interactions such as saving, trashing, and importing markdown files.
Sources: plans/migration.inventory.md:38-46, src-tauri/src/notes/write.rs:1-10
Note Storage Strategy
Notes are categorized into two primary storage types which dictate where they reside on the file system.
Storage Types
| Type | Description | File Location |
|---|---|---|
| Draft | Internal notes created by the app. | app_data_dir/drafts/<uuid>.md |
| Saved | User-defined notes exported or imported. | User-selected path (External) |
| Trash | Notes pending deletion. | app_data_dir/trash/<uuid>.md (for Drafts) |
Sources: plans/migration.inventory.md:50-55, src-tauri/src/notes/write.rs:16-18
Draft Lifecycle
When a new note is created, the system generates a unique UUID and initializes an empty .md file in the application's internal drafts directory. These files are subject to automatic content derivations (title and preview) during write operations.
Sources: src-tauri/src/notes/write.rs:15-30, src-tauri/src/notes/derive.rs:1-18
Core File Operations
The system provides several primitive operations to manage file content and metadata transitions.
Save and Save As
The save_as operation transition a note from "Draft" to "Saved" status. This involves writing the content to a new user-specified path, deleting the old internal draft file, and updating the database with the new file location and storage status.
The logic ensures that internal draft files are cleaned up only after a successful external write.
Sources: src-tauri/src/notes/write.rs:136-150, src/routes/pageActions.ts:74-89
Import/Open Operations
The import_file operation allows users to bring existing .md files into the system. If a file is already known to the database (matched by path), the system updates the existing record; otherwise, it creates a new "Saved" entry.
Sources: src-tauri/src/notes/import.rs:15-35, src/routes/pageActions.ts:50-64
Trashing and Deletion
Trashing a note involves moving it to a temporary state before final deletion.
- Drafts: The physical file is moved from the
drafts/directory to thetrash/directory. - Saved Notes: The physical file on the user's disk is never touched; only the database flag
is_trashedis set to 1. - Delete Forever: Deletes the database row. For drafts, it also deletes the local file in the trash directory.
Sources: plans/migration.inventory.md:144-162, src-tauri/src/notes.rs:59-69
Content Derivation Logic
Whenever content is written to a file, the system executes derivation logic to extract a title and a preview for the UI.
The system skips non-text lines (like Horizontal Rules ---) when searching for titles and strips markdown escape sequences to ensure clean display in the sidebar.
Sources: src-tauri/src/notes/derive.rs:1-18, src-tauri/src/notes/derive.rs:55-62
Security and Scoped Access
On platforms like macOS, Augenblick uses security-scoped bookmarks to maintain access to files outside the application sandbox.
- Scoped Files: Operations use
with_scoped_fileto resolve bookmarks and start accessing resources. - Path Resolution: If a resolved path differs from the stored path (e.g., file moved), the system updates the database with the effective new path.
- Permissions: The frontend requests
fileAccessMode: "scoped"during file dialogs to facilitate these security requirements.
Sources: plans/migration.inventory.md:234-245, src-tauri/src/notes/write.rs:75-80, src/routes/pageActions.ts:55-60
Summary
File System Operations in Augenblick provide a robust bridge between volatile in-app drafting and permanent user storage. By automating the transition between internal directories and external paths while maintaining security-scoped access, the system ensures that user data is managed safely and predictably across different operating systems.