Documentation
¶
Index ¶
- func CalculateDirSize(dirPath string) (int64, error)
- func CopyDir(src, dst string) error
- func CopyFile(src, dst string) error
- func CreateZipArchive(paths []string, basePath string, destPath string, compress bool) (int, error)
- func CreateZipToWriter(paths []string, basePath string, w io.Writer, compress bool) (int, error)
- func ExtractArchive(ctx context.Context, archivePath string, destPath string, ...) (int, error)
- func FindWorldDir(dataDir string) (string, error)
- func FindWorldDirs(dataDir string) ([]string, error)
- func GetDiskSpace(path string) (int64, error)
- func IsTextFile(path string) bool
- func SHA256File(path string) (string, error)
- func SanitizePathName(name string) string
- func VerifyZipArchive(path string) error
- func Within(root, target string) bool
- func WithinReal(root, target string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateDirSize ¶
calculateDirSize calculates the total size of a directory in bytes, including all nested files.
func CreateZipArchive ¶
CreateZipArchive creates a zip archive file on disk from the given paths.
func CreateZipToWriter ¶
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 FindWorldDirs ¶
Returns the server's world directory along with any sibling world dirs
func GetDiskSpace ¶
GetDiskSpace returns the total disk space available in bytes for the given path
func IsTextFile ¶
func SHA256File ¶
SHA256File calculates and returns the hex-encoded SHA256 hash of a file on disk.
func SanitizePathName ¶
func VerifyZipArchive ¶
VerifyZipArchive opens the zip archive and reads every entry so that stored file CRCs are verified.
func Within ¶
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 ¶
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.