Files
aptly/utils/utils.go
André Roth f7057a9517 go1.24: fix lint, unit and system tests
- development env: base on debian trixie with go1.24
- lint: run with default config
- fix lint errors
- fix unit tests
- fix system test
2025-04-26 13:29:50 +02:00

35 lines
919 B
Go

// Package utils collects various services: simple operations, compression, etc.
package utils
import (
"fmt"
"os"
"strings"
"golang.org/x/sys/unix"
)
// DirIsAccessible verifies that directory exists and is accessible
func DirIsAccessible(filename string) error {
fileStat, err := os.Stat(filename)
if err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("error checking directory '%s': %s", filename, err)
}
} else {
if fileStat.Mode().Perm() == 0000 || unix.Access(filename, unix.W_OK) != nil {
return fmt.Errorf("'%s' is inaccessible, check access rights", filename)
}
}
return nil
}
// SanitizePath removes leading '/', remove '..', '$' and '`'
func SanitizePath(path string) (result string) {
result = strings.Replace(path, "..", "", -1)
result = strings.Replace(result, "$", "", -1)
result = strings.Replace(result, "`", "", -1)
result = strings.TrimLeft(result, "/")
return
}