metadata

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandSharedOuterSources added in v0.2.1

func ExpandSharedOuterSources(meta *metapb.FileMetadata) error

ExpandSharedOuterSources resolves NestedSegmentSource.SharedOuterSourceIndex references in-place. Sources with a non-zero index inherit Segments, AesKey, AesIv, and (if unset) InnerVolumeSize from meta.SharedOuterSources[index-1]. Slice headers share their underlying array — RAM cost is unchanged from the legacy layout. Safe to call on any FileMetadata; a no-op when SharedOuterSources is empty.

The dedupe written by archive.NewFileMetadataFromContent is the write-side counterpart of this expansion.

Types

type BackupWorker

type BackupWorker struct {
	// contains filtered or unexported fields
}

func NewBackupWorker

func NewBackupWorker(configGetter config.ConfigGetter) *BackupWorker

func (*BackupWorker) Start

func (w *BackupWorker) Start(ctx context.Context) error

func (*BackupWorker) Stop

func (w *BackupWorker) Stop(ctx context.Context)

type FileMetadataLite added in v0.2.1

type FileMetadataLite struct {
	FileSize   int64
	ModifiedAt int64
	Status     metapb.FileStatus
}

FileMetadataLite holds the minimal metadata needed for directory listings. This avoids keeping full FileMetadata protos (with SegmentData, Par2Files, etc.) in memory just for Readdir.

type MetadataReader

type MetadataReader struct {
	// contains filtered or unexported fields
}

MetadataReader provides read operations for the virtual filesystem

func NewMetadataReader

func NewMetadataReader(service *MetadataService) *MetadataReader

NewMetadataReader creates a new metadata reader

func (*MetadataReader) GetFileMetadata

func (mr *MetadataReader) GetFileMetadata(virtualPath string) (*metapb.FileMetadata, error)

GetFileMetadata gets metadata for a virtual file

func (*MetadataReader) GetMetadataService

func (mr *MetadataReader) GetMetadataService() *MetadataService

GetMetadataService returns the underlying metadata service

type MetadataService

type MetadataService struct {
	// contains filtered or unexported fields
}

MetadataService provides low-level read/write operations for metadata files.

Only a lightweight metadata projection (liteCache) is kept in memory. The full FileMetadata proto — dominated by SegmentData/NestedSources slices holding thousands of message-ID strings — is never cached. Callers that need segments (Open, HealthChecker) re-read from disk each time; the proto then lives only for the duration of the open handle or the health check. This bounds steady-state memory at ~liteCache_entries × 40 bytes instead of the previous unbounded segment retention.

func NewMetadataService

func NewMetadataService(rootPath string) *MetadataService

NewMetadataService creates a new metadata service

func (*MetadataService) CleanupEmptyDirectories

func (ms *MetadataService) CleanupEmptyDirectories(virtualPath string, protected []string) error

CleanupEmptyDirectories recursively removes empty directories under the given virtual path. Uses a bottom-up approach to ensure parent directories are also removed if they become empty.

func (ms *MetadataService) CleanupOrphanedIDSymlinks(ctx context.Context) (int, error)

CleanupOrphanedIDSymlinks walks the .ids/ directory and removes symlinks whose targets no longer exist. Empty shard directories are cleaned up afterwards. Returns the number of removed symlinks.

func (*MetadataService) CreateDirectory

func (ms *MetadataService) CreateDirectory(name string) error

func (*MetadataService) CreateFileMetadata

func (ms *MetadataService) CreateFileMetadata(
	fileSize int64,
	sourceNzbPath string,
	status metapb.FileStatus,
	segmentData []*metapb.SegmentData,
	encryption metapb.Encryption,
	password string,
	salt string,
	aesKey []byte,
	aesIv []byte,
	releaseDate int64,
	par2Files []*metapb.Par2FileReference,
	nzbdavId string,
) *metapb.FileMetadata

CreateFileMetadata creates a new FileMetadata with basic fields

func (*MetadataService) DeleteDirectory

func (ms *MetadataService) DeleteDirectory(virtualPath string) error

DeleteDirectory deletes a metadata directory and all its contents

func (*MetadataService) DeleteFileMetadata

func (ms *MetadataService) DeleteFileMetadata(virtualPath string) error

DeleteFileMetadata deletes a metadata file

func (*MetadataService) DeleteFileMetadataWithSourceNzb

func (ms *MetadataService) DeleteFileMetadataWithSourceNzb(ctx context.Context, virtualPath string, deleteSourceNzb bool) error

DeleteFileMetadataWithSourceNzb deletes a metadata file and optionally its source NZB

func (*MetadataService) DirectoryExists

func (ms *MetadataService) DirectoryExists(virtualPath string) bool

DirectoryExists checks if a metadata directory exists

func (*MetadataService) FileExists

func (ms *MetadataService) FileExists(virtualPath string) bool

FileExists checks if a metadata file exists for the given virtual path

func (*MetadataService) GetMetadataDirectoryPath

func (ms *MetadataService) GetMetadataDirectoryPath(virtualPath string) string

GetMetadataDirectoryPath returns the filesystem path for a metadata directory

func (*MetadataService) GetMetadataFilePath

func (ms *MetadataService) GetMetadataFilePath(virtualPath string) string

GetMetadataFilePath returns the filesystem path for a metadata file

func (*MetadataService) ListDirectory

func (ms *MetadataService) ListDirectory(virtualPath string) ([]string, error)

ListDirectory lists all metadata files in a directory

func (*MetadataService) ListDirectoryAll added in v0.2.1

func (ms *MetadataService) ListDirectoryAll(virtualPath string) (dirs []fs.FileInfo, fileNames []string, err error)

ListDirectoryAll returns both subdirectory fs.FileInfo entries and virtual file names from a single os.ReadDir call. This is used by Readdir to avoid two separate directory reads.

func (*MetadataService) MoveToCorrupted

func (ms *MetadataService) MoveToCorrupted(ctx context.Context, virtualPath string) error

MoveToCorrupted moves a metadata file to a special corrupted directory for safety

func (*MetadataService) ReadFileMetadata

func (ms *MetadataService) ReadFileMetadata(virtualPath string) (*metapb.FileMetadata, error)

ReadFileMetadata reads file metadata from disk. The full proto (including SegmentData and NestedSources) is returned to the caller but NOT cached — those slices dominate heap usage and must not be retained beyond the caller's handle. As a side effect, the lightweight projection is cached so subsequent Readdir/Stat calls are fast without a disk read.

func (*MetadataService) ReadFileMetadataLite added in v0.2.1

func (ms *MetadataService) ReadFileMetadataLite(virtualPath string) (*FileMetadataLite, error)

ReadFileMetadataLite reads only the lightweight fields (size, modtime, status) needed for directory listings. On cache miss it reads at most liteScanBytes from the .meta file and scans the proto wire format for the three lite fields, never instantiating the full FileMetadata proto or its NestedSources/SegmentData slices. Falls back to a full read in the rare case the partial buffer doesn't cover the lite fields.

func (*MetadataService) RenameFileMetadata

func (ms *MetadataService) RenameFileMetadata(oldVirtualPath, newVirtualPath string) error

RenameFileMetadata atomically renames a metadata file (and its .id sidecar) from oldVirtualPath to newVirtualPath. Uses os.Rename for atomicity on the same filesystem, falling back to read-write-delete for cross-device moves.

func (*MetadataService) UpdateFileMetadata

func (ms *MetadataService) UpdateFileMetadata(virtualPath string, updateFunc func(*metapb.FileMetadata)) error

UpdateFileMetadata updates the modified timestamp of metadata

func (*MetadataService) UpdateFileStatus

func (ms *MetadataService) UpdateFileStatus(virtualPath string, status metapb.FileStatus) error

UpdateFileStatus updates the status of a file in metadata

func (*MetadataService) WriteFileMetadata

func (ms *MetadataService) WriteFileMetadata(virtualPath string, metadata *metapb.FileMetadata) error

WriteFileMetadata writes file metadata to disk

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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