nzbfilesystem

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrMsgFailedCreateDecryptReader = "failed to create decrypt reader: %w"
	ErrMsgFailedWrapEncryption      = "failed to wrap reader with encryption: %w"
)

Database operation error message templates

View Source
const (
	// RootPath represents the root directory path
	RootPath = "/"
)

File system constants

Variables

View Source
var (
	ErrInvalidWhence = errors.New("seek: invalid whence")
	ErrSeekNegative  = errors.New("seek: negative position")
	ErrSeekTooFar    = errors.New("seek: too far")
)

Error constants

View Source
var (
	ErrCannotRemoveRoot    = errors.New("cannot remove root directory")
	ErrNotDirectory        = errors.New("not a directory")
	ErrCannotReadDirectory = errors.New("cannot read from directory")
	ErrNegativeOffset      = errors.New("negative offset")
	ErrMissmatchedSegments = errors.New("missmatched segments for file size")
	ErrNoUsenetPool        = errors.New("usenet connection pool not configured")
	ErrNoCipherConfig      = errors.New("no cipher configured for encryption")
	ErrNoEncryptionParams  = errors.New("no NZB data available for encryption parameters")
	ErrFileIsCorrupted     = errors.New("file is corrupted, there are some missing segments")
	ErrFileClosed          = errors.New("file closed")
)

Error message constants

Functions

This section is empty.

Types

type ARRsRepairService

type ARRsRepairService interface {
	TriggerFileRescan(ctx context.Context, pathForRescan string, relativePath string, metadataStr *string) error
}

ARRsRepairService abstracts the ARR repair operations needed by the filesystem.

type ActiveStream

type ActiveStream struct {
	ID               string    `json:"id"`
	FilePath         string    `json:"file_path"`
	StartedAt        time.Time `json:"started_at"`
	LastActivity     time.Time `json:"last_activity"`
	Source           string    `json:"source"`
	UserName         string    `json:"user_name,omitempty"`
	ClientIP         string    `json:"client_ip,omitempty"`
	UserAgent        string    `json:"user_agent,omitempty"`
	TotalSize        int64     `json:"total_size"`
	BytesSent        int64     `json:"bytes_sent"`
	BytesDownloaded  int64     `json:"bytes_downloaded"`
	CurrentOffset    int64     `json:"current_offset"`
	BytesPerSecond   int64     `json:"bytes_per_second"`
	DownloadSpeed    int64     `json:"download_speed"`
	SpeedAvg         int64     `json:"speed_avg"`
	ETA              int64     `json:"eta"` // Seconds remaining
	TotalConnections int       `json:"total_connections"`
	BufferedOffset   int64     `json:"buffered_offset"`
	Status           string    `json:"status"` // e.g., "Buffering", "Streaming", "Stalled"
}

ActiveStream represents a file currently being streamed

type CorruptedFileError

type CorruptedFileError struct {
	TotalExpected int64
	UnderlyingErr error
}

CorruptedFileError represents an error where no articles could be read (complete failure)

func (*CorruptedFileError) Error

func (e *CorruptedFileError) Error() string

func (*CorruptedFileError) Unwrap

func (e *CorruptedFileError) Unwrap() error

type MetadataFileInfo

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

MetadataFileInfo implements fs.FileInfo for metadata-based files

func (*MetadataFileInfo) IsDir

func (mfi *MetadataFileInfo) IsDir() bool

func (*MetadataFileInfo) ModTime

func (mfi *MetadataFileInfo) ModTime() time.Time

func (*MetadataFileInfo) Mode

func (mfi *MetadataFileInfo) Mode() os.FileMode

func (*MetadataFileInfo) Name

func (mfi *MetadataFileInfo) Name() string

func (*MetadataFileInfo) Size

func (mfi *MetadataFileInfo) Size() int64

func (*MetadataFileInfo) Sys

func (mfi *MetadataFileInfo) Sys() any

type MetadataRemoteFile

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

MetadataRemoteFile implements the RemoteFile interface for metadata-backed virtual files

func NewMetadataRemoteFile

func NewMetadataRemoteFile(
	metadataService *metadata.MetadataService,
	healthRepository *database.HealthRepository,
	arrsService ARRsRepairService,
	rcloneClient rclonecli.RcloneRcClient,
	poolManager pool.Manager,
	configGetter config.ConfigGetter,
	streamTracker StreamTracker,
	cacheSource *segcache.Source,
) *MetadataRemoteFile

NewMetadataRemoteFile creates a new metadata-based remote file handler

func (*MetadataRemoteFile) Mkdir

func (mrf *MetadataRemoteFile) Mkdir(ctx context.Context, name string, perm os.FileMode) error

func (*MetadataRemoteFile) MkdirAll

func (mrf *MetadataRemoteFile) MkdirAll(ctx context.Context, name string, perm os.FileMode) error

func (*MetadataRemoteFile) OpenFile

func (mrf *MetadataRemoteFile) OpenFile(ctx context.Context, name string) (bool, afero.File, error)

OpenFile opens a virtual file backed by metadata

func (*MetadataRemoteFile) RemoveFile

func (mrf *MetadataRemoteFile) RemoveFile(ctx context.Context, fileName string) (bool, error)

RemoveFile removes a virtual file or directory from the metadata

func (*MetadataRemoteFile) RenameFile

func (mrf *MetadataRemoteFile) RenameFile(ctx context.Context, oldName, newName string) (bool, error)

RenameFile renames a virtual file or directory in the metadata

func (*MetadataRemoteFile) Stat

func (mrf *MetadataRemoteFile) Stat(ctx context.Context, name string) (bool, fs.FileInfo, error)

Stat returns file information for a path using metadata

type MetadataSegmentLoader

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

MetadataSegmentLoader adapts metadata segments to the usenet.SegmentLoader interface

func (*MetadataSegmentLoader) GetSegment

func (msl *MetadataSegmentLoader) GetSegment(index int) (segment usenet.Segment, groups []string, ok bool)

GetSegment implements usenet.SegmentLoader interface

type MetadataVirtualDirectory

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

MetadataVirtualDirectory implements afero.File for metadata-backed virtual directories

func (*MetadataVirtualDirectory) Close

func (mvd *MetadataVirtualDirectory) Close() error

Close implements afero.File.Close

func (*MetadataVirtualDirectory) Name

func (mvd *MetadataVirtualDirectory) Name() string

Name implements afero.File.Name

func (*MetadataVirtualDirectory) Read

func (mvd *MetadataVirtualDirectory) Read(p []byte) (n int, err error)

Read implements afero.File.Read (not supported for directories)

func (*MetadataVirtualDirectory) ReadAt

func (mvd *MetadataVirtualDirectory) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements afero.File.ReadAt (not supported for directories)

func (*MetadataVirtualDirectory) Readdir

func (mvd *MetadataVirtualDirectory) Readdir(count int) ([]fs.FileInfo, error)

Readdir implements afero.File.Readdir

func (*MetadataVirtualDirectory) Readdirnames

func (mvd *MetadataVirtualDirectory) Readdirnames(n int) ([]string, error)

Readdirnames implements afero.File.Readdirnames

func (*MetadataVirtualDirectory) Seek

func (mvd *MetadataVirtualDirectory) Seek(offset int64, whence int) (int64, error)

Seek implements afero.File.Seek (not supported for directories)

func (*MetadataVirtualDirectory) Stat

func (mvd *MetadataVirtualDirectory) Stat() (fs.FileInfo, error)

Stat implements afero.File.Stat

func (*MetadataVirtualDirectory) Sync

func (mvd *MetadataVirtualDirectory) Sync() error

Sync implements afero.File.Sync (no-op for directories)

func (*MetadataVirtualDirectory) Truncate

func (mvd *MetadataVirtualDirectory) Truncate(size int64) error

Truncate implements afero.File.Truncate (not supported)

func (*MetadataVirtualDirectory) Write

func (mvd *MetadataVirtualDirectory) Write(p []byte) (n int, err error)

Write implements afero.File.Write (not supported)

func (*MetadataVirtualDirectory) WriteAt

func (mvd *MetadataVirtualDirectory) WriteAt(p []byte, off int64) (n int, err error)

WriteAt implements afero.File.WriteAt (not supported)

func (*MetadataVirtualDirectory) WriteString

func (mvd *MetadataVirtualDirectory) WriteString(s string) (ret int, err error)

WriteString implements afero.File.WriteString (not supported)

type MetadataVirtualFile

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

MetadataVirtualFile implements afero.File for metadata-backed virtual files

func (*MetadataVirtualFile) Close

func (mvf *MetadataVirtualFile) Close() error

Close implements afero.File.Close

func (*MetadataVirtualFile) GetStreamID

func (mvf *MetadataVirtualFile) GetStreamID() string

GetStreamID returns the active stream ID associated with this file handle

func (*MetadataVirtualFile) Name

func (mvf *MetadataVirtualFile) Name() string

Name implements afero.File.Name

func (*MetadataVirtualFile) Read

func (mvf *MetadataVirtualFile) Read(p []byte) (n int, err error)

Read implements afero.File.Read

func (*MetadataVirtualFile) ReadAt

func (mvf *MetadataVirtualFile) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements afero.File.ReadAt. It delegates to ReadAtContext using the file-level context.

func (*MetadataVirtualFile) ReadAtContext added in v0.3.0

func (mvf *MetadataVirtualFile) ReadAtContext(readCtx context.Context, p []byte, off int64) (n int, err error)

ReadAtContext serves offset-based reads. Sequential offsets reuse the shared streaming reader (preserving the prefetch pipeline); non-sequential offsets use a short-lived range reader so the shared pipeline is not disturbed. All calls are serialized via mvf.mu — the caller (FUSE handle) must ensure per-handle ordering.

func (*MetadataVirtualFile) Readdir

func (mvf *MetadataVirtualFile) Readdir(count int) ([]fs.FileInfo, error)

Readdir implements afero.File.Readdir

func (*MetadataVirtualFile) Readdirnames

func (mvf *MetadataVirtualFile) Readdirnames(n int) ([]string, error)

Readdirnames implements afero.File.Readdirnames

func (*MetadataVirtualFile) Seek

func (mvf *MetadataVirtualFile) Seek(offset int64, whence int) (int64, error)

Seek implements afero.File.Seek

func (*MetadataVirtualFile) Stat

func (mvf *MetadataVirtualFile) Stat() (fs.FileInfo, error)

Stat implements afero.File.Stat

func (*MetadataVirtualFile) Sync

func (mvf *MetadataVirtualFile) Sync() error

Sync implements afero.File.Sync (no-op for read-only)

func (*MetadataVirtualFile) Truncate

func (mvf *MetadataVirtualFile) Truncate(size int64) error

Truncate implements afero.File.Truncate (not supported)

func (*MetadataVirtualFile) Write

func (mvf *MetadataVirtualFile) Write(p []byte) (n int, err error)

Write implements afero.File.Write (not supported)

func (*MetadataVirtualFile) WriteAt

func (mvf *MetadataVirtualFile) WriteAt(p []byte, off int64) (n int, err error)

WriteAt implements afero.File.WriteAt (not supported)

func (*MetadataVirtualFile) WriteString

func (mvf *MetadataVirtualFile) WriteString(s string) (ret int, err error)

WriteString implements afero.File.WriteString (not supported)

type NzbFilesystem

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

NzbFilesystem implements afero.Fs interface directly using the metadata service

func NewNzbFilesystem

func NewNzbFilesystem(remoteFile *MetadataRemoteFile) *NzbFilesystem

NewNzbFilesystem creates a new filesystem backed directly by metadata

func (*NzbFilesystem) Mkdir

func (nfs *NzbFilesystem) Mkdir(ctx context.Context, name string, perm os.FileMode) error

Mkdir creates a directory (not supported - read-only filesystem)

func (*NzbFilesystem) MkdirAll

func (nfs *NzbFilesystem) MkdirAll(ctx context.Context, name string, perm os.FileMode) error

MkdirAll creates a directory and all parent directories (not supported)

func (*NzbFilesystem) Name

func (nfs *NzbFilesystem) Name() string

Name returns the filesystem name

func (*NzbFilesystem) Open

func (nfs *NzbFilesystem) Open(ctx context.Context, name string) (afero.File, error)

Open opens a file for reading

func (*NzbFilesystem) OpenFile

func (nfs *NzbFilesystem) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (afero.File, error)

OpenFile opens a file with specified flags and permissions

func (*NzbFilesystem) Remove

func (nfs *NzbFilesystem) Remove(ctx context.Context, name string) error

Remove removes a file (not supported)

func (*NzbFilesystem) RemoveAll

func (nfs *NzbFilesystem) RemoveAll(ctx context.Context, name string) error

RemoveAll removes a file and any children

func (*NzbFilesystem) Rename

func (nfs *NzbFilesystem) Rename(ctx context.Context, oldName, newName string) error

Rename renames a file (not supported)

func (*NzbFilesystem) Stat

func (nfs *NzbFilesystem) Stat(ctx context.Context, name string) (fs.FileInfo, error)

Stat returns file information

type PartialContentError

type PartialContentError struct {
	BytesRead     int64
	TotalExpected int64
	UnderlyingErr error
}

PartialContentError represents an error where some articles are missing but some content was read

func (*PartialContentError) Error

func (e *PartialContentError) Error() string

func (*PartialContentError) Unwrap

func (e *PartialContentError) Unwrap() error

type RepairCoalescer added in v0.3.0

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

RepairCoalescer throttles per-file streaming-failure repair triggers and coalesces rclone VFS refresh calls so that a batch of corrupted reads cannot fan out into one RC POST per file.

Two mechanisms:

  1. Per-path debounce — ShouldTrigger returns false if the same file path was triggered within the debounce window. This prevents repeated reads of the same corrupted file from re-firing the repair pipeline.

  2. Directory-level VFS refresh coalescing — EnqueueRefresh adds a virtual directory to a pending set; a single worker goroutine drains the set, deduplicates, and issues at most one RefreshDir RC call at a time with a minimum interval between calls.

func NewRepairCoalescer added in v0.3.0

func NewRepairCoalescer(rclone rclonecli.RcloneRcClient, configGetter config.ConfigGetter) *RepairCoalescer

NewRepairCoalescer constructs a coalescer and starts its background worker. The worker runs for the lifetime of the process; call Close to stop it in tests or during graceful shutdown.

func (*RepairCoalescer) Close added in v0.3.0

func (c *RepairCoalescer) Close()

Close stops the background worker. Pending refreshes are dropped.

func (*RepairCoalescer) EnqueueRefresh added in v0.3.0

func (c *RepairCoalescer) EnqueueRefresh(virtualDir string)

EnqueueRefresh adds virtualDir to the set of directories that will be sent to rclone in the next batched vfs/refresh call. Duplicate directories within the same flush window collapse to a single entry.

func (*RepairCoalescer) ShouldTrigger added in v0.3.0

func (c *RepairCoalescer) ShouldTrigger(path string) bool

ShouldTrigger reports whether a streaming-failure repair should be fired for path. It returns true at most once per debounce window per path. Stale entries are pruned opportunistically on each call.

type StreamTracker

type StreamTracker interface {
	Add(filePath, source, userName, clientIP, userAgent string, totalSize int64) string
	UpdateProgress(id string, bytesRead int64)
	UpdateDownloadProgress(id string, bytesDownloaded int64)
	UpdateCurrentOffset(id string, offset int64)
	UpdateBufferedOffset(id string, offset int64)
	Remove(id string)
	IncArticlesDownloaded()
	IncArticlesPosted()
}

StreamTracker interface for tracking active streams

Directories

Path Synopsis
Package segcache provides a segment-aligned disk cache for Usenet file data.
Package segcache provides a segment-aligned disk cache for Usenet file data.

Jump to

Keyboard shortcuts

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