schema

package
v0.0.0-...-7a1a713 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2013 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package schema manipulates Camlistore schema blobs.

A schema blob is a JSON-encoded blob that describes other blobs. See documentation in Camlistore's doc/schema/ directory.

Index

Constants

View Source
const MaxSchemaBlobSize = 1 << 20

MaxSchemaBlobSize represents the upper bound for how large a schema blob may be.

View Source
const ShareHaveRef = "haveref"

ShareHaveRef is the auth type specifying that if you "have the reference" (know the blobref to the haveref share blob), then you have access to the referenced object from that share blob. This is the "send a link to a friend" access model.

Variables

View Source
var DefaultStatHasher = &defaultStatHasher{}
View Source
var (
	ErrNoCamliVersion = errors.New("schema: no camliVersion key in map")
)

Functions

func FileTime

func FileTime(f io.ReaderAt) (time.Time, error)

FileTime returns the best guess of the file's creation time (or modtime). If the file doesn't have its own metadata indication the creation time (such as in EXIF), FileTime uses the modification time from the file system. It there was a valid EXIF but an error while trying to get a date from it, it logs the error and tries the other methods.

func IsMissingField

func IsMissingField(err error) bool

IsMissingField returns whether error is of type MissingFieldError.

func LikelySchemaBlob

func LikelySchemaBlob(buf []byte) bool

LikelySchemaBlob returns quickly whether buf likely contains (or is the prefix of) a schema blob.

func RFC3339FromTime

func RFC3339FromTime(t time.Time) string

RFC3339FromTime returns an RFC3339-formatted time in UTC. Fractional seconds are only included if the time has fractional seconds.

func WriteFileChunks

func WriteFileChunks(bs blobserver.StatReceiver, file *Builder, r io.Reader) error

WriteFileChunks uploads chunks of r to bs while populating file. It does not upload file.

func WriteFileFromReader

func WriteFileFromReader(bs blobserver.StatReceiver, filename string, r io.Reader) (*blobref.BlobRef, error)

WriteFileFromReader creates and uploads a "file" JSON schema composed of chunks of r, also uploading the chunks. The returned BlobRef is of the JSON file schema blob.

func WriteFileMap

func WriteFileMap(bs blobserver.StatReceiver, file *Builder, r io.Reader) (*blobref.BlobRef, error)

WriteFileMap uploads chunks of r to bs while populating file and finally uploading file's Blob. The returned blobref is of file's JSON blob.

Types

type AnyBlob

type AnyBlob interface {
	Blob() *Blob
}

AnyBlob represents any type of schema blob.

type Blob

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

A Blob represents a Camlistore schema blob. It is immutable.

func BlobFromReader

func BlobFromReader(ref *blobref.BlobRef, r io.Reader) (*Blob, error)

BlobReader returns a new Blob from the provided Reader r, which should be the body of the provided blobref. Note: the hash checksum is not verified. Call (*Blob).Verify() to validate that the digest matches.

func (*Blob) AsClaim

func (b *Blob) AsClaim() (c Claim, ok bool)

AsClaim returns a Claim if the receiver Blob has all the required fields.

func (*Blob) AsShare

func (b *Blob) AsShare() (s Share, ok bool)

AsShare returns a Share if the receiver Blob has all the required fields.

func (*Blob) Blob

func (b *Blob) Blob() *Blob

Blob returns itself, so it satisifies the AnyBlob interface.

func (*Blob) BlobRef

func (b *Blob) BlobRef() *blobref.BlobRef

BlobRef returns the schema blob's blobref.

func (*Blob) Builder

func (b *Blob) Builder() *Builder

func (*Blob) ByteParts

func (b *Blob) ByteParts() []BytesPart

ByteParts returns the "parts" field. The caller owns the returned slice.

func (*Blob) ClaimDate

func (b *Blob) ClaimDate() (time.Time, error)

ClaimDate returns the "claimDate" field. If there is no claimDate, the error will be a MissingFieldError.

func (*Blob) DirectoryEntries

func (b *Blob) DirectoryEntries() *blobref.BlobRef

DirectoryEntries the "entries" field if valid and b's type is "directory", else it returns nil

func (*Blob) FileMode

func (b *Blob) FileMode() os.FileMode

func (*Blob) FileName

func (b *Blob) FileName() string

FileName returns the file, directory, or symlink's filename, or the empty string. TODO: move this off *Blob to a specialized type.

func (*Blob) JSON

func (b *Blob) JSON() string

JSON returns the JSON bytes of the schema blob.

func (*Blob) MapGid

func (b *Blob) MapGid() int

MapGid returns the most appropriate mapping from this file's group to the local machine's group, trying first a match by name, followed by just mapping the number through directly.

func (*Blob) MapUid

func (b *Blob) MapUid() int

MapUid returns the most appropriate mapping from this file's owner to the local machine's owner, trying first a match by name, followed by just mapping the number through directly.

func (*Blob) ModTime

func (b *Blob) ModTime() time.Time

ModTime returns the "unixMtime" field, or the zero time.

func (*Blob) NewDirReader

func (b *Blob) NewDirReader(fetcher blobref.SeekFetcher) (*DirReader, error)

func (*Blob) NewFileReader

func (b *Blob) NewFileReader(fetcher blobref.SeekFetcher) (*FileReader, error)

func (*Blob) PartsSize

func (b *Blob) PartsSize() int64

PartsSize returns the number of bytes represented by the "parts" field. TODO: move this off *Blob to a specialized type.

func (*Blob) ShareAuthType

func (b *Blob) ShareAuthType() string

func (*Blob) ShareTarget

func (b *Blob) ShareTarget() *blobref.BlobRef

func (*Blob) StaticSetMembers

func (b *Blob) StaticSetMembers() []*blobref.BlobRef

func (*Blob) Type

func (b *Blob) Type() string

Type returns the blob's "camliType" field.

type Buildable

type Buildable interface {
	Builder() *Builder
}

Buildable returns a Builder from a base.

type Builder

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

A Builder builds a JSON blob. After mutating the Builder, call Blob to get the built blob.

func NewAddAttributeClaim

func NewAddAttributeClaim(permaNode *blobref.BlobRef, attr, value string) *Builder

func NewBuilder

func NewBuilder() *Builder

NewBuilder returns a new blob schema builder. The "camliVersion" field is set to "1" by default and the required "camliType" field is NOT set.

func NewClaim

func NewClaim(claims ...*claimParam) *Builder

func NewCommonFileMap

func NewCommonFileMap(fileName string, fi os.FileInfo) *Builder

func NewDelAttributeClaim

func NewDelAttributeClaim(permaNode *blobref.BlobRef, attr string) *Builder

func NewFileMap

func NewFileMap(fileName string) *Builder

NewFileMap returns a new builder of a type "file" schema for the provided fileName. The chunk parts of the file are not populated.

func NewHashPlannedPermanode

func NewHashPlannedPermanode(h hash.Hash) *Builder

NewHashPlannedPermanode returns a planned permanode with the sum of the hash, prefixed with "sha1-", as the key.

func NewPlannedPermanode

func NewPlannedPermanode(key string) *Builder

NewPlannedPermanode returns a permanode with a fixed key. Like NewUnsignedPermanode, this builder is also not yet signed. Callers of NewPlannedPermanode must sign the map with a fixed claimDate and GPG date to create consistent JSON encodings of the Map (its blobref), between runs.

func NewSetAttributeClaim

func NewSetAttributeClaim(permaNode *blobref.BlobRef, attr, value string) *Builder

func NewShareRef

func NewShareRef(authType string, target *blobref.BlobRef, transitive bool) *Builder

NewShareRef creates a *Builder for a "share" claim.

func NewUnsignedPermanode

func NewUnsignedPermanode() *Builder

NewUnsignedPermanode returns a new random permanode, not yet signed.

func (*Builder) Blob

func (bb *Builder) Blob() *Blob

Blob builds the Blob. The builder continues to be usable after a call to Build.

func (*Builder) Builder

func (bb *Builder) Builder() *Builder

Builder returns a clone of itself and satisifies the Buildable interface.

func (*Builder) IsClaimType

func (bb *Builder) IsClaimType() bool

IsClaimType returns whether this blob builder is for a type which should be signed. (a "claim" or "permanode")

func (*Builder) JSON

func (bb *Builder) JSON() (string, error)

JSON returns the JSON of the blob as built so far.

func (*Builder) ModTime

func (bb *Builder) ModTime() (t time.Time, ok bool)

ModTime returns the "unixMtime" modtime field, if set.

func (*Builder) PartsSize

func (bb *Builder) PartsSize() int64

PartsSize returns the number of bytes represented by the "parts" field.

func (*Builder) PopulateDirectoryMap

func (bb *Builder) PopulateDirectoryMap(staticSetRef *blobref.BlobRef) *Builder

PopulateDirectoryMap sets the type of *Builder to "directory" and sets the "entries" field to the provided staticSet blobref.

func (*Builder) PopulateParts

func (bb *Builder) PopulateParts(size int64, parts []BytesPart) error

PopulateParts sets the "parts" field of the blob with the provided parts. The sum of the sizes of parts must match the provided size or an error is returned. Also, each BytesPart may only contain either a BytesPart or a BlobRef, but not both.

func (*Builder) SetClaimDate

func (bb *Builder) SetClaimDate(t time.Time) *Builder

SetClaimDate sets the "claimDate" on a claim. It is a fatal error to call SetClaimDate if the Map isn't of Type "claim".

func (*Builder) SetFileName

func (bb *Builder) SetFileName(name string) *Builder

SetFileName sets the fileName or fileNameBytes field. The filename is truncated to just the base.

func (*Builder) SetModTime

func (bb *Builder) SetModTime(t time.Time) *Builder

SetModTime sets the "unixMtime" field.

func (*Builder) SetRawStringField

func (bb *Builder) SetRawStringField(key, value string) *Builder

SetRawStringField sets a raw string field in the underlying map.

func (*Builder) SetSigner

func (bb *Builder) SetSigner(signer *blobref.BlobRef) *Builder

SetSigner sets the camliSigner field.

func (*Builder) SetSymlinkTarget

func (bb *Builder) SetSymlinkTarget(target string) *Builder

SetSymlinkTarget sets bb to be of type "symlink" and sets the symlink's target.

func (*Builder) SetType

func (bb *Builder) SetType(t string) *Builder

SetType sets the camliType field.

func (*Builder) Type

func (bb *Builder) Type() string

Type returns the camliType value.

type BytesPart

type BytesPart struct {
	// Size is the number of bytes that this part contributes to the overall segment.
	Size uint64 `json:"size"`

	// At most one of BlobRef or BytesRef must be set, but it's illegal for both to be set.
	// If neither are set, this BytesPart represents Size zero bytes.
	// BlobRef refers to raw bytes. BytesRef references a "bytes" schema blob.
	BlobRef  *blobref.BlobRef `json:"blobRef,omitempty"`
	BytesRef *blobref.BlobRef `json:"bytesRef,omitempty"`

	// Offset optionally specifies the offset into BlobRef to skip
	// when reading Size bytes.
	Offset uint64 `json:"offset,omitempty"`
}

BytesPart is the type representing one of the "parts" in a "file" or "bytes" JSON schema.

See doc/schema/bytes.txt and doc/schema/files/file.txt.

type Claim

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

A Claim is a Blob that is signed.

func (Claim) Attribute

func (c Claim) Attribute() string

Attribute returns the "attribute" field, if set.

func (Claim) Blob

func (c Claim) Blob() *Blob

Blob returns the claim's Blob.

func (Claim) ClaimDateString

func (c Claim) ClaimDateString() string

ClaimDate returns the blob's "claimDate" field.

func (Claim) ClaimType

func (c Claim) ClaimType() string

ClaimType returns the blob's "claimType" field.

func (Claim) ModifiedPermanode

func (c Claim) ModifiedPermanode() *blobref.BlobRef

ModifiedPermanode returns the claim's "permaNode" field, if it's a claim that modifies a permanode. Otherwise nil is returned.

func (Claim) Value

func (c Claim) Value() string

Value returns the "value" field, if set.

type ClaimType

type ClaimType string
const (
	SetAttribute ClaimType = "set-attribute"
	AddAttribute ClaimType = "add-attribute"
	DelAttribute ClaimType = "del-attribute"
)

type DirReader

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

A DirReader reads the entries of a "directory" schema blob's referenced "static-set" blob.

func NewDirReader

func NewDirReader(fetcher blobref.SeekFetcher, dirBlobRef *blobref.BlobRef) (*DirReader, error)

NewDirReader creates a new directory reader and prepares to fetch the static-set entries

func (*DirReader) Readdir

func (dr *DirReader) Readdir(n int) (entries []DirectoryEntry, err error)

Readdir implements the Directory interface.

func (*DirReader) StaticSet

func (dr *DirReader) StaticSet() ([]*blobref.BlobRef, error)

StaticSet returns the whole of the static set members of that directory

type Directory

type Directory interface {
	// Readdir reads the contents of the directory associated with dr
	// and returns an array of up to n DirectoryEntries structures.
	// Subsequent calls on the same file will yield further
	// DirectoryEntries.
	// If n > 0, Readdir returns at most n DirectoryEntry structures. In
	// this case, if Readdir returns an empty slice, it will return
	// a non-nil error explaining why. At the end of a directory,
	// the error is os.EOF.
	// If n <= 0, Readdir returns all the DirectoryEntries from the
	// directory in a single slice. In this case, if Readdir succeeds
	// (reads all the way to the end of the directory), it returns the
	// slice and a nil os.Error. If it encounters an error before the
	// end of the directory, Readdir returns the DirectoryEntry read
	// until that point and a non-nil error.
	Readdir(count int) ([]DirectoryEntry, error)
}

Directory is a read-only interface to a "directory" schema blob.

type DirectoryEntry

type DirectoryEntry interface {
	// CamliType returns the schema blob's "camliType" field.
	// This may be "file", "directory", "symlink", or other more
	// obscure types added in the future.
	CamliType() string

	FileName() string
	BlobRef() *blobref.BlobRef

	File() (File, error)           // if camliType is "file"
	Directory() (Directory, error) // if camliType is "directory"
	Symlink() (Symlink, error)     // if camliType is "symlink"
}

DirectoryEntry is a read-only interface to an entry in a (static) directory.

func NewDirectoryEntryFromBlobRef

func NewDirectoryEntryFromBlobRef(fetcher blobref.SeekFetcher, blobRef *blobref.BlobRef) (DirectoryEntry, error)

NewDirectoryEntryFromBlobRef takes a BlobRef and returns a DirectoryEntry if the BlobRef contains a type "file", "directory" or "symlink". TODO: "fifo", "socket", "char", "block", probably. later.

type File

type File interface {
	io.Closer
	io.ReaderAt
	io.Reader
	Size() int64
}

File is the interface returned when opening a DirectoryEntry that is a regular file.

type FileReader

type FileReader struct {
	// Immutable stuff:
	*io.SectionReader // provides Read, etc.
	// contains filtered or unexported fields
}

A FileReader reads the bytes of "file" and "bytes" schema blobrefs.

func NewFileReader

func NewFileReader(fetcher blobref.SeekFetcher, fileBlobRef *blobref.BlobRef) (*FileReader, error)

NewFileReader returns a new FileReader reading the contents of fileBlobRef, fetching blobs from fetcher. The fileBlobRef must be of a "bytes" or "file" schema blob.

The caller should call Close on the FileReader when done reading.

func (*FileReader) Close

func (fr *FileReader) Close() error

func (*FileReader) FileSchema

func (fr *FileReader) FileSchema() *superset

FileSchema returns the reader's schema superset. Don't mutate it.

func (*FileReader) GetChunkOffsets

func (fr *FileReader) GetChunkOffsets(c chan<- int64) error

GetChunkOffsets sends c each of the file's chunk offsets. The offsets are not necessarily sent in order, and all ranges of the file are not necessarily represented if the file contains zero holes. The channel c is closed before the function returns, regardless of error.

func (*FileReader) LoadAllChunks

func (fr *FileReader) LoadAllChunks()

LoadAllChunks causes all chunks of the file to be loaded as quickly as possible. The contents are immediately discarded, so it is assumed that the fetcher is a caching fetcher.

func (*FileReader) ReadAt

func (fr *FileReader) ReadAt(p []byte, offset int64) (n int, err error)

type MissingFieldError

type MissingFieldError string

A MissingFieldError represents a missing JSON field in a schema blob.

func (MissingFieldError) Error

func (e MissingFieldError) Error() string

type Share

type Share struct {
	Claim
}

A Share is a claim for giving access to a user's blob(s). When returned from (*Blob).AsShare, it always represents a valid share with all required fields.

func (Share) AuthType

func (s Share) AuthType() string

AuthType returns the AuthType of the Share.

func (Share) IsTransitive

func (s Share) IsTransitive() bool

IsTransitive returns whether the Share transitively gives access to everything reachable from the referenced blob.

func (Share) Target

func (s Share) Target() *blobref.BlobRef

Target returns the blob referenced by the Share.

type StatHasher

type StatHasher interface {
	Lstat(fileName string) (os.FileInfo, error)
	Hash(fileName string) (*blobref.BlobRef, error)
}

type StaticSet

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

func (*StaticSet) Add

func (ss *StaticSet) Add(ref *blobref.BlobRef)

func (*StaticSet) Blob

func (ss *StaticSet) Blob() *Blob

Map returns a Camli map of camliType "static-set" TODO: delete this method

type Symlink interface {
}

Jump to

Keyboard shortcuts

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