You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package staros
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var ERR_ALREADY_LOCKED = errors.New("ALREADY LOCKED")
|
|
|
|
var ERR_TIMEOUT = errors.New("TIME OUT")
|
|
|
|
|
|
|
|
func NewFileLock(filepath string) FileLock {
|
|
|
|
return FileLock{
|
|
|
|
filepath: filepath,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 检测文件/文件夹是否存在
|
|
|
|
func Exists(path string) bool {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
if err != nil && os.IsNotExist(err) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsFile 返回给定文件地址是否是一个文件,
|
|
|
|
//True为是一个文件,False为不是文件或路径无效
|
|
|
|
func IsFile(fpath string) bool {
|
|
|
|
s, err := os.Stat(fpath)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return !s.IsDir()
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsFolder 返回给定文件地址是否是一个文件夹,
|
|
|
|
//True为是一个文件夹,False为不是文件夹或路径无效
|
|
|
|
func IsFolder(fpath string) bool {
|
|
|
|
s, err := os.Stat(fpath)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return s.IsDir()
|
|
|
|
}
|