Storage Manager
The Storage Manager provides a unified API for managing application storage across Windows, macOS, and Linux. It handles platform-specific directory conventions, ensures directories exist and are accessible, and provides graceful fallback when standard paths are unavailable.
Platform Paths
Section titled “Platform Paths”SideSeat stores data in platform-appropriate locations following OS conventions:
| Type | Windows | macOS | Linux |
|---|---|---|---|
| User Config | %USERPROFILE%\SideSeat\ | ~/.sideseat/ | ~/.sideseat/ |
| Config | %APPDATA%\SideSeat\config\ | ~/Library/Application Support/SideSeat/ | $XDG_CONFIG_HOME/sideseat/ |
| Data | %APPDATA%\SideSeat\data\ | ~/Library/Application Support/SideSeat/ | $XDG_DATA_HOME/sideseat/ |
| Cache | %LOCALAPPDATA%\SideSeat\cache\ | ~/Library/Caches/SideSeat/ | $XDG_CACHE_HOME/sideseat/ |
| Logs | %LOCALAPPDATA%\SideSeat\logs\ | ~/Library/Logs/SideSeat/ | $XDG_STATE_HOME/sideseat/ |
| Temp | %TEMP%\sideseat\ | $TMPDIR/sideseat/ | /tmp/sideseat/ |
Linux XDG Defaults
Section titled “Linux XDG Defaults”On Linux, if XDG environment variables are not set, the following defaults are used:
$XDG_CONFIG_HOMEdefaults to~/.config/$XDG_DATA_HOMEdefaults to~/.local/share/$XDG_CACHE_HOMEdefaults to~/.cache/$XDG_STATE_HOMEdefaults to~/.local/state/
Directory Structure
Section titled “Directory Structure”data/├── db/ # Database files└── uploads/ # User uploaded content
cache/ # Regeneratable cached dataconfig/ # Application configurationlogs/ # Application logstemp/ # Temporary processing filesEnvironment Variable Overrides
Section titled “Environment Variable Overrides”You can override storage locations using environment variables:
| Variable | Description |
|---|---|
SIDESEAT_CONFIG_DIR | Override config directory |
SIDESEAT_DATA_DIR | Override data directory |
SIDESEAT_CACHE_DIR | Override cache directory |
# Example: Use custom data directoryexport SIDESEAT_DATA_DIR=/mnt/storage/sideseat/dataUser Config Directory
Section titled “User Config Directory”The user config directory (~/.sideseat on Unix, %USERPROFILE%\SideSeat on Windows) is a special location where users can manually place configuration files. Unlike other directories, this is not automatically created by SideSeat.
To use custom configuration:
-
Create the directory manually:
Terminal window # Unix/macOSmkdir -p ~/.sideseat# Windows (PowerShell)mkdir $env:USERPROFILE\SideSeat -
Place configuration files (e.g.,
config.json) -
SideSeat will detect and load these files on startup
Initialization
Section titled “Initialization”On startup, SideSeat:
- Attempts to use platform-specific paths
- Creates all required directories if they don’t exist
- Verifies each directory is accessible (read/write test)
- Falls back to
.sideseat/in the current directory if platform paths fail
Initialization Errors
Section titled “Initialization Errors”If initialization fails, you may see errors like:
"Failed to create {directory}"- Permission denied or disk full"{path} exists but is not a directory"- A file exists at the expected directory path"{directory} is not writable"- Cannot write to the directory"{directory} is not readable"- Cannot read from the directory
Fallback Mode
Section titled “Fallback Mode”When standard platform paths are unavailable (e.g., no home directory, permission issues), SideSeat falls back to using .sideseat/ in the current working directory. A warning is logged when fallback mode is active.
API Reference
Section titled “API Reference”StorageType Enum
Section titled “StorageType Enum”pub enum StorageType { Config, // Configuration files Data, // Persistent application data Cache, // Regeneratable cached data Logs, // Application logs Temp, // Temporary files}DataSubdir Enum
Section titled “DataSubdir Enum”pub enum DataSubdir { Database, // data/db/ Uploads, // data/uploads/}StorageManager Methods
Section titled “StorageManager Methods”| Method | Description |
|---|---|
init() | Initialize storage manager and create directories |
work_dir() | Get current working directory (where app was started) |
user_config_dir() | Get user config directory path |
config_dir() | Get config directory path |
data_dir() | Get data directory path |
cache_dir() | Get cache directory path |
logs_dir() | Get logs directory path |
temp_dir() | Get temp directory path |
using_fallback() | Check if using fallback storage |
data_subdir(subdir) | Get path to a data subdirectory |
get_path(type, filename) | Get full path for a file |
exists(path) | Check if a path exists |
is_writable(type) | Check if a storage location is writable |
user_config_exists() | Check if user config directory exists |
user_config_path(filename) | Get path to a user config file |
read_user_config(filename) | Read a user config file |
list_user_config_files() | List files in user config directory |
Usage Examples
Section titled “Usage Examples”use sideseat::core::{StorageManager, StorageType, DataSubdir};
// Initialize storagelet storage = StorageManager::init().await?;
// Get current working directorylet cwd = storage.work_dir();println!("Started from: {:?}", cwd);
// Get data subdirectory pathlet db_path = storage.data_subdir(DataSubdir::Database).join("app.db");
// Get config file pathlet config_path = storage.get_path(StorageType::Config, "settings.json");
// Get cache directory for custom uselet cache_path = storage.cache_dir().join("my_cache_file");
// Check if using fallback locationif storage.using_fallback() { println!("Warning: Using fallback storage");}
// Read user config if it existsif let Some(content) = storage.read_user_config("config.json").await { println!("Found user config: {}", content);}
// List all user config filesfor file in storage.list_user_config_files().await { println!("User config file: {:?}", file);}Best Practices
Section titled “Best Practices”- Don’t hardcode paths - Always use
StorageManagermethods to get paths - Check fallback mode - Log a warning if
using_fallback()returns true - Handle missing user config - User config directory may not exist
- Use appropriate storage types:
Configfor settings that should persistCachefor data that can be regeneratedTempfor short-lived filesDatafor user data and databases