fix filechecker in health with precondition check
Signed-off-by: andy xie <andy.xning@gmail.com>
This commit is contained in:
parent
7694c31658
commit
658cda621f
2 changed files with 19 additions and 3 deletions
|
@ -2,9 +2,11 @@ package checks
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -15,10 +17,19 @@ import (
|
|||
// if the file exists.
|
||||
func FileChecker(f string) health.Checker {
|
||||
return health.CheckFunc(func() error {
|
||||
if _, err := os.Stat(f); err == nil {
|
||||
return errors.New("file exists")
|
||||
absoluteFilePath, err := filepath.Abs(f)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get absolute path for %q: %v", f, err)
|
||||
}
|
||||
return nil
|
||||
|
||||
_, err = os.Stat(absoluteFilePath)
|
||||
if err == nil {
|
||||
return errors.New("file exists")
|
||||
} else if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue