mirror of https://github.com/statping/statping
stale issue bot fix, test fix
parent
d7c54eb5e7
commit
eb634c472b
|
@ -8,6 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DirWritable(path string) (bool, error) {
|
func DirWritable(path string) (bool, error) {
|
||||||
|
@ -24,6 +25,14 @@ func DirWritable(path string) (bool, error) {
|
||||||
return false, errors.New("write permission bit is not set on this file for user")
|
return false, errors.New("write permission bit is not set on this file for user")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var stat syscall.Stat_t
|
||||||
|
if err = syscall.Stat(path, &stat); err != nil {
|
||||||
|
return false, errors.New("unable to get stat")
|
||||||
|
}
|
||||||
|
|
||||||
|
if uint32(os.Geteuid()) != stat.Uid {
|
||||||
|
return false, errors.New("user doesn't have permission to write to this directory")
|
||||||
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +45,10 @@ func Ping(address string, secondsTimeout int) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if strings.Contains(out, "Destination Host Unreachable") {
|
if strings.Contains(out, "Unknown host") {
|
||||||
|
return errors.New("unknown host")
|
||||||
|
}
|
||||||
|
if strings.Contains(out, "100.0% packet loss") {
|
||||||
return errors.New("destination host unreachable")
|
return errors.New("destination host unreachable")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -2,7 +2,10 @@ package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DirWritable(path string) (bool, error) {
|
func DirWritable(path string) (bool, error) {
|
||||||
|
@ -19,14 +22,6 @@ func DirWritable(path string) (bool, error) {
|
||||||
return false, errors.New("write permission bit is not set on this file for user")
|
return false, errors.New("write permission bit is not set on this file for user")
|
||||||
}
|
}
|
||||||
|
|
||||||
var stat syscall.Stat_t
|
|
||||||
if err = syscall.Stat(path, &stat); err != nil {
|
|
||||||
return false, errors.New("unable to get stat")
|
|
||||||
}
|
|
||||||
|
|
||||||
if uint32(os.Geteuid()) != stat.Uid {
|
|
||||||
return false, errors.New("user doesn't have permission to write to this directory")
|
|
||||||
}
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue