FileExists check if a file exists

This commit is contained in:
Iakov Davydov 2017-11-13 14:46:31 +01:00 committed by Nick Craig-Wood
parent 31d2fb4e11
commit 7ae7080824

View File

@ -733,3 +733,16 @@ func CheckClose(c io.Closer, err *error) {
*err = cerr
}
}
// FileExists returns true if a file remote exists.
// If remote is a directory, FileExists returns false.
func FileExists(fs Fs, remote string) (bool, error) {
_, err := fs.NewObject(remote)
if err != nil {
if err == ErrorObjectNotFound || err == ErrorNotAFile {
return false, nil
}
return false, err
}
return true, nil
}