Help us shape the future of Go! Take the 2026 Go Developer Survey

unixfs_sync

package
v0.57.21 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DeleteMode_name = map[int32]string{
		0: "DeleteMode_NONE",
		1: "DeleteMode_BEFORE",
		2: "DeleteMode_DURING",
		3: "DeleteMode_AFTER",
		4: "DeleteMode_ONLY",
	}
	DeleteMode_value = map[string]int32{
		"DeleteMode_NONE":   0,
		"DeleteMode_BEFORE": 1,
		"DeleteMode_DURING": 2,
		"DeleteMode_AFTER":  3,
		"DeleteMode_ONLY":   4,
	}
)

Enum value maps for DeleteMode.

Functions

func CleanPathListForFilter

func CleanPathListForFilter(pathList []string) []string

CleanPathListForFilter cleans the given list of paths for NewFilterFileList.

Sorts and cleans the paths. Strips any leading '/'.

func Sync

func Sync(
	ctx context.Context,
	outPath string,
	fsHandle *unixfs.FSHandle,
	deleteMode DeleteMode,
	filterCb FilterCb,
) error

Sync recursively synchronizes the contents of the UnixFS to disk.

Attempts to skip files by checking size and modification time. The output path does not have to be empty when starting. filterCb is optional and is called with each element in the fs tree. TODO: Does not (yet) support symlinks or other non-file and non-dir node types.

func SyncFromDisk

func SyncFromDisk(
	ctx context.Context,
	destHandle *unixfs.FSHandle,
	srcPath string,
	deleteMode DeleteMode,
	filterCb FilterCb,
) error

SyncFromDisk syncs from disk to the given UnixFS FSHandle.

func SyncFromFS

func SyncFromFS(
	ctx context.Context,
	destHandle *unixfs.FSHandle,
	srcFs fs.FS,
	deleteMode DeleteMode,
	filterCb FilterCb,
) error

SyncFromFS syncs from the given fs.FS to the UnixFS FSHandle.

func SyncToBilly

func SyncToBilly(
	ctx context.Context,
	bfs BillyFS,
	fsHandle *unixfs.FSHandle,
	deleteMode DeleteMode,
	filterCb FilterCb,
) error

SyncToBilly recursively synchronizes the contents of the UnixFS to a BillyFS.

Attempts to skip files by checking size and modification time. The output path does not have to be empty when starting. TODO: Node types other than directory, regular file, and symlink are not supported.

func SyncToBillyContents

func SyncToBillyContents(
	ctx context.Context,
	bfs BillyFS,
	fsHandle *unixfs.FSHandle,
	deleteMode DeleteMode,
	filterCb FilterCb,
	changeCb ChangeCb,
) error

SyncToBillyContents compares regular-file bytes even when size and mtime match. Unchanged files are left intact so source watchers only observe actual edits. changeCb, if set, observes each destination file the sync changes.

func SyncToUnixfs

func SyncToUnixfs(
	ctx context.Context,
	dest,
	src *unixfs.FSHandle,
	deleteMode DeleteMode,
	filterCb FilterCb,
) error

SyncToUnixfs recursively synchronizes the contents of the UnixFS to another UnixFS.

Attempts to skip files by checking size and modification time. The output path does not have to be empty when starting. Directories, regular files, and symlinks are supported; other node types (FIFO, device, socket, etc.) are still skipped.

func SyncToUnixfsBatch

func SyncToUnixfsBatch(
	ctx context.Context,
	b *unixfs_world.BatchFSWriter,
	src *unixfs.FSHandle,
	filterCb FilterCb,
) error

SyncToUnixfsBatch walks a source FSHandle and drives a BatchFSWriter, accumulating file content blobs eagerly and committing every directory merge in a single world-object transaction. Mirrors SyncToUnixfs in semantics but collapses the per-op 2N+1 btx.Write amplification to N+1.

The destination root directory must already exist in the batch writer's world object (e.g. via FsInit). On error, the batch writer is Released to drop accumulated state; on success, Commit is called exactly once.

The source handle must point at a directory; lone file or symlink sources are not supported.

func SyncXattrs

func SyncXattrs(
	ctx context.Context,
	outPath string,
	fsHandle *unixfs.FSHandle,
) error

SyncXattrs applies extended attributes from the source UnixFS tree to the files on disk at outPath. Call after Sync to preserve xattrs. This is a separate pass because billy.Filesystem does not support xattrs.

Types

type BillyFS

type BillyFS interface {
	billy.Basic
	billy.Dir
}

BillyFS has the needed billy filesystem interfaces.

type ChangeCb

type ChangeCb func(outPath string, kind ChangeKind)

ChangeCb observes a destination file after the sync changes it. Removing a directory reports each file it contained.

type ChangeKind

type ChangeKind int

ChangeKind classifies a destination file changed by a sync.

const (
	// ChangeWrite rewrote an existing file.
	ChangeWrite ChangeKind = iota
	// ChangeCreate created a file.
	ChangeCreate
	// ChangeRemove removed a file.
	ChangeRemove
)

type DeleteMode

type DeleteMode int32

DeleteMode is the set of available delete modes for Sync.

const (
	// DeleteMode_NONE does not delete files from the destination.
	DeleteMode_DeleteMode_NONE DeleteMode = 0
	// DeleteMode_BEFORE scans & deletes files from the destination before writing
	// any new files or directories to the destination.
	DeleteMode_DeleteMode_BEFORE DeleteMode = 1
	// DeleteMode_DURING scans & deletes files from the destination while writing.
	DeleteMode_DeleteMode_DURING DeleteMode = 2
	// DeleteMode_AFTER scans & deletes files from the destination after writing.
	DeleteMode_DeleteMode_AFTER DeleteMode = 3
	// DeleteMode_ONLY scans & deletes files and skips writing any new data.
	DeleteMode_DeleteMode_ONLY DeleteMode = 4
)

func (DeleteMode) Enum

func (x DeleteMode) Enum() *DeleteMode

func (DeleteMode) MarshalJSON

func (x DeleteMode) MarshalJSON() ([]byte, error)

MarshalJSON marshals the DeleteMode to JSON.

func (DeleteMode) MarshalProtoJSON

func (x DeleteMode) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the DeleteMode to JSON.

func (DeleteMode) MarshalProtoText

func (x DeleteMode) MarshalProtoText() string

func (DeleteMode) MarshalText

func (x DeleteMode) MarshalText() ([]byte, error)

MarshalText marshals the DeleteMode to text.

func (DeleteMode) String

func (x DeleteMode) String() string

func (*DeleteMode) UnmarshalJSON

func (x *DeleteMode) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the DeleteMode from JSON.

func (*DeleteMode) UnmarshalProtoJSON

func (x *DeleteMode) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the DeleteMode from JSON.

func (*DeleteMode) UnmarshalText

func (x *DeleteMode) UnmarshalText(b []byte) error

UnmarshalText unmarshals the DeleteMode from text.

type FilterCb

type FilterCb func(ctx context.Context, path string, nodeType unixfs.FSCursorNodeType) (cntu bool, err error)

FilterCb is a callback that can be passed to Sync. If it returns false for cntu, skips the node & children. If it returns an error, Sync is canceled and returns the error. The path will be formatted like "directory/file.txt"

func CombineFilterCbs

func CombineFilterCbs(cbs ...FilterCb) FilterCb

CombineFilterCbs combines multiple FilterCb into a single FilterCb.

func NewFilterFileList

func NewFilterFileList(pathList []string, isSorted bool) FilterCb

NewFilterFileList filters by checking if the path is in the list of paths. Performance is significantly better if pathList is sorted. Directories are never skipped.

NOTE: the path list MUST be sorted in ascending order if isSorted=true! NOTE: the path list MUST be formatted like "directory/file.txt" with no leading ./

func NewSkipPathPrefixes

func NewSkipPathPrefixes(skipPathPrefixes []string) FilterCb

NewSkipPathPrefixes creates a FilterCb which skips given path prefixes from a []string slice.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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