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) 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) ([]RootInfo, error)
- func (m *Manager) ListSources(ctx context.Context) ([]entity.ProviderStorageSource, 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) SyncOne(ctx context.Context, ins provider.Instance) error
- func (m *Manager) Upload(ctx context.Context, providerType, instanceName, relPath string, ...) error
- type RootInfo
- 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.
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.
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) ListRoots ¶
ListRoots returns distinct (provider_type, instance_name) pairs with file count.
func (*Manager) ListSources ¶
ListSources returns all configured sync sources.
func (*Manager) RestoreAll ¶
RestoreAll writes all DB file rows back to filesystem using configured sources. Handles both "single" (syncPath = full file path) and "folder" (syncPath = dir) modes. 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 maps "providerType/instanceName" → []SrcInfo for path resolution. 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.
func (*Manager) SetRetention ¶
SetRetention updates retention_days for one file row.