Skip to content

refactor(lib/metainfogen): deduplicate metainfo generation - #651

Draft
Pybsama wants to merge 1 commit into
uber:masterfrom
Pybsama:codex/deduplicate-metainfo-generation
Draft

refactor(lib/metainfogen): deduplicate metainfo generation#651
Pybsama wants to merge 1 commit into
uber:masterfrom
Pybsama:codex/deduplicate-metainfo-generation

Conversation

@Pybsama

@Pybsama Pybsama commented Jul 31, 2026

Copy link
Copy Markdown

Summary

  • add a narrow CAStore.GenerateCacheFileMetaInfo operation for opening a cached blob, generating torrent metainfo, and persisting it
  • reuse that operation from both the cache write path and metainfogen.Generator, while keeping piece-length selection in metainfogen
  • close the cache reader after generation and cover successful persistence, missing cache files, and invalid piece lengths

This keeps the existing error prefixes and metadata overwrite behavior while removing the duplicate workflow introduced with the in-memory cache path.

Fixes #488.

Test plan

  • CGO_CFLAGS="-Wno-return-local-addr" go test -count=1 -race ./lib/store ./lib/metainfogen
  • CGO_CFLAGS="-Wno-return-local-addr" go test $(go list ./...) -cover
  • CGO_CFLAGS="-Wno-return-local-addr" go build ./...
  • golangci-lint run ./...
  • CGO_CFLAGS="-Wno-return-local-addr" go vet ./lib/store ./lib/metainfogen
  • CGO_CFLAGS="-Wno-return-local-addr" go test ./lib/store ./lib/metainfogen -bench=. -benchmem -run='^$'

Move cache-file metainfo generation and persistence into CAStore so both cache writes and metainfogen use one implementation. Add focused coverage for successful persistence and error paths.
@CLAassistant

CLAassistant commented Jul 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread lib/store/ca_store.go
return metaInfo, nil
}

func (s *CAStore) generateMetadataFromFile(name string, pieceLength int64) error {

@thijmv thijmv Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider making this function public and calling it directly from Generator.generate after computing the piece length? That would avoid having to introduce an additional helper function to the ca store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(metainfogen): deduplicate metainfo generation code from castore and metainfogen

3 participants