watchman

package
v0.0.0-...-841f565 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicFields

func BasicFields() []string

BasicFields returns a list of basic fields

func GetSocketName

func GetSocketName() (string, error)

GetSocketName returns a strong containing the location of the watchman conn

func IsBinaryInstalled

func IsBinaryInstalled() bool

IsBinaryInstalled checks if watchman is visible in the os path

func JSONUnmarshalCommand

func JSONUnmarshalCommand(cmd *exec.Cmd, v interface{}) error

JSONUnmarshalCommand accepts a cmd pointer, and an arbitrary interface executes that command and attempts to unmarshal the output as JSON if the command returns a JSON value that contains an error key it will attempt to raise a new error with the string value of that error key

if the error key contains a value other than a string this function will panic

func Path

func Path() (string, error)

Path returns a string containing the path to the watchman binary

func PathOnce

func PathOnce() (path string, err error)

PathOnce cached the path to the watchman binary

Types

type Client

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

Client a client interface for the watchman conn protocol

func Connect

func Connect(ctx context.Context, timeoutSeconds int) (*Client, error)

Connect will attempt to connect to the watchman conn service for IPC

func (*Client) CheckCapabilities

func (client *Client) CheckCapabilities(opts VersionOptions) (resp VersionResponse, err error)

CheckCapabilities checks the capabilities of the watchman socket service using the version command returns an error if the required capabilities are not present https://facebook.github.io/watchman/docs/cmd/version.html

func (*Client) Close

func (client *Client) Close() error

Close closes the connection to the watchman socket service

func (*Client) DeleteAll

func (client *Client) DeleteAll() (resp DeleteAllResponse, err error)

DeleteAll Requests that the project containing the requested dir is watched for changes. Watchman will track all files and dirs rooted at the project path, and respond with the relative path difference between the project path and the requested dir. https://facebook.github.io/watchman/docs/cmd/watch-del-all.html

func (*Client) Exec

func (client *Client) Exec(cmd RawPDUCommand, destResp interface{}) error

Exec executes a command on the server synchronously and marshals the response into the given struct This function will raise an error if you do not supply for the destResp

func (*Client) Find

func (client *Client) Find(opts FindOptions) (resp FindResponse, err error)

Find lists all files that match the optional patterns under the specified dir. When no patterns are provided, all files are returned. https://facebook.github.io/watchman/docs/cmd/find.html

func (*Client) ListCapabilities

func (client *Client) ListCapabilities() (resp ListCapabilitiesResponse, err error)

ListCapabilities lists the capabilities of the watchman socket service https://facebook.github.io/watchman/docs/cmd/list-capabilities.html

func (*Client) Query

func (client *Client) Query(opts QueryOptions) (resp QueryResponse, err error)

Query executes a query against the specified root. https://facebook.github.io/watchman/docs/cmd/query.html

func (*Client) Receive

func (client *Client) Receive() (resp RawPDUResponse, err error)

Receive attempts to read a single JSON encoded PDU response line from the watchman socket service if the response contains an error key it will raise an error with its value if the response contains an error key, and it's value is a string this process will panic

func (*Client) Send

func (client *Client) Send(rawCmd RawPDUCommand) error

Send issues a command to the watchman socket service

func (*Client) Watch deprecated

func (client *Client) Watch(opts WatchOptions) (resp WatchResponse, err error)

Watch Requests that the specified dir is watched for changes. Watchman will track all files and dirs rooted at the specified path. https://facebook.github.io/watchman/docs/cmd/watch.html

Deprecated:starting in version 3.1. We recommend that clients adopt the watch-project command. https://facebook.github.io/watchman/docs/cmd/watch-project.html

func (*Client) WatchProject

func (client *Client) WatchProject(opts WatchProjectOptions) (resp WatchProjectResponse, err error)

WatchProject Requests that the project containing the requested dir is watched for changes. Watchman will track all files and dirs rooted at the project path, and respond with the relative path difference between the project path and the requested dir. https://facebook.github.io/watchman/docs/cmd/watch-project.html

type DeleteAllResponse

type DeleteAllResponse struct {
	Version string   `json:"version" mapstructure:"version"`
	Root    []string `json:"root" mapstructure:"root"`
}

DeleteAllResponse https://facebook.github.io/watchman/docs/cmd/watch-del-all.html

type File

type File struct {
	Name   string `json:"name" mapstructure:"name"`     // Name the filename, relative to the watched root
	Exists bool   `json:"exists" mapstructure:"exists"` // true if the file exists, false if it has been deleted

	CClock string `json:"cclock" mapstructure:"cclock"` // the “created clock”; the clock value when we first observed the file, or the clock value when it last switched from !exists to exists.
	OClock string `json:"oclock" mapstructure:"oclock"` // the “observed clock”; the clock value where we last observed some change in this file or its metadata.

	CTime   int64 `json:"ctime" mapstructure:"ctime"`       // last inode change time measured in integer second
	CTimeMs int64 `json:"ctime_ms" mapstructure:"ctime_ms"` // last inode change time measured in integer millisecond
	CTimeUs int64 `json:"ctime_us" mapstructure:"ctime_us"` // last inode change time measured in integer microsecond
	CTimeNs int64 `json:"ctime_ns" mapstructure:"ctime_ns"` // last inode change time measured in integer nanosecond
	CTimeF  int64 `json:"ctime_f" mapstructure:"ctime_f"`   // last inode change time measured in floating-point second

	MTime   int64 `json:"mtime" mapstructure:"mtime"`       // modified time measured in integer seconds
	MTimeMs int64 `json:"mtime_ms" mapstructure:"mtime_ms"` // modified time measured in integer milliseconds
	MTimeUs int64 `json:"mtime_us" mapstructure:"mtime_us"` // modified time measured in integer microseconds
	MTimeNs int64 `json:"mtime_ns" mapstructure:"mtime_ns"` // modified time measured in integer nanoseconds
	MTimeF  int64 `json:"mtime_f" mapstructure:"mtime_f"`   // modified time measured in floating-point seconds

	Size  int  `json:"size" mapstructure:"size"`   // file size in bytes
	Mode  int  `json:"mode" mapstructure:"mode"`   // file (or directory) mode expressed as a decimal integer
	Uid   int  `json:"uid" mapstructure:"uid"`     // the owning uid
	Gid   int  `json:"gid" mapstructure:"gid"`     // the owning gid
	Ino   int  `json:"ino" mapstructure:"ino"`     // the inode number
	Dev   int  `json:"dev" mapstructure:"dev"`     // the device number
	Nlink int  `json:"nlink" mapstructure:"nlink"` // number of hard links
	New   bool `json:"new" mapstructure:"new"`     // whether this entry is newer than the since generator criteria

	// Since 3.1.
	Type string `json:"type" mapstructure:"type"` // File type. Values listed in the type query expression (https://facebook.github.io/watchman/docs/expr/type.html)

	// Since 4.6.
	SymlinkTarget string `json:"symlink_target" mapstructure:"symlink_target"` // the target of a symbolic link if the file is a symbolic link

	// Since 4.9.
	ContentSHA1Hex string `json:"content.sha1hex" mapstructure:"content.sha1hex"` // the SHA-1 digest of the file’s byte content, encoded as 40 hexadecimal digits (e.g. "da39a3ee5e6b4b0d3255bfef95601890afd80709" for an empty file)
}

File https://facebook.github.io/watchman/docs/cmd/query.html

type FileHasher

type FileHasher []File

FileHasher file hasher is a complex type for a slice of watchman.File

func (FileHasher) CalculateRootHash

func (fh FileHasher) CalculateRootHash() string

CalculateRootHash returns a sha256 of the files

type FindOptions

type FindOptions struct {
	Directory string
	Patterns  []string
}

FindOptions https://facebook.github.io/watchman/docs/cmd/find.html

type FindResponse

type FindResponse struct {
	Version string `json:"version" mapstructure:"version"`
	Clock   string `json:"clock" mapstructure:"clock"`
	Files   []File `json:"files" mapstructure:"files"`
}

FindResponse https://facebook.github.io/watchman/docs/cmd/find.html

type ListCapabilitiesResponse

type ListCapabilitiesResponse struct {
	Version      string   `json:"version" mapstructure:"version"`
	Capabilities []string `json:"capabilities" mapstructure:"capabilities"`
}

ListCapabilitiesResponse https://facebook.github.io/watchman/docs/cmd/list-capabilities.html

func (ListCapabilitiesResponse) HasCapability

func (l ListCapabilitiesResponse) HasCapability(check string) bool

HasCapability returns true if the capability is in the list

type OnChangeNotification

type OnChangeNotification func(change SubscriptionChangeFeedResponse)

OnChangeNotification a callback that can handle change feed notifications

type OnErrorNotification

type OnErrorNotification func(err error)

OnErrorNotification a callback that can handle watchman socket errors

type QueryFilter

type QueryFilter struct {
	Since               string        `json:"since,omitempty" mapstructure:"since"`                               // The clock to use for querying changes
	Fields              []string      `json:"fields,omitempty" mapstructure:"fields"`                             // a list of fields to project file objects
	Expression          []interface{} `json:"expression,omitempty" mapstructure:"expression"`                     // any valid expression to query the file system
	Glob                []string      `json:"glob,omitempty" mapstructure:"glob"`                                 // https://facebook.github.io/watchman/docs/file-query.html#glob-generator
	DeferVcs            bool          `json:"defer_vcs,omitempty" mapstructure:"defer_vcs"`                       // https://facebook.github.io/watchman/docs/cmd/subscribe.html#filesystem-settling
	Defer               []string      `json:"defer,omitempty" mapstructure:"defer"`                               // https://facebook.github.io/watchman/docs/cmd/subscribe.html#defer
	Drop                []string      `json:"drop,omitempty" mapstructure:"drop"`                                 // https://facebook.github.io/watchman/docs/cmd/subscribe.html#drop
	DedupResults        bool          `json:"dedup_results,omitempty" mapstructure:"dedup_results"`               // https://facebook.github.io/watchman/docs/file-query.html#de-duplicating-results
	GlobIncludeDotFiles bool          `json:"glob_includedotfiles,omitempty" mapstructure:"glob_includedotfiles"` // https://github.com/facebook/watchman/issues/647#issuecomment-422252118
}

QueryFilter the optional query parameters for a query

type QueryOptions

type QueryOptions struct {
	Directory string
	Filter    *QueryFilter
}

QueryOptions https://facebook.github.io/watchman/docs/cmd/find.html

type QueryResponse

type QueryResponse struct {
	Version         string `json:"version" mapstructure:"version"`
	Clock           string `json:"clock" mapstructure:"clock"`
	IsFreshInstance bool   `json:"is_fresh_instance" mapstructure:"is_fresh_instance"`
	Files           []File `json:"files" mapstructure:"files"`
}

QueryResponse https://facebook.github.io/watchman/docs/cmd/find.html

type RawPDUCommand

type RawPDUCommand []interface{}

RawPDUCommand is the raw structure required to serialize a command for the socket server

type RawPDUCommandOptions

type RawPDUCommandOptions map[string]interface{}

RawPDUCommandOptions is a raw PDU options object

type RawPDUResponse

type RawPDUResponse map[string]interface{}

RawPDUResponse is the raw PDU response structure from the socket

func (RawPDUResponse) Decode

func (resp RawPDUResponse) Decode(v interface{}) error

Decode decodes the raw PDU response into a struct pointer Note: this will panic if you do not supply a pointer

type SubscribeOptions

type SubscribeOptions struct {
	Name   string `json:"name" mapstructure:"name"` // the name of the subscription used to provide unilateral responses
	Root   string `json:"root" mapstructure:"root"` // the relative root to subscribe for changes
	Filter *QueryFilter
}

SubscribeOptions https://facebook.github.io/watchman/docs/cmd/subscribe.html

type Subscription

type Subscription struct {
	Cancel                chan bool
	Errors                chan error
	ChangeFeed            chan SubscriptionChangeFeedResponse
	CancelOnFirstError    bool
	IgnoreInitialResponse bool
	RawCommand            RawPDUCommand
	// contains filtered or unexported fields
}

Subscription a sub

func Subscribe

func Subscribe(opts SubscribeOptions, cancelOnFirstError bool, ignoreInitialResponse bool) (sub *Subscription, err error)

Subscribe The updates will continue to be sent while the connection is open. If the connection is closed, the subscription is implicitly removed. https://facebook.github.io/watchman/docs/cmd/subscribe.html

In some circumstances it is desirable for a client to observe the creation of the control files at the start of a version control operation. You may specify that you want this behavior by passing the defer_vcs flag to your subscription command invocation https://facebook.github.io/watchman/docs/cmd/subscribe.html#filesystem-settling

Some applications will want to know that the update is in progress and continue to process notifications. Others may want to defer processing the notifications until the update completes, and some may wish to drop any notifications produced while the update was in progress. https://facebook.github.io/watchman/docs/cmd/subscribe.html#advanced-settling

func (*Subscription) Canceled

func (sub *Subscription) Canceled() bool

Canceled checks if the subscription has been canceled

func (*Subscription) OnChangeNotification

func (sub *Subscription) OnChangeNotification(onChange OnChangeNotification)

OnChangeNotification executes the callback function in a go routine for every change detected on the file system

func (*Subscription) OnErrorNotification

func (sub *Subscription) OnErrorNotification(onError OnErrorNotification)

OnErrorNotification executes the callback function in a go routine for every error returned from the socket

func (*Subscription) PushChange

func (sub *Subscription) PushChange(change SubscriptionChangeFeedResponse) bool

PushChange sends a change over the change feed channel

func (*Subscription) PushError

func (sub *Subscription) PushError(err error) bool

PushError sends an error over the errors channel

func (*Subscription) Unsubscribe

func (sub *Subscription) Unsubscribe() bool

Unsubscribe shuts down the subscription

func (*Subscription) Wait

func (sub *Subscription) Wait() bool

Wait synchronously blocks awaiting the cancellation signal

type SubscriptionChangeFeedResponse

type SubscriptionChangeFeedResponse struct {
	Version         string `json:"version" mapstructure:"version"`
	Unilateral      bool   `json:"unilateral" mapstructure:"unilateral"`
	Clock           string `json:"clock" mapstructure:"clock"`
	Files           []File `json:"files" mapstructure:"files"`
	Root            string `json:"root" mapstructure:"root"`
	Subscription    string `json:"subscription" mapstructure:"subscription"`
	IsFreshInstance bool   `json:"is_fresh_instance" mapstructure:"is_fresh_instance"`
}

SubscriptionChangeFeedResponse https://facebook.github.io/watchman/docs/cmd/subscribe.html

type VersionOptions

type VersionOptions struct {
	Optional []string
	Required []string
}

VersionOptions https://facebook.github.io/watchman/docs/cmd/version.html

type VersionResponse

type VersionResponse struct {
	Version      string          `json:"version" mapstructure:"version"`
	Capabilities map[string]bool `json:"capabilities" mapstructure:"capabilities"`
}

VersionResponse https://facebook.github.io/watchman/docs/cmd/version.html

type WatchOptions

type WatchOptions struct {
	Directory string
}

WatchOptions https://facebook.github.io/watchman/docs/cmd/watch.html Deprecated: starting in version 3.1. We recommend that clients adopt the watch-project command. https://facebook.github.io/watchman/docs/cmd/watch-project.html

type WatchProjectOptions

type WatchProjectOptions struct {
	Directory string
}

WatchProjectOptions https://facebook.github.io/watchman/docs/cmd/watch-project.html

type WatchProjectResponse

type WatchProjectResponse struct {
	Version string `json:"version" mapstructure:"version"`
	Watch   string `json:"watch" mapstructure:"watch"`
	Watcher string `json:"watcher" mapstructure:"watcher"`
	RelPath string `json:"relative_path" mapstructure:"relative_path"`
}

WatchProjectResponse https://facebook.github.io/watchman/docs/cmd/watch-project.html

type WatchResponse

type WatchResponse struct {
	Version string `json:"version" mapstructure:"version"`
}

WatchResponse https://facebook.github.io/watchman/docs/cmd/watch.html Deprecated: starting in version 3.1. We recommend that clients adopt the watch-project command. https://facebook.github.io/watchman/docs/cmd/watch-project.html

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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