dir

package
v1.14.5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package dir handles the directories in use by the internal server. Such as the download, extra, and preview directories.

Index

Constants

View Source
const Pattern = "df2app"

Variables

View Source
var (
	ErrFile   = errors.New("dir: file error")
	ErrSave   = errors.New("dir: save error")
	ErrNoPath = errors.New("dir: directory path is not set")
	ErrNoDir  = errors.New("dir: directory path does not exist")
)

Functions

func CleanTemp added in v1.14.0

func CleanTemp(stale time.Duration) error

CleanTemp removes the temporary directories likely created using MkdirTemp, that are older than the stale time value. An error is returned if a directory cannot be removed.

func CreateTemp added in v1.14.0

func CreateTemp(pattern string) (*os.File, error)

CreateTemp creates a new temporary file using os.CreateTemp. However, no path is required and the new file will be located in a subdirectory created using MkdirTemp.

func IsTemp added in v1.14.0

func IsTemp(d os.DirEntry) bool

IsTemp returns true when the dir entry is likely a temporary directory or file created using MkdirTemp.

func MkdirStale added in v1.14.0

func MkdirStale(path string) (string, error)

MkdirStale creates a temporary subdirectory in os.TempDir using the provided path as the basis of the directory name. Unlike MkdirTemp, this func does not apply randomization to the directory name and the result will not always be unique. Allowing the directory to be used as a short-term file cache.

The returned string is the path to an existing or the newly created temporary directory.

func MkdirTemp added in v1.14.0

func MkdirTemp(pattern string) (string, error)

MkdirTemp creates a temporary directory at os.TempDir using the provided pattern. The optional pattern should not include a randomizer string "-*".

Example usage on Linux:

path, _ := MkdirTemp("abc")
fmt.Println(path)

Output:
/tmp/df2app-abc-d83gsddb34

func Paths

func Paths(d ...Directory) []string

Paths converts the slice of Directory types to a slice of strings representing the directory paths.

func RemoveAll added in v1.14.0

func RemoveAll(name string) error

RemoveAll removes the named directory. For safety, the directory removal is locked using os.OpenRoot to os.TempDir.

Types

type Directory

type Directory string

Directory is a string type that represents an internal server directory path.

func (Directory) Check

func (d Directory) Check(sl *slog.Logger) error

Check to confirm the directory is writable.

func (Directory) IsDir

func (d Directory) IsDir() error

IsDir returns an error if the path does not exists or is not a directory.

func (Directory) Join

func (d Directory) Join(name string) string

Join combines the directory path with the given file or directory name.

func (Directory) Path

func (d Directory) Path() string

Path returns the directory path as a string.

Jump to

Keyboard shortcuts

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