providersync

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: MIT Imports: 17 Imported by: 0

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

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 New

func New(db *gorm.DB) *Manager

New returns a Manager backed by db.

func (*Manager) CheckSource

func (m *Manager) CheckSource(mode, syncPath string) ([]string, error)

CheckSource lists file paths under syncPath without reading content.

func (*Manager) DeleteByID

func (m *Manager) DeleteByID(ctx context.Context, id uint) error

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

func (m *Manager) DeleteSource(ctx context.Context, id uint) error

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) GetByID

func (m *Manager) GetByID(ctx context.Context, id uint) (entity.ProviderStorage, error)

GetByID returns one file row.

func (*Manager) GetSource added in v0.13.0

func (m *Manager) GetSource(ctx context.Context, id uint) (entity.ProviderStorageSource, error)

GetSource returns one configured source by ID.

func (*Manager) ListAll

func (m *Manager) ListAll(ctx context.Context) ([]entity.ProviderStorage, error)

ListAll returns all stored file rows.

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

func (m *Manager) ListRoots(ctx context.Context) ([]entity.ProviderStorage, error)

ListRoots returns top-level rows (parent_id=0) across all instances.

func (*Manager) ListSources

func (m *Manager) ListSources(ctx context.Context) ([]entity.ProviderStorageSource, error)

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

func (m *Manager) RepairTree(ctx context.Context) (int, error)

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

func (m *Manager) RestoreAll(ctx context.Context) error

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

func (m *Manager) RunRetention(ctx context.Context)

RunRetention purges expired file rows.

func (*Manager) SaveSource

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

func (m *Manager) SetRetention(ctx context.Context, id uint, days int) error

SetRetention updates retention_days for one file row.

func (*Manager) SyncAll added in v0.13.0

func (m *Manager) SyncAll(ctx context.Context) (int, error)

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.

func (*Manager) SyncOne

func (m *Manager) SyncOne(ctx context.Context, ins provider.Instance) error

SyncOne runs a single backup pass for one instance.

func (*Manager) Upload

func (m *Manager) Upload(ctx context.Context, providerType, instanceName, relPath string, content []byte) error

Upload stores file content directly into DB (manual upload).

type SrcInfo

type SrcInfo struct{ Mode, SyncPath string }

SrcInfo holds mode and path for one configured sync source.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL