entities

package
v0.1.23-oss Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EntryTypeDevNode = EntryType(iota)
	EntryTypeDir
	EntryTypeFile
	EntryTypeSymlink
)
View Source
const (
	// Git standard modes, as defined by go-git.
	FileModeEmpty      = FileMode(filemode.Empty)
	FileModeDir        = FileMode(filemode.Dir)
	FileModeRegular    = FileMode(filemode.Regular)
	FileModeDeprecated = FileMode(filemode.Deprecated)
	FileModeExecutable = FileMode(filemode.Executable)
	FileModeSymlink    = FileMode(filemode.Symlink)
	FileModeSubmodule  = FileMode(filemode.Submodule)

	// Modes after this are not git standard modes
	FileModeDevNode  FileMode = 0200000
	FileModeDeepTree FileMode = 0210000
)
View Source
const (
	// HashSize is the number of bytes in a Hash.
	HashSize = hash.Size
	// HashHexSize is the length of a Hash in hexadecimal notation.
	HashHexSize = hash.HexSize
)
View Source
const (
	ABFSMetaServer  = "default-server"
	ABFSMetaProject = "abfs-meta"
)
View Source
const (
	// SHA256Size is the number of bytes in a SHA256.
	SHA256Size = plumbing.SHA256Size
	// SHA256HexSize is the length of a SHA256 in hexadecimal notation.
	SHA256HexSize = plumbing.SHA256HexSize
)
View Source
const ABFSSocketFileName = ".abfs.sock"
View Source
const DistDirVar = "DIST_DIR"
View Source
const MismatchesLogFile = ".abfs_mismatches"
View Source
const (
	// NSJailConfigPathEnv names the environment variable holding the path, relative to the
	// top of the source tree, of the NSJail build config XML. If unset, no config is loaded.
	NSJailConfigPathEnv = "ABFS_NSJAIL_CONFIG"
)
View Source
const OutDirVar = "OUT_DIR"

Variables

View Source
var (
	ErrEntryNotFound       = errors.New("entry not found")
	ErrNotADirectory       = errors.New("entry is not a directory")
	ErrEntryADirectory     = errors.New("entry is a directory")
	ErrNotAFile            = errors.New("entry is not a file")
	ErrEntryExists         = errors.New("entry already exists")
	ErrNotADirectoryObject = errors.New("expected a directory object")
	ErrDirNotEmpty         = errors.New("directory not empty")
)
View Source
var DistDir = path.Join(OutDir, "dist")
View Source
var EmptyDirContent = []byte("tree 0\x00")
View Source
var EmptyFileContent = []byte("blob 0\x00")
View Source
var ErrNotExist = fs.ErrNotExist
View Source
var ErrObjectParse = errors.New("failed to parse the object")
View Source
var OutDir = "out"
View Source
var PatchEntryMapName = map[PatchEntryState]string{
	PatchEntryStateUnassigned:       "unassigned",
	PatchEntryStateDirModified:      "dir-modified",
	PatchEntryStateDir:              "dir",
	PatchEntryStateIn:               "input",
	PatchEntryStateDep:              "dep",
	PatchEntryStateRSP:              "rsp",
	PatchEntryStateExtraIn:          "extra-input",
	PatchEntryStateExtraRead:        "hidden",
	PatchEntryStateNotReadRSP:       "not-read-rsp",
	PatchEntryStateNotReadDep:       "not-read-dep",
	PatchEntryStateOrderOnly:        "order-only",
	PatchEntryStateNotReadOrderOnly: "not-read-order-only",
	PatchEntryInfoAutoSnapshot:      "auto-snapshot",
	PatchEntryStateOut:              "target",
	PatchEntryStateDepFile:          "depfile",
	PatchEntryStateExtraWrite:       "extra-write",
	PatchEntryStateMissingDepFile:   "missing-depfile",
	PatchEntryStateMissingOut:       "missing-target",
}

Const patch entry names

View Source
var (
	ZeroSHA256 = SHA256(plumbing.ZeroSHA256)
)

Functions

func BlobSizeAfterCompressed

func BlobSizeAfterCompressed(fileSize int64) int64

Note: This only handle the case of compression level 0

func ChrootTransform

func ChrootTransform(path, chroot string) string

Transform paths to remove the input 'chroot'.

func CloseErrCheck

func CloseErrCheck(c io.Closer, err *error)

func DecodeObject

func DecodeObject(content []byte) (string, []byte, error)

func FirstError

func FirstError(errs ...error) error

func IgnoreNotExistErr

func IgnoreNotExistErr(err error) error

func IsDev

func IsDev() bool

func IsHash

func IsHash(s string) bool

IsHash reports whether s is a valid hexadecimal hash.

func IsNotExist

func IsNotExist(err error) bool

func IsSHA256

func IsSHA256(s string) bool

IsSHA256 reports whether s is a valid hexadecimal SHA-256 hash.

func ModeToString

func ModeToString(m FileMode) string

func NotExistErrf

func NotExistErrf(format string, a ...any) error

func PathApply

func PathApply(a, b string) string

func PathDiff

func PathDiff(a, b string) string

func TapTypes

func TapTypes() string

func WrapNotExist

func WrapNotExist(err error) error

func WriteObject

func WriteObject(objType string, content []byte, w io.Writer) error

Types

type BlobStore

type BlobStore interface {
	OpenBlob(ctx context.Context, key Hash) (io.ReadCloser, error)
	WriteBlob(ctx context.Context, key Hash, size int64, reader io.Reader) error
}

type CASStore

type CASStore interface {
	BlobStore
	ObjectStore
	MapStore
	RefStore
	io.Closer
	CAS() cas.Store
	// TODO: Optimize keep alive: change the interface to keys []entities.Hash
	KeepAlive(ctx context.Context, key Hash) error
	// IsObjectRemote is for both objects and blobs.
	// It will firstly check the remote attribute if the object is in the local cache.
	// If it's not, it will then check if it's on the remote server by requesting the header.
	IsObjectRemote(ctx context.Context, key Hash) (bool, error)
	StartGC(ctx context.Context) error
	HealthCheck() error
}

type DeepEntry

type DeepEntry struct {
	Name string
	Mode FileMode
	Hash Hash
	Size int64
}

type DeepTree

type DeepTree struct {
	Entries []*DeepEntry
}

type DeletePatch

type DeletePatch []string

func (DeletePatch) ChrootTransform

func (p DeletePatch) ChrootTransform(chroot string)

func (DeletePatch) MarshalJSON

func (p DeletePatch) MarshalJSON() ([]byte, error)

func (*DeletePatch) UnmarshalJSON

func (p *DeletePatch) UnmarshalJSON(data []byte) error

type EntryType

type EntryType int

func (EntryType) String

func (e EntryType) String() string

type FSConfig

type FSConfig struct {
	Debug       bool
	LogHttp     bool
	LogPathsStr []string         `json:"LogPaths"`
	LogPaths    []*regexp.Regexp `json:"-"`

	IgnoreSoongEnvAvail bool
}

type FileEntry

type FileEntry struct {
	Name string
	Mode FileMode
	Hash Hash
	Size int64
}

func DecodeDir

func DecodeDir(buf []byte, meta TreeMeta) ([]FileEntry, error)

func DecodeDirPlain

func DecodeDirPlain(buf []byte) ([]FileEntry, error)

DecodeDirPlain is similar to DecodeDir, but the sizes of the entries won't be present in the returned objects since they weren't provided.

type FileMode

type FileMode uint32

FileMode is a Git file mode, extended with ABFS-specific modes (see FileModeDevNode and FileModeDeepTree) and a stat-operation bit. String, ToOSFileMode and FileModeNew delegate to the go-git code in third_party/go-git.

const (
	PatchStatOperation FileMode = 01000000
	SrcDir                      = "/src"
)

func FileModeFromLetter

func FileModeFromLetter(s string) (FileMode, error)

func FileModeNew

func FileModeNew(s string) (FileMode, error)

FileModeNew parses the octal string representation of a FileMode. On error it returns FileModeEmpty.

func ModeToFileMode

func ModeToFileMode(mode fs.FileMode) FileMode

func (FileMode) IsDir

func (m FileMode) IsDir() bool

func (FileMode) IsFile

func (m FileMode) IsFile() bool
func (m FileMode) IsFileOrSymlink() bool

func (FileMode) IsStat

func (m FileMode) IsStat() bool

func (*FileMode) SetStat

func (m *FileMode) SetStat()

func (FileMode) String

func (m FileMode) String() string

String returns m as a 7-digit, zero-padded octal number.

func (FileMode) ToLetter

func (m FileMode) ToLetter() string

func (FileMode) ToOSFileMode

func (m FileMode) ToOSFileMode() (os.FileMode, error)

ToOSFileMode returns the os.FileMode to use for a file system entry with Git mode m, or an error if m has no file system equivalent.

func (*FileMode) UnsetStat

func (m *FileMode) UnsetStat()

type Hash

type Hash [HashSize]byte

Hash is a SHA-1 object hash.

var (
	ZeroHash      = Hash(plumbing.ZeroHash)
	EmptyFileHash Hash
	EmptyDirHash  Hash
)

func NewHash

func NewHash(s string) Hash

NewHash parses a hexadecimal hash. Invalid input yields a zero or partial hash; use IsHash to validate first.

func (Hash) IsZero

func (h Hash) IsZero() bool

IsZero reports whether h is the zero hash.

func (Hash) MarshalJSON

func (h Hash) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Hash.

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Hash) String

func (h Hash) String() string

String returns h in hexadecimal notation.

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Hash.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type HashStat

type HashStat struct {
	Hash Hash
	Mode FileMode
	Size int64
}

HashStat is useful because it is the info needed to recreate a file. The Hash will allow the store to look up the content and the mode stores permission bits. The size is also useful for creation so a stat can work without needing a server lookup of the hash.

type MapStore

type MapStore interface {
	MapResults(ctx context.Context, id Hash) ([]Hash, error)
	RefreshMapResults(ctx context.Context, id Hash) error
	AddMapResult(ctx context.Context, from, to Hash) error
}

type NSJailAllowReadWrite

type NSJailAllowReadWrite struct {
	XMLName xml.Name `xml:"allow_readwrite"`
	Path    string   `xml:"path,attr"`
}

NSJailAllowReadWrite represents an <allow_readwrite> element

type NSJailBuildConfig

type NSJailBuildConfig struct {
	XMLName       xml.Name              `xml:"build_config"`
	Name          string                `xml:"name,attr,omitempty"`
	AndroidTarget string                `xml:"android_target,attr,omitempty"`
	Goals         []NSJailGoal          `xml:"goal"`
	Flags         []NSJailFlag          `xml:"flag"`
	Configs       []NSJailConfigElement `xml:"config"` // For fetch_target within build_config
	// contains filtered or unexported fields
}

NSJailBuildConfig represents a <build_config> element

type NSJailConfig

type NSJailConfig struct {
	XMLName        xml.Name                      `xml:"config"`
	Targets        []*NSJailTarget               `xml:"target"`
	Views          []NSJailView                  `xml:"view"` // Keep Views here for unmarshaling
	BuildConfigMap map[string]*NSJailBuildConfig `xml:"-"`
}

NSJailConfig is the root element

func LoadNSJailConfig

func LoadNSJailConfig(mountPoint string) (NSJailConfig, error)

LoadNSJailConfig will load the NSJail config.

func (*NSJailConfig) LunchableAndroidTarget

func (n *NSJailConfig) LunchableAndroidTarget(target string) string

LunchableAndroidTarget target will return a lunchable Android target given a target.

func (*NSJailConfig) OverlaysForBuildTarget

func (n *NSJailConfig) OverlaysForBuildTarget(buildTarget string) []string

OverlaysForBuildTarget returns the names of each overlay directory for a given build target.

func (*NSJailConfig) ViewsForBuildTarget

func (n *NSJailConfig) ViewsForBuildTarget(buildTarget string) []string

type NSJailConfigElement

type NSJailConfigElement struct {
	XMLName xml.Name `xml:"config"`
	Name    string   `xml:"name,attr,omitempty"`  // For name="fetch_build" or "fetch_target"
	Value   string   `xml:"value,attr,omitempty"` // For value="8061540" or "<target>_partial-userdebug""
}

NSJailConfigElement represents a <config> element inside a <target> or <build_config> Renamed to avoid conflict with the root NSJailConfig struct

type NSJailFlag

type NSJailFlag struct {
	XMLName  xml.Name `xml:"flag"`
	Name     string   `xml:"name,attr"`
	Contexts string   `xml:"contexts,attr,omitempty"` // omitempty if contexts might not be present
}

NSJailFlag represents a <flag> element

type NSJailGoal

type NSJailGoal struct {
	XMLName xml.Name `xml:"goal"`
	Name    string   `xml:"name,attr"`
}

NSJailGoal represents a <goal> element

type NSJailOverlay

type NSJailOverlay struct {
	XMLName xml.Name `xml:"overlay"`
	Name    string   `xml:"name,attr"`
}

NSJailOverlay represents an <overlay> element

type NSJailPath

type NSJailPath struct {
	XMLName     xml.Name `xml:"path"`
	Source      string   `xml:"source,attr"`
	Destination string   `xml:"destination,attr"`
}

NSJailPath represents a <path> element within a <view>

type NSJailTarget

type NSJailTarget struct {
	XMLName         xml.Name               `xml:"target"`
	Name            string                 `xml:"name,attr"`
	Tags            string                 `xml:"tags,attr,omitempty"`
	Overlays        []NSJailOverlay        `xml:"overlay"`
	AllowReadWrites []NSJailAllowReadWrite `xml:"allow_readwrite"`
	BuildConfigs    []*NSJailBuildConfig   `xml:"build_config"`
	Configs         []NSJailConfigElement  `xml:"config"` // For fetch_build, fetch_target inside vf_targets
	Views           []NSJailView           `xml:"view"`   // This will store just a name
}

NSJailTarget represents a <target> element

type NSJailView

type NSJailView struct {
	XMLName xml.Name     `xml:"view"`
	Name    string       `xml:"name,attr"`
	Paths   []NSJailPath `xml:"path"`
}

NSJailView represents a <view> element

type NotExistErr

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

func (*NotExistErr) Error

func (e *NotExistErr) Error() string

func (*NotExistErr) Unwrap

func (e *NotExistErr) Unwrap() []error

type ObjectHeader

type ObjectHeader struct {
	Type           ObjectType
	Size           int64
	CompressedSize int64 // size after zlib compressed
}

func (*ObjectHeader) FileSize

func (h *ObjectHeader) FileSize() int64

func (*ObjectHeader) IsBlob

func (h *ObjectHeader) IsBlob() bool

func (*ObjectHeader) IsEmpty

func (h *ObjectHeader) IsEmpty() bool

type ObjectStore

type ObjectStore interface {
	OpenObjectFile(ctx context.Context, key Hash) (io.ReadCloser, error)
	GetObject(ctx context.Context, key Hash) ([]byte, error)
	GetTree(ctx context.Context, key Hash) ([]byte, TreeMeta, error)
	PutObject(ctx context.Context, key Hash, content []byte) error
	PutTree(ctx context.Context, key Hash, content []byte, meta TreeMeta) error
	WriteObject(ctx context.Context, key Hash, reader io.Reader) error
	ObjectHeader(ctx context.Context, key Hash) (ObjectHeader, error)
}

type ObjectType

type ObjectType string
const (
	ObjectTypeBlob    ObjectType = "blob"
	ObjectTypeUnknown ObjectType = "unknown"
)

type Patch

type Patch []*PatchEntry

func (Patch) ChrootTransform

func (p Patch) ChrootTransform(chroot string)

func (Patch) HashForPath

func (p Patch) HashForPath(path string) (h Hash)

func (Patch) HashStatForPath

func (p Patch) HashStatForPath(path string) (h HashStat)

func (Patch) MarshalJSON

func (p Patch) MarshalJSON() ([]byte, error)

func (*Patch) UnmarshalJSON

func (p *Patch) UnmarshalJSON(data []byte) error

type PatchEntry

type PatchEntry struct {
	Path  string
	Mode  FileMode
	Hash  Hash
	Size  int64
	State PatchEntryState
}

func (*PatchEntry) SetState

func (p *PatchEntry) SetState(s PatchEntryState)

type PatchEntryState

type PatchEntryState int
const (
	// Default state before the state evaluation
	PatchEntryStateUnassigned PatchEntryState = 0
	// The patch is associated with a directory but the directory is modified during the build step
	PatchEntryStateDirModified PatchEntryState = 1
	// The patch is associated with a directory
	PatchEntryStateDir PatchEntryState = 2

	// Read states:
	//   Declared input in ninja and is read by the build process
	PatchEntryStateIn PatchEntryState = 3
	//   Found in the dep-file (.d file) and is read by the build process
	PatchEntryStateDep PatchEntryState = 4
	//   Declared as RSP file and is read by the build process
	PatchEntryStateRSP PatchEntryState = 5
	//   Declared input in ninja, but the build process has not read it
	PatchEntryStateExtraIn PatchEntryState = 6
	//   Not declared in the ninja, but the build process has read it (hidden dependency)
	PatchEntryStateExtraRead PatchEntryState = 7
	//   Declared as RSP file, but the build process has not read it
	PatchEntryStateNotReadRSP PatchEntryState = 8
	//   Found in the dep-file (.d file), but the build process has not read it
	PatchEntryStateNotReadDep PatchEntryState = 9
	//   Declared as Order-only input and the build process has read it
	PatchEntryStateOrderOnly PatchEntryState = 20
	//   Declared as Order-only input and but the build process has not read it
	PatchEntryStateNotReadOrderOnly PatchEntryState = 21
	//   Found read file that was not committed, file was auto snapshot
	PatchEntryInfoAutoSnapshot PatchEntryState = 22
	// Write states:
	//   Declared as a target in ninja and is written by the build process
	PatchEntryStateOut PatchEntryState = 10
	//   Declared as a depfile in ninja and is written by the build process
	PatchEntryStateDepFile PatchEntryState = 11
	//   Not declared in the ninja, but is written by the build process
	PatchEntryStateExtraWrite PatchEntryState = 12
	//   Declared as a depfile in ninja, but build process has not written it
	PatchEntryStateMissingDepFile PatchEntryState = 13
	//   Declared as a target in ninja, but build process has not written it
	PatchEntryStateMissingOut PatchEntryState = 14
)

func PatchEntryStateByName

func PatchEntryStateByName(s string) (PatchEntryState, error)

func (PatchEntryState) IsOrderOnly

func (s PatchEntryState) IsOrderOnly() bool

func (PatchEntryState) IsStateSetByTap

func (s PatchEntryState) IsStateSetByTap() bool

IsStateSetByTap identifies the "low-level" states that tap sets and shouldn't be overwritten

func (PatchEntryState) String

func (s PatchEntryState) String() string

type ProjectRefHash

type ProjectRefHash struct {
	Project string
	Ref     string
	Hash    Hash
}

type RefHash

type RefHash struct {
	Ref  string
	Hash Hash
}

type RefStore

type RefStore interface {
	GetRefs(server string, project string, refs []string) ([]Hash, error)
	SearchRefs(server string, project string, refPrefix string, limit int) ([]ProjectRefHash, error)
	PutRefs(server string, project string, refs []RefHash) error
}

type SHA256

type SHA256 [SHA256Size]byte

SHA256 is a SHA-256 content hash.

func NewSHA256

func NewSHA256(s string) SHA256

NewSHA256 parses a hexadecimal SHA-256 hash. Invalid input yields a zero or partial hash; use IsSHA256 to validate first.

func (SHA256) IsZero

func (h SHA256) IsZero() bool

IsZero reports whether h is the zero hash.

func (SHA256) MarshalJSON

func (h SHA256) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for SHA256.

func (SHA256) MarshalText

func (h SHA256) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (SHA256) String

func (h SHA256) String() string

String returns h in hexadecimal notation.

func (*SHA256) UnmarshalJSON

func (h *SHA256) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for SHA256.

func (*SHA256) UnmarshalText

func (h *SHA256) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Sizer

type Sizer interface {
	Size() (size int64, err error)
}

type StatInfo

type StatInfo struct {
	Size    int64
	Mode    FileMode
	GitType ObjectType
}

type SyncHashSet

type SyncHashSet [256]*sync.Map

func NewHashSet

func NewHashSet() SyncHashSet

func (SyncHashSet) Has

func (s SyncHashSet) Has(h Hash) bool

func (SyncHashSet) Put

func (s SyncHashSet) Put(h Hash) bool

type TapCmdResult

type TapCmdResult struct {
	TapData
	Pid              int
	ExitCode         int
	TapCounts        map[string]uint64
	Rusage           *syscall.Rusage
	Timestamp        time.Time
	RunDuration      float64
	SnapshotDuration float64
	Stdout           string
	Stderr           string
}

type TapData

type TapData struct {
	ReadPatch  Patch
	WritePatch Patch
	Deletes    DeletePatch
	TapEntries []*TapFSEntry
}

type TapFSEntry

type TapFSEntry struct {
	Type    TapType
	Dirty   bool
	IsARI   bool
	Path    string
	ARI     string
	Hash    Hash
	AuxPath string
	Mode    fs.FileMode
	Size    int64
}

Use one generic type for all entries

type TapType

type TapType int
const (
	TapFSMkdir       TapType = 0
	TapFSSymlink     TapType = 1
	TapFSLink        TapType = 2
	TapFSUnlink      TapType = 3
	TapFSRename      TapType = 4
	TapFSReadDir     TapType = 5
	TapFSSymlinkRead TapType = 6
	TapFSStat        TapType = 7
	TapFSOpenRead    TapType = 8
	TapFSOpenWrite   TapType = 9
	TapFSAttrChange  TapType = 10
)

func (TapType) String

func (t TapType) String() string

type TappingType

type TappingType string
const (
	TapFS      TappingType = "fs"
	TapEntries TappingType = "entries"
)

func (*TappingType) Set

func (t *TappingType) Set(value string) error

func (*TappingType) String

func (t *TappingType) String() string

func (*TappingType) Type

func (t *TappingType) Type() string

type TreeMeta

type TreeMeta struct {
	Sizes []int64
}

Jump to

Keyboard shortcuts

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