files

package
v1.0.38 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDirSize

func CalculateDirSize(dirPath string) (int64, error)

calculateDirSize calculates the total size of a directory in bytes, including all nested files.

func CopyDir

func CopyDir(src, dst string) error

CopyDir recursively copies a directory tree from src to dst.

func CopyFile

func CopyFile(src, dst string) error

func CreateZipArchive

func CreateZipArchive(paths []string, basePath string, destPath string, compress bool) (int, error)

CreateZipArchive creates a zip archive file on disk from the given paths.

func CreateZipToWriter

func CreateZipToWriter(paths []string, basePath string, w io.Writer, compress bool) (int, error)

CreateZipToWriter writes a zip archive of the given paths to the writer. basePath is the root directory used to calculate relative paths in the archive. When compress is false all entries are stored uncompressed. Returns the number of files archived.

func ExtractArchive

func ExtractArchive(ctx context.Context, archivePath string, destPath string, counter *atomic.Int32) (int, error)

Extract archive to destPath

func FindWorldDir

func FindWorldDir(dataDir string) (string, error)

func FindWorldDirs

func FindWorldDirs(dataDir string) ([]string, error)

Returns the server's world directory along with any sibling world dirs

func GetDiskSpace

func GetDiskSpace(path string) (int64, error)

GetDiskSpace returns the total disk space available in bytes for the given path

func IsTextFile

func IsTextFile(path string) bool

func SHA256File

func SHA256File(path string) (string, error)

SHA256File calculates and returns the hex-encoded SHA256 hash of a file on disk.

func SanitizePathName

func SanitizePathName(name string) string

func VerifyZipArchive

func VerifyZipArchive(path string) error

VerifyZipArchive opens the zip archive and reads every entry so that stored file CRCs are verified.

func Within

func Within(root, target string) bool

Within reports whether target resolves to root itself or a path inside root.

It is a boundary check, not a string prefix check: a sibling directory whose name merely shares root's prefix (root=/data/srv, target=/data/srv-evil/x) is NOT within root. Absolute targets outside root and targets that escape via ".." are rejected.

func WithinReal

func WithinReal(root, target string) bool

WithinReal reports whether target (when existing, or its closest existing ancestor if target does not yet exist) resolves strictly to root itself or within root after evaluating all symbolic links.

It first performs a lexical boundary check via Within. Then it canonicalizes root and target (or target's closest existing parent) via filepath.EvalSymlinks to ensure no symlink points outside root.

Types

This section is empty.

Jump to

Keyboard shortcuts

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