Documentation
¶
Overview ¶
Package providersync syncs provider credential files to/from the DB.
On startup: DB → filesystem (restore). Background ticker: filesystem → DB (backup), skipping unchanged files via SHA-256 hash comparison. Retention job: purges expired file rows on each tick.
Index ¶
- func SourceToInstance(src entity.ProviderStorageSource) provider.Instance
- type Manager
- func (m *Manager) CheckSource(mode, syncPath string) ([]string, error)
- func (m *Manager) DeleteByID(ctx context.Context, id uint) error
- func (m *Manager) DeleteByInstance(ctx context.Context, providerType, instanceName string) (int64, error)
- func (m *Manager) DeleteSource(ctx context.Context, id uint) error
- func (m *Manager) GetByID(ctx context.Context, id uint) (entity.ProviderStorage, error)
- func (m *Manager) GetSource(ctx context.Context, id uint) (entity.ProviderStorageSource, error)
- func (m *Manager) ListAll(ctx context.Context) ([]entity.ProviderStorage, error)
- func (m *Manager) ListChildren(ctx context.Context, providerType, instanceName string, parentID uint) ([]entity.ProviderStorage, error)
- func (m *Manager) ListRoots(ctx context.Context) ([]entity.ProviderStorage, error)
- func (m *Manager) ListSources(ctx context.Context) ([]entity.ProviderStorageSource, error)
- func (m *Manager) PurgeExcluded(ctx context.Context, providerType, instanceName string) (int, error)
- func (m *Manager) RecomputeRetention(ctx context.Context, providerType, instanceName string) (int, error)
- func (m *Manager) RepairTree(ctx context.Context) (int, error)
- func (m *Manager) RestoreAll(ctx context.Context) error
- func (m *Manager) RestoreSelected(ctx context.Context, ids []uint, srcsByInstance map[string][]SrcInfo) (int, error)
- func (m *Manager) RunRetention(ctx context.Context)
- func (m *Manager) SaveSource(ctx context.Context, src entity.ProviderStorageSource) (entity.ProviderStorageSource, error)
- func (m *Manager) SetRetention(ctx context.Context, id uint, days int) error
- func (m *Manager) SyncAll(ctx context.Context) (int, error)
- func (m *Manager) SyncOne(ctx context.Context, ins provider.Instance) error
- func (m *Manager) Upload(ctx context.Context, providerType, instanceName, relPath string, ...) error
- type SrcInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SourceToInstance ¶
func SourceToInstance(src entity.ProviderStorageSource) provider.Instance
SourceToInstance converts a ProviderStorageSource to a provider.Instance suitable for SyncOne / backup calls. Excludes are read separately at the store layer since provider.Instance has no slot for them.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager drives syncing for all provider instances that have Storage configured. One Manager per app lifetime; call Start once.
func (*Manager) CheckSource ¶
CheckSource lists file paths under syncPath without reading content.
func (*Manager) DeleteByID ¶
DeleteByID removes one file row from DB.
func (*Manager) DeleteByInstance ¶
func (m *Manager) DeleteByInstance(ctx context.Context, providerType, instanceName string) (int64, error)
DeleteByInstance removes all rows for a provider instance.
func (*Manager) DeleteSource ¶
DeleteSource removes a sync source by ID and recomputes file retention so rows that previously inherited this source's retention drop back to the next matching source (or 0 / lifetime if none).
func (*Manager) ListChildren ¶
func (m *Manager) ListChildren(ctx context.Context, providerType, instanceName string, parentID uint) ([]entity.ProviderStorage, error)
ListChildren returns direct children (files + folders) under parentID for an instance. parentID=0 means instance root.
func (*Manager) ListSources ¶
ListSources returns all configured sync sources.
func (*Manager) PurgeExcluded ¶ added in v0.13.0
func (m *Manager) PurgeExcluded(ctx context.Context, providerType, instanceName string) (int, error)
PurgeExcluded walks every row for (providerType, instanceName) and deletes rows whose absolute rel_path matches any current enabled-source exclude pattern. Empty folder rows left behind are also pruned so the tree doesn't show ghost directories. Returns the number of file rows deleted.
func (*Manager) RecomputeRetention ¶ added in v0.13.0
func (m *Manager) RecomputeRetention(ctx context.Context, providerType, instanceName string) (int, error)
RecomputeRetention walks every file row for (providerType, instanceName) and rewrites retention_days based on the deepest currently-enabled source whose path covers the row. Returns the number of rows updated. Cheap to call on every source change since pickRetention is in-memory.
func (*Manager) RepairTree ¶ added in v0.13.0
RepairTree rewires parent_id values for every row from its rel_path so listChildren / explorer drill-down works even when a parent row was previously deleted (orphan recovery). Returns the number of rows fixed. Cheap; intended for boot-time and after destructive operations.
func (*Manager) RestoreAll ¶
RestoreAll writes all DB file rows back to filesystem. rel_path is now an absolute path; we only restore files whose absolute path falls under at least one enabled source (file mode "single") or under an enabled folder source's prefix. Call once at startup.
func (*Manager) RestoreSelected ¶
func (m *Manager) RestoreSelected(ctx context.Context, ids []uint, srcsByInstance map[string][]SrcInfo) (int, error)
RestoreSelected writes specific DB rows (by ID) back to filesystem. srcsByInstance is kept for API compatibility but ignored: rel_path is now an absolute filesystem path, written directly. Returns count of files written.
func (*Manager) RunRetention ¶
RunRetention purges expired file rows.
func (*Manager) SaveSource ¶
func (m *Manager) SaveSource(ctx context.Context, src entity.ProviderStorageSource) (entity.ProviderStorageSource, error)
SaveSource creates or updates a sync source and immediately runs a backup pass. Also recomputes per-file retention for the instance so existing rows reflect the new (or changed) source retention without waiting for the next sync tick.
func (*Manager) SetRetention ¶
SetRetention updates retention_days for one file row.
func (*Manager) SyncAll ¶ added in v0.13.0
SyncAll iterates all enabled sources and runs a backup pass for each. Returns number of sources that synced cleanly; per-source errors are logged but do not abort the loop (one bad path shouldn't stop the others). Safe to call on startup so users see populated rows immediately without having to wait for the cron tick.