wisski-cloud-distillery/pkg/fsx/type.go
Tom Wiesing a4f91ae7cf
{backup,snapshort}: Improve behaviour
This commit improves the behaviour of 'backup' and 'snapshot' by
treating symbolic links properly, as well as writes proper reports.
2022-09-13 11:44:32 +02:00

30 lines
764 B
Go

// Package fsx provides convenient abstractions to work with the filesystem.
package fsx
import (
"os"
)
// Exists checks if the given path exists
func Exists(path string) bool {
_, err := os.Lstat(path)
return err == nil
}
// IsDirectory checks if the provided path exists and is a directory
func IsDirectory(path string) bool {
info, err := os.Stat(path)
return err == nil && info.Mode().IsDir()
}
// IsFile checks if the provided path exists and is a regular file
func IsFile(path string) bool {
info, err := os.Stat(path)
return err == nil && info.Mode().IsRegular()
}
// IsLink checks if the provided path exists and is a symlink
func IsLink(path string) bool {
info, err := os.Lstat(path)
return err == nil && info.Mode()&os.ModeSymlink != 0
}