file

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoFileRangeRecord    = errors.New("missing file range record")
	ErrNoJobRecord          = errors.New("missing job record")
	ErrNoFilecoinDeals      = errors.New("no filecoin deals available")
	ErrByteOffsetBeyondFile = errors.New("byte offset would exceed file size")
)

Functions

This section is empty.

Types

type DealsForFileRange added in v0.5.10

type DealsForFileRange struct {
	FileRange model.FileRange
	Deals     []model.Deal
}

type DefaultHandler

type DefaultHandler struct{}

func (DefaultHandler) GetFileDealsHandler

func (DefaultHandler) GetFileDealsHandler(
	ctx context.Context,
	db *gorm.DB,
	id uint64,
) ([]DealsForFileRange, error)

GetFileDealsHandler retrieves the deals associated with a given file ID.

The method operates by querying the database using the provided file ID. It starts by selecting the relevant file range, joining it with the cars table on the job_id field, and then joining with the deals table using the piece_cid field.

Parameters:

  • ctx: The context for managing timeouts and cancellation.
  • db: The gorm.DB instance for database operations.
  • id: The ID of the file for which deals need to be retrieved.

Returns:

  • A slice of DealsForFileRange containing the deals associated with the provided file ID for each FileRange.
  • An error if any issues occur during the database operation.

func (DefaultHandler) GetFileHandler

func (DefaultHandler) GetFileHandler(
	ctx context.Context,
	db *gorm.DB,
	id uint64,
) (*model.File, error)

GetFileHandler retrieves a file with its associated file ranges from the database using a given file ID.

This function preloads the associated FileRanges for the queried file. If no record is found matching the provided ID, it returns an ErrNotFound error.

Parameters:

  • ctx: The context for managing timeouts and cancellation.
  • db: The gorm.DB instance for database operations.
  • id: The ID of the file to be retrieved.

Returns:

  • A pointer to the retrieved model.File, if found.
  • An error if any issues occur during the database operation, including when the file is not found.

func (DefaultHandler) PrepareToPackFileHandler

func (DefaultHandler) PrepareToPackFileHandler(
	ctx context.Context,
	db *gorm.DB,
	fileID uint64) (int64, error)

func (DefaultHandler) PushFileHandler

func (DefaultHandler) PushFileHandler(
	ctx context.Context,
	db *gorm.DB,
	preparation string,
	source string,
	fileInfo Info,
) (*model.File, error)

PushFileHandler pushes a file to the database using specified preparation and source details.

This function retrieves the source attachment by its preparation and source. If the source isn't attached to the given preparation, an ErrNotFound error is returned. The function then validates the file's existence in the storage system using the RClone handler. If the file is validated successfully, it is then pushed to the database.

Parameters:

  • ctx: The context for managing timeouts and cancellation.
  • db: The gorm.DB instance for database operations.
  • preparation: The preparation ID or name.
  • source: The source ID or name.
  • fileInfo: Information regarding the file to be pushed.

Returns:

  • A pointer to the pushed model.File, if successful.
  • An error if any issues occur during the operation, including when the source isn't attached to the preparation, if the file doesn't exist in the storage system, or if the file already exists

func (DefaultHandler) RetrieveFileHandler added in v0.5.0

func (DefaultHandler) RetrieveFileHandler(
	ctx context.Context,
	db *gorm.DB,
	filecoinRetriever FilecoinRetriever,
	id uint64,
) (data io.ReadSeekCloser, name string, modTime time.Time, err error)

RetrieveFileHandler retrieves the actual bytes for a file on disk using a given file ID.

For now, this function only works if the file remains available in its original source storage

Parameters: - ctx: The context for managing timeouts and cancellation. - db: The gorm.DB instance for database operations. - id: The ID of the file to be retrieved.

Returns: - A ReadSeekCloser for the given file - the name of the file - An error if any issues occur during the database operation, including when the file is not found.

type FilecoinRetriever added in v0.5.1

type FilecoinRetriever interface {
	Retrieve(ctx context.Context, c cid.Cid, rangeStart int64, rangeEnd int64, sps []string, out io.Writer) error
	RetrieveReader(ctx context.Context, c cid.Cid, rangeStart int64, rangeEnd int64, sps []string) (io.ReadCloser, error)
}

type Handler

type Handler interface {
	PrepareToPackFileHandler(
		ctx context.Context,
		db *gorm.DB,
		fileID uint64) (int64, error)

	GetFileDealsHandler(
		ctx context.Context,
		db *gorm.DB,
		id uint64,
	) ([]DealsForFileRange, error)

	GetFileHandler(
		ctx context.Context,
		db *gorm.DB,
		id uint64,
	) (*model.File, error)

	PushFileHandler(
		ctx context.Context,
		db *gorm.DB,
		preparation string,
		source string,
		fileInfo Info,
	) (*model.File, error)

	RetrieveFileHandler(
		ctx context.Context,
		db *gorm.DB,
		retriever FilecoinRetriever,
		id uint64,
	) (data io.ReadSeekCloser, name string, modTime time.Time, err error)
}
var Default Handler = &DefaultHandler{}

type Info

type Info struct {
	Path string `json:"path"` // Path to the new file, relative to the source
}

type MockFile added in v0.5.0

type MockFile struct {
	mock.Mock
}

func (*MockFile) GetFileDealsHandler added in v0.5.0

func (m *MockFile) GetFileDealsHandler(
	ctx context.Context,
	db *gorm.DB,
	id uint64,
) ([]DealsForFileRange, error)

func (*MockFile) GetFileHandler added in v0.5.0

func (m *MockFile) GetFileHandler(ctx context.Context, db *gorm.DB, id uint64) (*model.File, error)

func (*MockFile) PrepareToPackFileHandler added in v0.5.0

func (m *MockFile) PrepareToPackFileHandler(ctx context.Context, db *gorm.DB, fileID uint64) (int64, error)

func (*MockFile) PushFileHandler added in v0.5.0

func (m *MockFile) PushFileHandler(ctx context.Context, db *gorm.DB, preparation string, source string, fileInfo Info) (*model.File, error)

func (*MockFile) RetrieveFileHandler added in v0.5.0

func (m *MockFile) RetrieveFileHandler(
	ctx context.Context,
	db *gorm.DB,
	retriever FilecoinRetriever,
	id uint64,
) (data io.ReadSeekCloser, name string, modTime time.Time, err error)

type UnableToServeRangeError added in v0.5.1

type UnableToServeRangeError struct {
	Start int64
	End   int64
	Err   error
}

func (UnableToServeRangeError) Error added in v0.5.1

func (e UnableToServeRangeError) Error() string

func (UnableToServeRangeError) Unwrap added in v0.5.1

func (e UnableToServeRangeError) Unwrap() error

Jump to

Keyboard shortcuts

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