target

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LimitErrorWriter added in v0.4.0

type LimitErrorWriter struct {
	W io.Writer // underlying reader
	L int64     // limit
	N int64     // number of bytes read
}

LimitErrorWriter is a wrapper around an io.Writer that returns io.ErrShortWrite when the limit is reached.

func NewLimitErrorWriter added in v0.4.0

func NewLimitErrorWriter(w io.Writer, l int64) *LimitErrorWriter

NewLimitErrorWriter returns a new LimitErrorWriter that wraps the given writer and limit.

func (*LimitErrorWriter) Write added in v0.4.0

func (l *LimitErrorWriter) Write(p []byte) (n int, err error)

Write writes up to len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. Write returns a non-nil error when n < len(p). Write does not modify the slice data, even temporarily. The limit is enforced by returning io.ErrShortWrite when the limit is reached.

type OS added in v0.3.0

type OS struct {
}

OS is the struct type that holds all information for interacting with the filesystem

func NewOS added in v0.3.0

func NewOS() *OS

NewOS creates a new Os and applies provided options from opts

func (*OS) CreateSafeDir added in v0.3.0

func (o *OS) CreateSafeDir(config *config.Config, dstBase string, newDir string, mode fs.FileMode) error

CreateSafeDir creates newDir in dstBase and checks for path traversal in directory name. If dstBase is empty, the directory will be created in the current working directory. If dstBase does not exist and config.CreateDestination() returns true, it will be created with the config.CustomCreateDirMode(). The mode parameter is the file mode that should be set on the directory. If the directory already exists, the mode will be set on the directory.

func (*OS) CreateSafeFile added in v0.3.0

func (o *OS) CreateSafeFile(cfg *config.Config, dstBase string, newFileName string, reader io.Reader, mode fs.FileMode) error

CreateSafeFile creates newFileName in dstBase with content from reader and file headers as provided in mode. If dstBase is empty, the file will be created in the current working directory. If dstBase does not exist and config.CreateDestination() returns true, it will be created with the config.CustomCreateDirMode(). The mode parameter is the file mode that is set on the file. If the path of the file contains path traversal, an error should be returned. If the path *to the file* (not dstBase) does not exist, the directories is created with the config.CustomCreateDirMode() by the implementation.

func (o *OS) CreateSafeSymlink(config *config.Config, dstBase string, newLinkName string, linkTarget string) error

CreateSymlink creates in dstBase a symlink newLinkName with destination linkTarget. If dstBase is empty, the symlink is created in the current working directory. If dstBase does not exist and config.CreateDestination() returns true, it will be created with the config.CustomCreateDirMode(). If the path of the symlink contains path traversal, an error is returned. If the path *to the symlink* (not dstBase) does not exist, the directories is created with the config.CustomCreateDirMode(). If the symlink already exists and config.Overwrite() returns false, an error is returned.

type Target

type Target interface {

	// CreateSafeFile creates a file with a specified name and content within a given directory.
	// The function takes a configuration object, a destination directory, a name for the file,
	// a reader for the file content, and a file mode.
	//
	// The dstDir parameter specifies the directory where the file should be created. If dstDir is empty,
	// the file is created in the current working directory. If dstDir does not exist and config.CreateDestination()
	// returns true, the function may create the directory with permissions specified by config.CustomCreateDirMode().
	//
	// The name parameter specifies the name of the file. If the name contains path traversal (e.g., "../"),
	// the function returns an error to prevent the creation of files outside of the intended directory.
	//
	// The reader parameter provides the content for the file.
	//
	// The mode parameter specifies the file mode that should be set on the file.
	//
	// If the path to the file (excluding dstDir) does not exist, the function may create the necessary directories
	// with permissions specified by config.CustomCreateDirMode().
	//
	// The function returns an error if there's a problem creating the file or the necessary directories.
	// If the function completes successfully, it returns nil.
	CreateSafeFile(config *config.Config, dstDir string, name string, reader io.Reader, mode fs.FileMode) error

	// CreateSafeDir creates a directory with a specified name within a given directory.
	// The function takes a configuration object, a destination directory, a name for the directory, and a file mode.
	//
	// The dstDir parameter specifies the directory where the new directory should be created. If dstDir is empty,
	// the directory is created in the current working directory. If dstDir does not exist and config.CreateDestination()
	// returns true, the function may create the directory with permissions specified by config.CustomCreateDirMode().
	//
	// The dirName parameter specifies the name of the new directory. If the dirName contains path traversal (e.g., "../"),
	// the function returns an error to prevent the creation of directories outside of the intended directory.
	//
	// The mode parameter specifies the file mode that should be set on the new directory.
	//
	// If the path to the new directory (excluding dstDir) does not exist, the function may create the necessary directories
	// with permissions specified by config.CustomCreateDirMode().
	//
	// The function returns an error if there's a problem creating the directory or the necessary directories.
	// If the function completes successfully, it returns nil.
	CreateSafeDir(config *config.Config, dstDir string, dirName string, mode fs.FileMode) error

	// CreateSafeSymlink creates a symbolic link with a specified name and target within a given directory.
	// The function takes a configuration object, a destination directory, a name for the symlink, and a target for the symlink.
	//
	// The dstDir parameter specifies the directory where the symlink should be created. If dstDir is empty,
	// the symlink is created in the current working directory. If dstDir does not exist and config.CreateDestination()
	// returns true, the function may create the directory with permissions specified by config.CustomCreateDirMode().
	//
	// The name parameter specifies the name of the symlink. If the name contains path traversal (e.g., "../"),
	// the function returns an error to prevent the creation of symlinks outside of the intended directory.
	//
	// The linkTarget parameter specifies the target of the symlink. This is the file or directory that the symlink will point to.
	//
	// If the path to the symlink (excluding dstDir) does not exist, the function may create the necessary directories
	// with permissions specified by config.CustomCreateDirMode().
	//
	// The function returns an error if there's a problem creating the symlink or the necessary directories.
	// If the function completes successfully, it returns nil.
	CreateSafeSymlink(config *config.Config, dstDir string, name string, linkTarget string) error
}

Target specifies all function that are needed to be implemented to extract contents from an archive

Jump to

Keyboard shortcuts

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