What is a Location?
A location is any folder on your device that you want Spacedrive to index. Once added:- Files are indexed immediately
- Changes are detected in real-time
- Metadata syncs across your devices (if enabled)
- Content gets unique identifiers for deduplication
Location Architecture
Locations have a sophisticated relationship with the file index:Root Entry
When you add a location, Spacedrive creates a root entry in the entries table for the location directory itself. This root entry:- Has no parent (
parent_id = NULL) - Gets a self-reference in the
entry_closuretable - Serves as the ancestor for all files/folders within the location
- Is stored in the
directory_pathstable with its full filesystem path
Why Root Entries?
This design enables nested locations without duplicating the file tree. If you have:- Location A:
/Users/alice/Documents(entry_id: 123) - Location B:
/Users/alice/Documents/Work(entry_id: 124)
- No duplication -
Work/report.pdfexists once in the database, accessible from both locations - Consistent hierarchy - Parent-child relationships are preserved regardless of location boundaries
- Efficient storage - Adding nested locations doesn’t create redundant entry records
- Flexible organization - Users can create fine-grained locations within broader ones
- Different index modes - Apply Deep indexing to
/Photosbut Shallow to/Photos/RAWwithout duplicating entries
Entry Hierarchy
All files and folders within a location form a tree structure:entry_closure table enables efficient queries:
- “Find all files in this location” → Query where
ancestor_id = 123 - “Get file path” → Walk up closure table following parent relationships
- “Calculate total size” → Aggregate from all descendants
Directory Paths Table
Directory paths are stored separately for performance:Device Ownership & Sync
Entries don’t have adevice_id field. Instead, ownership is inherited from the location:
-
Efficient ownership queries - Find all entries owned by a device via
entry_closure: - No redundant storage - Avoids storing device_id on millions of entry records
-
Instant ownership transfer - When you move an external drive between devices, just update the location’s
device_id. All millions of files instantly change ownership without touching the entries table. See Library Sync - Portable Volumes for details.
- Only the owning device can modify entries in a location
- Other devices have read-only views of remote locations
- Location ownership change is a single-row update (not a bulk migration)
Core Properties
See Data Model - Location for the complete database schema.
Index Modes
Choose how deeply Spacedrive analyzes your files:- Shallow: Basic metadata only (name, size, dates)
- Content: Includes content hashing for deduplication
- Deep: Full media processing with thumbnails and metadata
Scan States
Locations track their scanning status:Adding Locations
Using the CLI
Using the API
What Happens When You Add a Location
The location creation process is atomic (uses database transactions):- Path validation - Ensures the directory exists and is accessible
- Create root entry - Creates an entry for the location directory
- Assigns a UUID for sync compatibility
- Sets
parent_id = NULL(this is a root) - Sets
indexed_atto enable sync emission
- Create closure record - Adds self-reference to
entry_closuretable - Create directory path - Adds full path to
directory_pathstable - Duplicate check - Verifies no location already exists for this entry
- Create location record - Stores location metadata
- Links to root entry via
entry_id - Sets initial
scan_state = "pending"
- Links to root entry via
- Commit transaction - All or nothing (prevents partial state)
- Emit sync event - Broadcasts root entry StateChange for sync
- Start indexing job - Begins scanning child files/folders
- Watcher setup - Begins monitoring changes
- Event broadcast - Notifies other services
File System Watching
The watcher service provides real-time monitoring across all platforms.Platform Support
macOS: Uses FSEvents for efficient volume-level monitoring Linux: Uses inotify for precise file-level events Windows: Uses ReadDirectoryChangesW for real-time updatesEvent Types
The watcher detects these file system changes:Automatic Filtering
The watcher respects the indexer rules configured for each location. These rules determine which files and directories are tracked: Available Indexer Rules:no_system_files- Ignores.DS_Store,Thumbs.db, and other OS-generated filesno_hidden- Ignores hidden files (dotfiles) except important ones like.gitignoreno_git- Ignores.gitdirectoriesgitignore- Respects.gitignorepatterns in the directory treeonly_images- Only processes image filesno_dev_dirs- Ignoresnode_modules/,target/,.cache/, and other build directories
Currently, the watcher uses hardcoded filtering instead of per-location indexer rules. Integration with the indexer rules engine is planned, which will allow each location to have custom filtering rules configured through the UI.
Configuration
Watcher Settings
Configure the watcher for your needs:Performance Tuning
For large directories (>100k files):- Increase buffer size to prevent event loss
- Use longer debounce periods
- Consider excluding cache directories
- Enable polling fallback
- Increase debounce duration
- Monitor connection stability
- SSDs: Shorter debounce, larger buffers
- HDDs: Longer debounce for mechanical latency
Watching Events
Subscribe to location events in your code:Event Flow
When a file changes:- Operating system detects change
- Watcher receives raw event
- Event is filtered and debounced
- Structured event is created
- Event bus broadcasts to subscribers
- Services react (indexer, sync, UI)
Managing Locations
Pause Watching
Temporarily stop monitoring without removing:Update Settings
Change location configuration:Remove Location
Stop tracking a directory:Troubleshooting
High CPU Usage
If watching causes high CPU:- Check for directories with rapid changes
- Increase debounce duration
- Exclude problematic subdirectories
- Temporarily disable watching
Missing Changes
If file changes aren’t detected:- Verify location has watching enabled
- Check file system permissions
- Ensure platform limits aren’t exceeded
- Try restarting the watcher
Duplicate Events
If you see the same change multiple times:- Increase debounce duration
- Check for symlink loops
- Verify you’re not watching overlapping paths
Debug Mode
Enable detailed logging:Platform Limits
macOS
- FSEvents may coalesce rapid changes
- Volume-level monitoring affects all locations on a drive
Linux
- inotify has a watch descriptor limit (usually 8192)
- Increase with:
echo 524288 | sudo tee /proc/sys/fs/inotify/max_user_watches
Windows
- Long paths require special handling
- Network drives may fall back to polling
Best Practices
Location Organization
- Nested locations are supported - You can add both
/Documentsand/Documents/Workas separate locations- The file tree is shared, not duplicated
- Each location provides a different “view” into the same hierarchy
- Useful for applying different index modes or policies to subdirectories
- Group related content - One location per project or media type
- Consider performance - Separate frequently-changing directories
Exclusion Patterns
Create.spacedriveignore files to exclude:
Network Locations
For network-attached storage:- Use Content index mode (avoid Deep)
- Increase debounce to 500ms+
- Monitor connection stability
- Consider scheduled indexing instead
Integration
Services Using Location Events
- Indexer: Re-analyzes modified files
- Search: Updates search index
- Sync: Propagates changes to other devices
- Thumbnails: Regenerates previews
- Frontend: Updates UI in real-time
Event Priority
Critical events are processed first:- User-initiated changes
- Create/delete operations
- Modifications
- Metadata updates
Implementation Details
Database Schema
Locations utilize three main tables: locations - Location metadataQuery Patterns
Find all entries in a location:Related Documentation
- Data Model - Complete database schema
- Indexing - How files are analyzed
- Sync - Cross-device synchronization
- Events - Event system architecture
