pathutil

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 9 Imported by: 240

Documentation

Overview

Example
package main

import (
	"fmt"
	"strings"

	"github.com/bitrise-io/go-utils/pathutil"
)

func main() {
	pths, err := pathutil.FilterPaths(
		[]string{"/app2.apk", "/MyApp.ipa", "/app1.apk"},
		pathutil.ExtensionFilter(".apk", true),
	)
	if err != nil {
		panic(err)
	}

	pths, err = pathutil.SortPathsByComponents(pths)
	if err != nil {
		panic(err)
	}

	fmt.Println(strings.Join(pths, ", "))
}
Output:

/app1.apk, /app2.apk

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsPath

func AbsPath(pth string) (string, error)

AbsPath expands ENV vars and the ~ character

then call Go's Abs

func ChangeDirForFunction

func ChangeDirForFunction(dir string, fn func()) error

ChangeDirForFunction ...

func CurrentWorkingDirectoryAbsolutePath

func CurrentWorkingDirectoryAbsolutePath() (string, error)

CurrentWorkingDirectoryAbsolutePath ...

func EnsureDirExist

func EnsureDirExist(dir string) error

EnsureDirExist ...

func EscapeGlobPath

func EscapeGlobPath(path string) string

EscapeGlobPath escapes a partial path, determined at runtime, used as a parameter for filepath.Glob

func ExpandTilde

func ExpandTilde(pth string) (string, error)

ExpandTilde ...

func FileContainsFilter

func FileContainsFilter(pth, str string) (bool, error)

FileContainsFilter ...

func FilterPaths

func FilterPaths(fileList []string, filters ...FilterFunc) ([]string, error)

FilterPaths ...

func GetFileName

func GetFileName(path string) string

GetFileName returns the name of the file from a given path or the name of the directory if it is a directory

func IsDirExists

func IsDirExists(pth string) (bool, error)

IsDirExists ...

func IsPathExists

func IsPathExists(pth string) (bool, error)

IsPathExists ...

func IsRelativePath

func IsRelativePath(pth string) bool

IsRelativePath ...

func ListEntries

func ListEntries(dir string, filters ...FilterFunc) ([]string, error)

ListEntries filters contents of a directory using the provided filters

func ListPathInDirSortedByComponents

func ListPathInDirSortedByComponents(searchDir string, relPath bool) ([]string, error)

ListPathInDirSortedByComponents ...

func NormalizedOSTempDirPath

func NormalizedOSTempDirPath(tmpDirNamePrefix string) (retPth string, err error)

NormalizedOSTempDirPath ... Creates a temp dir, and returns its path. If tmpDirNamePrefix is provided it'll be used

as the tmp dir's name prefix.

Normalized: it's guaranteed that the path won't end with '/'.

func PathCheckAndInfos

func PathCheckAndInfos(pth string) (os.FileInfo, bool, error)

PathCheckAndInfos ... Returns: 1. file info or nil 2. bool, indicating whether the path exists 3. error, if any error happens during the check

func RevokableChangeDir

func RevokableChangeDir(dir string) (func() error, error)

RevokableChangeDir ...

func SortPathsByComponents

func SortPathsByComponents(paths []string) ([]string, error)

SortPathsByComponents ...

func UserHomeDir

func UserHomeDir() string

UserHomeDir ...

Types

type BySortablePathComponents

type BySortablePathComponents []SortablePath

BySortablePathComponents ..

func (BySortablePathComponents) Len

func (s BySortablePathComponents) Len() int

func (BySortablePathComponents) Less

func (s BySortablePathComponents) Less(i, j int) bool

func (BySortablePathComponents) Swap

func (s BySortablePathComponents) Swap(i, j int)

type FilterFunc

type FilterFunc func(string) (bool, error)

FilterFunc ...

func BaseFilter

func BaseFilter(base string, allowed bool) FilterFunc

BaseFilter ...

func ComponentFilter

func ComponentFilter(component string, allowed bool) FilterFunc

ComponentFilter ...

func ComponentWithExtensionFilter

func ComponentWithExtensionFilter(ext string, allowed bool) FilterFunc

ComponentWithExtensionFilter ...

func DirectoryContainsFileFilter

func DirectoryContainsFileFilter(fileName string) FilterFunc

DirectoryContainsFileFilter returns a FilterFunc that checks if a directory contains a file

func ExtensionFilter

func ExtensionFilter(ext string, allowed bool) FilterFunc

ExtensionFilter ...

func InDirectoryFilter

func InDirectoryFilter(dir string, allowed bool) FilterFunc

InDirectoryFilter ...

func IsDirectoryFilter

func IsDirectoryFilter(allowed bool) FilterFunc

IsDirectoryFilter ...

func RegexpFilter

func RegexpFilter(pattern string, allowed bool) FilterFunc

RegexpFilter ...

type PathModifier added in v1.0.1

type PathModifier interface {
	AbsPath(pth string) (string, error)
}

PathModifier ...

func NewPathModifier added in v1.0.1

func NewPathModifier() PathModifier

NewPathModifier ...

type SortablePath

type SortablePath struct {
	Pth        string
	AbsPth     string
	Components []string
}

SortablePath ...

func NewSortablePath

func NewSortablePath(pth string) (SortablePath, error)

NewSortablePath ...

Jump to

Keyboard shortcuts

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