fs

package
v0.0.0-...-afecb3f Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: MPL-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Adapted from https://github.com/thought-machine/please Copyright Thought Machine, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const DirPermissions = os.ModeDir | 0775

DirPermissions are the default permission bits we apply to directories.

Variables

This section is empty.

Functions

func AbsoluteSystemPathFromUpstream

func AbsoluteSystemPathFromUpstream(s string) titanpath.AbsoluteSystemPath

AbsoluteSystemPathFromUpstream is used to mark return values from APIs that we expect to give us absolute paths. No checking is performed. Prefer to use this over a cast to maintain the search-ability of interfaces into and out of the titanpath.AbsoluteSystemPath type.

func CheckedToAbsoluteSystemPath

func CheckedToAbsoluteSystemPath(s string) (titanpath.AbsoluteSystemPath, error)

CheckedToAbsoluteSystemPath inspects a string and determines if it is an absolute path.

func CopyFile

func CopyFile(from *LstatCachedFile, to string) error

CopyFile copies a file from 'from' to 'to', with an attempt to perform a copy & rename to avoid chaos if anything goes wrong partway.

func CreateDirFSAtRoot

func CreateDirFSAtRoot(absolutePath string) iofs.FS

CreateDirFSAtRoot creates an `os.dirFS` instance at the root of the volume containing the specified path.

func DirContainsPath

func DirContainsPath(dir string, target string) (bool, error)

DirContainsPath returns true if the path 'target' is contained within 'dir' Expects both paths to be absolute and does not verify that either path exists.

func EnsureDir

func EnsureDir(filename string) error

EnsureDir ensures that the directory of the given file has been created.

func FileExists

func FileExists(filename string) bool

FileExists returns true if the given path exists and is a file.

func GetCwd

GetCwd returns the calculated working directory after traversing symlinks.

func GetDirFSRootPath

func GetDirFSRootPath(fsys iofs.FS) string

GetDirFSRootPath returns the root path of a os.dirFS.

func GetTurboDataDir

func GetTurboDataDir() titanpath.AbsoluteSystemPath

GetTurboDataDir returns a directory outside of the repo where titan can store data files related to titan.

func GetUserConfigDir

func GetUserConfigDir() titanpath.AbsoluteSystemPath

GetUserConfigDir returns the platform-specific common location for configuration files that belong to a user.

func GetVolumeRoot

func GetVolumeRoot(absolutePath string) string

GetVolumeRoot returns the root directory given an absolute path.

func GitLikeHashFile

func GitLikeHashFile(filePath string) (string, error)

GitLikeHashFile is a function that mimics how Git calculates the SHA1 for a file (or, in Git terms, a "blob") (without git)

func HashFile

func HashFile(filePath string) (string, error)

func HashObject

func HashObject(i interface{}) (string, error)

func IofsRelativePath

func IofsRelativePath(fsysRoot string, absolutePath string) (string, error)

IofsRelativePath calculates a `os.dirFS`-friendly path from an absolute system path.

func IsDirectory

func IsDirectory(path string) bool

IsDirectory checks if a given path is a directory

func MarshalPackageJSON

func MarshalPackageJSON(pkgJSON *PackageJSON) ([]byte, error)

MarshalPackageJSON Serialize PackageJSON to a slice of bytes

func PathExists

func PathExists(filename string) bool

PathExists returns true if the given path exists, as a file or a directory.

func RecursiveCopy

func RecursiveCopy(from string, to string) error

RecursiveCopy copies either a single file or a directory. 'mode' is the mode of the destination file.

func ResolveUnknownPath

func ResolveUnknownPath(root titanpath.AbsoluteSystemPath, unknown string) titanpath.AbsoluteSystemPath

ResolveUnknownPath returns unknown if it is an absolute path, otherwise, it assumes unknown is a path relative to the given root.

func TempDir

func TempDir(subDir string) titanpath.AbsoluteSystemPath

TempDir returns the absolute path of a directory with the given name under the system's default temp directory location

func UnsafeToAbsoluteSystemPath

func UnsafeToAbsoluteSystemPath(s string) titanpath.AbsoluteSystemPath

UnsafeToAbsoluteSystemPath directly converts a string to an AbsoluteSystemPath

func UnsafeToAnchoredSystemPath

func UnsafeToAnchoredSystemPath(s string) titanpath.AnchoredSystemPath

UnsafeToAnchoredSystemPath directly converts a string to an AbsoluteSystemPath

func Walk

func Walk(rootPath string, callback func(name string, isDir bool) error) error

Walk implements an equivalent to filepath.Walk. It's implemented over github.com/karrick/godirwalk but the provided interface doesn't use that to make it a little easier to handle.

func WalkMode

func WalkMode(rootPath string, callback func(name string, isDir bool, mode os.FileMode) error) error

WalkMode is like Walk but the callback receives an additional type specifying the file mode type. N.B. This only includes the bits of the mode that determine the mode type, not the permissions.

Types

type LstatCachedFile

type LstatCachedFile struct {
	Path titanpath.AbsoluteSystemPath
	// contains filtered or unexported fields
}

LstatCachedFile maintains a cache of file info, mode and type for the given Path

func (*LstatCachedFile) GetInfo

func (file *LstatCachedFile) GetInfo() (fs.FileInfo, error)

GetInfo returns, and caches the file info for the LstatCachedFile.Path

func (*LstatCachedFile) GetMode

func (file *LstatCachedFile) GetMode() (fs.FileMode, error)

GetMode returns, and caches the file mode for the LstatCachedFile.Path

func (*LstatCachedFile) GetType

func (file *LstatCachedFile) GetType() (fs.FileMode, error)

GetType returns, and caches the type bits of (FileMode & os.ModeType) for the LstatCachedFile.Path

type PackageJSON

type PackageJSON struct {
	Name                 string            `json:"name"`
	Version              string            `json:"version"`
	Scripts              map[string]string `json:"scripts"`
	Dependencies         map[string]string `json:"dependencies"`
	DevDependencies      map[string]string `json:"devDependencies"`
	OptionalDependencies map[string]string `json:"optionalDependencies"`
	PeerDependencies     map[string]string `json:"peerDependencies"`
	PackageManager       string            `json:"packageManager"`
	Os                   []string          `json:"os"`
	Workspaces           Workspaces        `json:"workspaces"`
	Private              bool              `json:"private"`
	// Exact JSON object stored in package.json including unknown fields
	// During marshalling struct fields will take priority over raw fields
	RawJSON map[string]interface{} `json:"-"`

	// relative path from repo root to the package.json file
	PackageJSONPath titanpath.AnchoredSystemPath `json:"-"`
	// relative path from repo root to the package
	Dir                    titanpath.AnchoredSystemPath `json:"-"`
	InternalDeps           []string                     `json:"-"`
	UnresolvedExternalDeps map[string]string            `json:"-"`
	ExternalDeps           []string                     `json:"-"`
	TransitiveDeps         []string                     `json:"-"`
	LegacyTurboConfig      *TurboJSON                   `json:"titan"`
	Mu                     sync.Mutex                   `json:"-"`
	ExternalDepsHash       string                       `json:"-"`
}

PackageJSON represents NodeJS package.json

func ReadPackageJSON

func ReadPackageJSON(path titanpath.AbsoluteSystemPath) (*PackageJSON, error)

ReadPackageJSON returns a struct of package.json

func UnmarshalPackageJSON

func UnmarshalPackageJSON(data []byte) (*PackageJSON, error)

UnmarshalPackageJSON decodes a byte slice into a PackageJSON struct

type Pipeline

type Pipeline map[string]TaskDefinition

Pipeline is a struct for deserializing .pipeline in configFile

func (Pipeline) GetTaskDefinition

func (pc Pipeline) GetTaskDefinition(taskID string) (TaskDefinition, bool)

GetTaskDefinition returns a TaskDefinition from a serialized definition in configFile

func (Pipeline) HasTask

func (pc Pipeline) HasTask(task string) bool

HasTask returns true if the given task is defined in the pipeline, either directly or via a package task (`pkg#task`)

type RemoteCacheOptions

type RemoteCacheOptions struct {
	TeamID    string `json:"teamId,omitempty"`
	Signature bool   `json:"signature,omitempty"`
}

RemoteCacheOptions is a struct for deserializing .remoteCache of configFile

type TaskDefinition

type TaskDefinition struct {
	Outputs                 TaskOutputs
	ShouldCache             bool
	EnvVarDependencies      []string
	TopologicalDependencies []string
	TaskDependencies        []string
	Inputs                  []string
	OutputMode              util.TaskOutputMode
}

TaskDefinition is a representation of the configFile pipeline for further computation.

func (*TaskDefinition) UnmarshalJSON

func (c *TaskDefinition) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes JSON into a TaskDefinition

type TaskOutputs

type TaskOutputs struct {
	Inclusions []string
	Exclusions []string
}

TaskOutputs represents the patterns for including and excluding files from outputs

type TurboJSON

type TurboJSON struct {
	GlobalDeps         []string
	GlobalEnv          []string
	Pipeline           Pipeline
	RemoteCacheOptions RemoteCacheOptions
}

TurboJSON is the root titanrepo configuration

func LoadTurboConfig

func LoadTurboConfig(rootPath titanpath.AbsoluteSystemPath, rootPackageJSON *PackageJSON, includeSynthesizedFromRootPackageJSON bool) (*TurboJSON, error)

LoadTurboConfig loads, or optionally, synthesizes a TurboJSON instance

func ReadTurboConfig

func ReadTurboConfig(rootPath titanpath.AbsoluteSystemPath, rootPackageJSON *PackageJSON) (*TurboJSON, error)

ReadTurboConfig toggles between reading from package.json or the configFile to support early adopters.

func (*TurboJSON) UnmarshalJSON

func (c *TurboJSON) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes TurboJSON objects into struct

type Workspaces

type Workspaces []string

func (*Workspaces) UnmarshalJSON

func (r *Workspaces) UnmarshalJSON(data []byte) error

type WorkspacesAlt

type WorkspacesAlt struct {
	Packages []string `json:"packages,omitempty"`
}

Jump to

Keyboard shortcuts

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