Architecture
Locations
Locations are a fundamental concept in Spacedrive that represent directories or paths that are managed and indexed by the application. The Locations system is responsible for tracking, monitoring, and managing these paths across the filesystem.
Core Components
Location Manager
The Location system is primarily managed by two key structures:
Locations
: The main interface for interacting with locationsLocationManagerActor
: Handles the actual management of locations including watching for changes
The Location Manager provides functionality for:
- Adding and removing locations
- Managing file system watchers
- Tracking online/offline status of locations
- Coordinating file system events
Location States
Locations can exist in several states tracked by ScanState
:
Pending
: Initial state when location is addedIndexed
: Basic file structure has been indexedFilesIdentified
: Files have been processed and identifiedCompleted
: Full indexing and processing is complete
Key Features
File System Watching
- Locations are actively monitored for changes using a file system watcher
- Changes are detected in real-time and synchronized with the database
- Watchers can be paused/resumed for maintenance operations
Location Management
- Creation: New locations are created with
LocationCreateArgs
, specifying path and indexer rules - Updates: Existing locations can be modified using
LocationUpdateArgs
- Deletion: Locations can be safely removed with cleanup of associated data
Error Handling
The system includes robust error handling through LocationError
and LocationManagerError
for various failure scenarios:
- File system errors
- Database operations
- Watcher management
- Path validation
- Synchronization issues
Implementation Details
Location Creation Flow
- Path validation and normalization
- Check for nested locations
- Create database entry
- Initialize file system watcher
- Begin initial scan process
Synchronization
- Locations maintain online/offline status
- Changes are tracked and synchronized across the library
- File operations are coordinated to prevent conflicts
Guards and Safety
The system provides safety mechanisms through guard types:
PauseWatcherGuard
: Temporarily pause watching a locationIgnoreEventsForPathGuard
: Ignore events for specific paths during operations
Best Practices
When working with Locations:
- Always use the provided APIs for location operations
- Handle errors appropriately using the provided error types
- Use guards when performing operations that could trigger unnecessary events
- Consider the implications of nested locations
- Be aware of the scanning states when implementing features
Related Components
Locations interact closely with:
- File Path system
- Indexer Rules
- Library system
- Job system for scanning and processing