fscopy

package
v0.0.0-...-94cc341 Latest Latest
Warning

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

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

README

File System Copy (fscopy)

The fscopy package provides robust file system operations for the syncfiles tool, focusing on file selection, copying, and symbolic linking with support for gitignore-style filtering.

Overview

This package implements the core functionality for the syncfiles tool, enabling efficient file synchronization across directories with advanced filtering capabilities. It handles three main operations:

graph LR
    A[selectFiles] -->|list of files| B[copyFiles]
    B -->|link targets| C[linkFiles]

Components

File Selection

The file selection system uses a flexible filtering mechanism that supports:

  • Directory traversal using filepath.WalkDir
  • Gitignore-style pattern matching
  • Symlink detection and handling
  • Custom file filtering based on path patterns
File Copying

The copying system:

  • Preserves file permissions and attributes
  • Maintains directory structure
  • Handles relative path transformations
  • Efficiently copies file contents
Symbolic Linking

The linking system:

  • Creates symbolic links between directories
  • Supports templated link paths with placeholders
  • Calculates relative paths automatically
  • Handles existing links gracefully

Interfaces

The package defines several key interfaces:

  • FileSelector: For selecting files based on filters
  • FileCopier: For copying files between directories
  • FileFilter: For filtering files based on custom criteria
  • FileTreeOperator: For performing operations during directory traversal

Usage Examples

Selecting Files
selector := &FileSystemSelector{}
files, err := selector.ListFiles(ctx, "/path/to/source")
Copying Files
copier := &FileSystemCopier{}
err := copier.Copy(ctx, "/path/to/source", "/path/to/destination", files...)
copier := &FileSystemCopier{}
err := copier.Link(ctx, "/path/to/source", "/path/to/destination", linkRequests...)

Advanced Features

  • Gitignore Support: Files can be filtered using .syncignore files with gitignore syntax
  • Symlink Detection: Properly handles symbolic links during traversal
  • Templated Paths: Supports path templates with placeholders like <n> for dynamic path generation

Documentation

Overview

Copyright 2025 AlaudaDevops authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package fscopy provides file manipulation utilities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileCopier

type FileCopier interface {
	Copy(ctx context.Context, base, dst string, files ...ifs.FileInfo) error
	Link(ctx context.Context, base, dst string, links ...ifs.LinkRequest) error
}

FileCopier copies files from a given path to a destination base is the original base path dst is the destination path files is the list of files to copy

type FileFilter

type FileFilter interface {
	IsFileAllowed(ctx context.Context, info ifs.FileInfo) (bool, error)
}

FileFilter checks if a files is allowed to be copied

type FileSelector

type FileSelector interface {
	ListFiles(ctx context.Context, path string, filters ...FileFilter) ([]ifs.FileInfo, error)
}

FileSelector selects files from a given path respecting .syncignore files rules in the given path or in its subfolders returning a list of allowed files

type FileSystemCopier

type FileSystemCopier struct {
}

func (*FileSystemCopier) Copy

func (s *FileSystemCopier) Copy(ctx context.Context, base, destination string, files ...ifs.FileInfo) error

Copy copies a list of files using a base and destination folders implements the FileCopier interface

func (*FileSystemCopier) CopyFile

func (s *FileSystemCopier) CopyFile(ctx context.Context, base, destination string, file ifs.FileInfo) error

CopyFile copies one file from base to destination

func (s *FileSystemCopier) Link(ctx context.Context, base, destination string, links ...ifs.LinkRequest) error

Link will create symlinks based on the base and destination folders given the list links it will ignore if the destination folder was already created and the link already exists

type FileSystemSelector

type FileSystemSelector struct {
}

FileSystemSelector implements a file selector using the local file system

func (*FileSystemSelector) ListFiles

func (s *FileSystemSelector) ListFiles(ctx context.Context, path string, filters ...FileFilter) ([]ifs.FileInfo, error)

ListFiles implements the FileSelector interface

type FileTreeOperator

type FileTreeOperator interface {
	WalkDirFunc(ctx context.Context, path string, d fs.DirEntry, err error) error
}

FileTreeOperator operator to walk a file tree and do its own processing

type IgnoreNode

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

IgnoreNode represents a node in a ignore file filter, and can be used directly to check if a given path is ignored

func (*IgnoreNode) AddChild

func (n *IgnoreNode) AddChild(path string, matcher goignore.IgnoreMatcher) bool

AddChild tries to add the child to an existing child verifying if it should be added down the tree otherwise will add to its own children

func (*IgnoreNode) IsFileAllowed

func (n *IgnoreNode) IsFileAllowed(ctx context.Context, file ifs.FileInfo) (bool, error)

IsFileAllowed implements the FileFilter interface returning true if the file is allowed and false if it should be ignored

func (*IgnoreNode) ListMatchers

func (n *IgnoreNode) ListMatchers(path string) (result map[string]goignore.IgnoreMatcher)

ListMatchers returns a map of matchers for the given path matching the path and all its ancestors

func (*IgnoreNode) WalkDirFunc

func (n *IgnoreNode) WalkDirFunc(ctx context.Context, path string, d fs.DirEntry, err error) error

WalkDirFunc implements the FileTreeOperator interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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