rpaste/modules/utility/file.go

39 lines
681 B
Go
Raw Normal View History

2021-12-21 01:06:08 +00:00
// file utility area
//
// This part of the utility package is primarily for file or path checking.
package utility
import (
2021-12-24 09:01:22 +00:00
_ "errors"
"os"
_ "path"
_ "path/filepath"
_ "strings"
2021-12-21 01:06:08 +00:00
)
// Check if this is a file
func IsFile(filePath string) (bool, error) {
2021-12-24 09:01:22 +00:00
f, err := os.Stat(filePath)
if err == nil {
return !f.IsDir(), nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
2021-12-21 01:06:08 +00:00
}
// Check if this even exists
func IsExist(path string) (bool, error) {
2021-12-24 09:01:22 +00:00
_, err := os.Stat(path)
if err == nil || os.IsExist(err) {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
2021-12-21 01:06:08 +00:00
}
// todo: add string checking, we can't paste binary