fileutil

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup

func Cleanup(path string)

Cleanup removes the specified file or directory and prints any errors to stderr. It's supposed to be used in defer statements to clean up temporary directories.

func Exists

func Exists(path string) (bool, error)

func ForceLongPathTempDir added in v0.11.1

func ForceLongPathTempDir()

ForceLongPathTempDir ensures that os.TempDir() creates temporary directories with long paths on Windows, resolving all "8.3" style short names. This is necessary because some external tools automatically resolve short paths to long paths, which can cause problems when trying to relativize paths.

We prevent this issue by forcing long paths in os.TempDir() rather than normalizing paths whenever we relativize them for the following reasons:

  • Go does not provide a function that normalizes paths without following symlinks, so we would have to implement it ourselves.
  • The temporary directories we create in cifuzz appear to be the only common source of 8.3 paths and users are very unlikely to launch cifuzz from an 8.3 path.
func ForceSymlink(oldname, newname string) error

ForceSymlink creates newname as a symbolic link to oldname. If newname already exists, it will be overwritten.

func IsBelow

func IsBelow(path string, root string) (bool, error)

IsBelow returns true if and only if path lies below or is the path root. path and root must be either both absolute or both relative.

func IsDir

func IsDir(path string) bool

IsDir returns whether this path is a directory. Tries to behave the same as Python's pathlib.Path.is_dir()

func IsSharedLibrary added in v0.20.0

func IsSharedLibrary(path string) bool
func IsSymlink(path string) bool

func IsSystemLibrary added in v0.20.0

func IsSystemLibrary(library string) bool

func PrettifyPath

func PrettifyPath(path string) string

PrettifyPath prints a possibly shortened path for display purposes. If path is located under the current working directory, the relative path to it is returned, otherwise or in case of an error the path is returned unchanged.

func SearchFileBackwards added in v0.20.0

func SearchFileBackwards(start, filename string) (string, error)

SearchFileBackwards searches for a file by going backwards/upwards from a given path if a path `/foo/bar` is given the order of search is

  1. /foo/bar
  2. /foo/
  3. /

func Touch

func Touch(path string) error

Touch creates a file at the given path

Types

This section is empty.

Jump to

Keyboard shortcuts

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