providersync

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 13 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.

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.

func (*Manager) GetByID

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

GetByID returns one file row.

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) ([]RootInfo, error)

ListRoots returns distinct (provider_type, instance_name) pairs with file count.

func (*Manager) ListSources

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

ListSources returns all configured sync sources.

func (*Manager) RestoreAll

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

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

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.

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

type RootInfo struct {
	ProviderType string
	InstanceName string
	FileCount    int64
}

RootInfo is one (provider_type, instance_name) pair with a file count.

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