syncproject

package
v0.42.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package syncproject describes sync projects: one or more sync jobs, each keeping a local directory and a bucket folder in step, run together.

A project comes from a TOML file (knot file sync-project) or from the sync block of a template's volumes, which the server hands the space's agent when it registers.

Index

Constants

View Source
const (
	ModeTwoWay   = "two-way"  // changes either side are made on the other
	ModeDownload = "download" // the bucket folder to the directory
	ModeUpload   = "upload"   // the directory to the bucket folder
)

Modes a job syncs in.

View Source
const TemplateProject = "template"

TemplateProject is the name of the project a template's sync block makes.

Variables

This section is empty.

Functions

func GitignorePatterns

func GitignorePatterns(data []byte) (patterns, skipped []string)

GitignorePatterns turns the lines of a .gitignore-style file into exclude patterns. What exclude patterns cannot say is left out and reported: negations (!), which would sync less than the file asks. Anchored patterns (/build) match at any depth, which may leave out more.

func NameFromPath

func NameFromPath(path string) string

NameFromPath is the project name a file gives when it names none: its name without the extension.

Types

type Job

type Job struct {
	// Name names the job within its project; it defaults to the local
	// directory's name.
	Name string `toml:"name" yaml:"name" json:"name,omitempty" msgpack:"name,omitempty"`
	// Local is the directory; ~ is the home directory of whoever runs it.
	Local string `toml:"local" yaml:"local" json:"local" msgpack:"local"`
	// Remote is the bucket folder, bucket:folder.
	Remote string `toml:"remote" yaml:"remote" json:"remote" msgpack:"remote"`
	// Snapshot, bucket:folder, is snapshotted to Remote when Remote does not
	// exist yet: a new folder starts as a copy of it.
	Snapshot string `toml:"snapshot" yaml:"snapshot" json:"snapshot,omitempty" msgpack:"snapshot,omitempty"`
	// Mode is two-way (the default), download or upload.
	Mode string `toml:"mode" yaml:"mode" json:"mode,omitempty" msgpack:"mode,omitempty"`
	// Watch keeps the job running, syncing changes as they are made; on
	// unless set false.
	Watch *bool `toml:"watch" yaml:"watch" json:"watch,omitempty" msgpack:"watch,omitempty"`
	// Delete passes deletions on; on unless set false.
	Delete *bool `toml:"delete" yaml:"delete" json:"delete,omitempty" msgpack:"delete,omitempty"`
	// Exclude leaves paths out, as knot file sync --exclude.
	Exclude []string `toml:"exclude" yaml:"exclude" json:"exclude,omitempty" msgpack:"exclude,omitempty"`
	// ExcludeFrom names a file of patterns, such as .gitignore, relative
	// to Local, read when the job starts.
	ExcludeFrom string `toml:"exclude_from" yaml:"exclude_from" json:"exclude_from,omitempty" msgpack:"exclude_from,omitempty"`
	// NoDefaultExcludes syncs version control folders (.git) and editor
	// scratch files too.
	NoDefaultExcludes bool `` /* 130-byte string literal not displayed */
	// AllowMassDelete lets a pass delete most of a side's files.
	AllowMassDelete bool `toml:"allow_mass_delete" yaml:"allow_mass_delete" json:"allow_mass_delete,omitempty" msgpack:"allow_mass_delete,omitempty"`
}

Job keeps one local directory and one bucket folder in step.

func (Job) Deleting

func (j Job) Deleting() bool

Deleting reports whether the job passes deletions on.

func (Job) SyncMode

func (j Job) SyncMode() string

SyncMode is the job's mode, two-way when unset.

func (Job) Watching

func (j Job) Watching() bool

Watching reports whether the job keeps running.

type JobStatus

type JobStatus struct {
	Name   string `json:"name" msgpack:"name"`
	Local  string `json:"local" msgpack:"local"`
	Remote string `json:"remote" msgpack:"remote"`
	Mode   string `json:"mode" msgpack:"mode"`
	// State is starting, snapshotting, syncing, watching, done, failed or
	// stopped.
	State      string `json:"state" msgpack:"state"`
	Passes     int    `json:"passes" msgpack:"passes"`
	LastPass   string `json:"last_pass,omitempty" msgpack:"last_pass,omitempty"` // RFC 3339
	Error      string `json:"error,omitempty" msgpack:"error,omitempty"`
	Uploaded   int    `json:"uploaded" msgpack:"uploaded"`
	Downloaded int    `json:"downloaded" msgpack:"downloaded"`
	Deleted    int    `json:"deleted" msgpack:"deleted"`
	Conflicts  int    `json:"conflicts" msgpack:"conflicts"`
}

JobStatus is how a running job is doing.

type Project

type Project struct {
	// Name names the project; a file's defaults to the file's name.
	Name string `toml:"name" json:"name" msgpack:"name"`
	// Exclude is left out of every job, as well as each job's own.
	Exclude []string `toml:"exclude" json:"exclude,omitempty" msgpack:"exclude,omitempty"`
	// NoDefaultExcludes has every job sync version control folders (.git)
	// and editor scratch files too, leaving out only what Exclude and the
	// jobs' own patterns say.
	NoDefaultExcludes bool  `toml:"no_default_excludes" json:"no_default_excludes,omitempty" msgpack:"no_default_excludes,omitempty"`
	Sync              []Job `toml:"sync" json:"sync" msgpack:"sync"`
}

Project is a set of sync jobs run together.

func FromVolumes

func FromVolumes(volumes string) (*Project, error)

FromVolumes reads the sync block of a template's volumes, its variables already resolved: nil when there is none.

func Parse

func Parse(data []byte, name string) (*Project, error)

Parse reads a project from TOML. name is the project's name when the file gives none, such as the file's own name.

func (*Project) Encode

func (p *Project) Encode() ([]byte, error)

Encode writes a project as TOML.

func (*Project) Validate

func (p *Project) Validate() error

Validate checks a project, and names its unnamed jobs.

type ProjectStatus

type ProjectStatus struct {
	Name string `json:"name" msgpack:"name"`
	// Template says the project is the template's, which the space keeps
	// running.
	Template bool        `json:"template,omitempty" msgpack:"template,omitempty"`
	Jobs     []JobStatus `json:"jobs" msgpack:"jobs"`
}

ProjectStatus is how a running project is doing.

func (ProjectStatus) Settled

func (p ProjectStatus) Settled() (settled, failed bool)

Settled reports whether every job has made its first pass or finished, so the folders are in step, and whether any job failed.

Jump to

Keyboard shortcuts

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