Documentation
¶
Overview ¶
Package conda holds the parts of the conda channel protocol that hosted, proxy and group repositories share: package file names, the request paths of a channel, and a streaming reader and merger for the very large repodata.json documents (the conda-forge linux-64 one is close to half a gigabyte) that never holds a whole document in memory.
Index ¶
- Constants
- Variables
- func BuildTimes(r io.Reader, limit int64, name string) (map[string]time.Time, error)
- func EarliestBuild(r io.Reader, limit int64, name, version string) (time.Time, bool, error)
- func EntryIdentity(raw json.RawMessage) (string, string)
- func EntryTimestamp(raw json.RawMessage) time.Time
- func PlainSegment(s string) bool
- func RepodataFile(current bool, comp Compression) string
- func Scan(r io.Reader, limit int64, v Visitor) error
- func ValidSubdir(subdir string) bool
- func ValidateIndex(r io.Reader, comp Compression, limit int64) error
- func ValidateJSONObject(r io.Reader, limit int64) error
- type Builder
- type Compression
- type Document
- type Entry
- type File
- type Kind
- type MemberOptions
- type MemberStats
- type Path
- type Section
- type Visitor
Constants ¶
const ( ExtTarBz2 = ".tar.bz2" ExtConda = ".conda" )
Package file extensions: .tar.bz2 files are listed under "packages" in a repodata.json, .conda files under "packages.conda".
const ( MaxNameLen = 255 MaxVersionLen = 100 MaxBuildLen = 255 MaxPlatformLen = 50 )
Column widths of the hosted format's conda package rows, also the limits a package file name must respect.
const ChanneldataFile = "channeldata.json"
ChanneldataFile is the channel-root document listing every package name.
const MaxEntryBytes = 4 << 20
MaxEntryBytes bounds one repodata entry (and the info object): real entries are a few KiB, the largest depend lists tens of KiB. A hostile document must not be able to make the reader buffer a gigabyte-long string.
Variables ¶
var ( // ErrTooLarge is a document that decompresses to more than its limit. ErrTooLarge = errors.New("conda: repodata exceeds its size limit") // ErrMalformed is a document that is not a repodata.json. ErrMalformed = errors.New("conda: malformed repodata") // ErrBaseURL is a document whose info.base_url points package downloads // somewhere other than the channel: served through a proxy it would let // clients fetch around it. ErrBaseURL = errors.New("conda: repodata sets info.base_url") )
var ErrNotListed = errors.New("conda: file is not listed in the repodata")
ErrNotListed is a package file the repodata does not list.
Functions ¶
func BuildTimes ¶ added in v0.16.0
BuildTimes is, for every version of the package called name (compared without regard to case) in the plain repodata.json in r, the earliest "timestamp" of its entries; the zero time for a version none of whose entries carries one. limit bounds the bytes read.
func EarliestBuild ¶ added in v0.16.0
EarliestBuild is the earliest "timestamp" among the entries of the plain repodata.json in r whose name (compared without regard to case) and version are the given ones: when the package version was first built, the nearest thing to a publish time a channel states. ok is false when no matching entry carries a timestamp. limit bounds the bytes read.
func EntryIdentity ¶ added in v0.16.0
func EntryIdentity(raw json.RawMessage) (string, string)
EntryIdentity is the "name" and "version" a repodata entry states about its package, "" for a field it lacks or that is not a string.
func EntryTimestamp ¶ added in v0.16.0
func EntryTimestamp(raw json.RawMessage) time.Time
EntryTimestamp is the "timestamp" of a repodata entry: when the package was built, the only date repodata carries. The zero time when the entry has none, or one that is not a positive number.
func PlainSegment ¶
PlainSegment reports whether s is valid UTF-8 without path separators or control characters: text a database column holds and a URL segment names.
func RepodataFile ¶
func RepodataFile(current bool, comp Compression) string
RepodataFile is the file name of a repodata document.
func Scan ¶
Scan streams the repodata.json in r, calling v for the info object and every package entry, and holding one entry in memory at a time. r must be plain JSON (see Open). It returns ErrMalformed for anything that is not a JSON object whose "packages" and "packages.conda" members, when present, are objects of objects, and ErrTooLarge when r yields more than limit bytes.
func ValidSubdir ¶
ValidSubdir reports whether subdir, the directory of a channel packages and repodata live under (linux-64, noarch), is usable as a repository path segment and fits the platform column of the hosted format. Any other value is a database error or a path escape, not a subdirectory.
func ValidateIndex ¶
func ValidateIndex(r io.Reader, comp Compression, limit int64) error
ValidateIndex checks that r, the body of a repodata file of the given encoding, is a usable one: plain and zstd documents are scanned in full (structure, and no info.base_url); a bzip2 stream, which no modern client asks for and which decodes slowly, is only checked for its magic number. limit bounds the decoded size.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder merges the repodata.json documents of several members into one for a subdirectory, in a single streaming pass: entries go to temporary files, so memory is one entry plus the set of file names seen. Earlier members win a file name. Close it to remove the temporary files.
func NewBuilder ¶
NewBuilder starts a merged document for subdir. Temporary files go to tmpDir ("" for the system default).
func (*Builder) Add ¶
func (b *Builder) Add(r io.Reader, o MemberOptions) (MemberStats, error)
Add merges the repodata document in r (plain JSON or a zstd or bzip2 stream) into the result. On error the Builder is unusable: Close it.
type Compression ¶
type Compression int
Compression is how a repodata file is encoded.
const ( // CompNone is plain JSON. CompNone Compression = iota // CompZstd is a zstd stream (repodata.json.zst). CompZstd // CompBzip2 is a bzip2 stream (repodata.json.bz2). CompBzip2 )
func Open ¶
func Open(r io.Reader, limit int64) (io.ReadCloser, Compression, error)
Open returns the decoded bytes of a repodata document in r: plain JSON, or a zstd or bzip2 stream, told apart by their magic numbers. The decoded output is limited to limit bytes (ErrTooLarge). Closing the result releases the decoder; it does not close r.
func (Compression) Suffix ¶
func (c Compression) Suffix() string
Suffix is the file name suffix of the compression, "" for plain JSON.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a merged repodata.json held in temporary files.
type Entry ¶
type Entry struct {
// SHA256 and MD5 are lowercase hex, "" when the entry has none (or a
// malformed one).
SHA256, MD5 string
// Name and Version are the package name and version the entry itself
// states ("" when it has none), which need not agree with its file name.
Name, Version string
// Size is the file size in bytes, -1 when the entry has none.
Size int64
// Published is the entry's "timestamp" (see EntryTimestamp), the zero time
// when it has none.
Published time.Time
}
Entry is what a repodata entry says about its package file: the digests a download must match.
func Lookup ¶
Lookup finds filename in the plain repodata.json in r and returns its digests, or ErrNotListed. It reads r at most once and keeps about a megabyte: instead of parsing the whole document it searches for the entry's key and decodes only the value after it. r must hold a document that was validated (ValidateIndex); limit bounds the bytes read.
type File ¶
type File struct {
Name, Version, Build, Ext string
}
File is a conda package file name taken apart.
func ParseFilename ¶
ParseFilename splits <name>-<version>-<build>(.tar.bz2|.conda) from the right: a package name may contain hyphens (scikit-learn), but neither a version nor a build string can. ok is false for any other extension, a name with fewer than three parts, empty parts, invalid UTF-8, path separators or control characters.
type Kind ¶
type Kind int
Kind is the type of a channel request path.
const ( // KindOther is a path a proxy or group does not serve (repodata.jlap, // sharded repodata, index.html, anything unknown). KindOther Kind = iota // KindRepodata is <subdir>/repodata.json or <subdir>/current_repodata.json, // plain or compressed (.zst, .bz2). KindRepodata // KindPackage is <subdir>/<name>-<version>-<build>.conda or .tar.bz2. KindPackage // KindChanneldata is channeldata.json at the channel root. KindChanneldata )
type MemberOptions ¶
type MemberOptions struct {
// Hidden reports whether entries of the named package are dropped. It is
// asked about the name in the file name and about the entry's own "name"
// field, so a document cannot smuggle a package past it by lying in one.
Hidden func(name string) bool
// Drop, when set, is asked about every entry that passed the checks above,
// with its parsed file name (its raw JSON is only valid during the call),
// and drops the entry when it returns true.
Drop func(file File, entry json.RawMessage) bool
// MaxBytes bounds the decoded size of the member's document.
MaxBytes int64
}
MemberOptions tunes Builder.Add for one member's document.
type MemberStats ¶
type MemberStats struct {
// Added entries went into the merged document.
Added int
// Duplicates were dropped: an earlier member lists the same file.
Duplicates int
// Hidden entries were dropped by MemberOptions.Hidden.
Hidden int
// Dropped entries were dropped by MemberOptions.Drop.
Dropped int
// Invalid entries were dropped: a key that is no package file name, or one
// listed in the wrong section.
Invalid int
}
MemberStats counts what Builder.Add did with one member's entries.
type Path ¶
type Path struct {
Kind Kind
// Subdir is the platform directory of KindRepodata and KindPackage paths.
Subdir string
// File is the file name below Subdir (the whole path for KindChanneldata).
File string
// Current reports a current_repodata.json (the latest versions only).
Current bool
// Comp is the encoding of a KindRepodata file.
Comp Compression
}
Path is a parsed channel request path.
type Section ¶
type Section int
Section is one of the two package maps of a repodata.json.
type Visitor ¶
type Visitor struct {
// Info receives the "info" object.
Info func(info json.RawMessage) error
// Entry receives one package entry of a section.
Entry func(section Section, filename string, entry json.RawMessage) error
}
Visitor receives the parts of a repodata.json as Scan streams over it. Any field may be nil. The slices passed in are only valid during the call. A returned error stops the scan and is returned as is.