Skip to content

Commit

Permalink
Don't invalidate cache if not root
Browse files Browse the repository at this point in the history
  • Loading branch information
valleedelisle committed May 14, 2024
1 parent a14672f commit bd79a60
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"
"os"
"os/exec"
"os/user"
"os/signal"
"regexp"
"strings"
Expand Down Expand Up @@ -84,6 +85,14 @@ func (c *CmdIO) Close() error {
return nil
}

func isRoot() bool {
currentUser, err := user.Current()
if err != nil {
log.Fatalf("[isRoot] Unable to get current user: %s", err)
}
return currentUser.Username == "root"
}

func main() {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
Expand Down Expand Up @@ -151,6 +160,10 @@ func main() {
} else if !strings.Contains(*fioFlags, "--directory") && !strings.Contains(*fioFlags, "--filename") {
fioArgs.WriteString(" --directory=/data")
}
if ! isRoot() {
log.Printf("Can't invalidate the cache because we're not root")
fioArgs.WriteString(" --invalidate=0")
}
cmd := fmt.Sprintf(
"%s --name=%s --runtime=%s --status-interval=%s %s %s",
*fioPath,
Expand Down

0 comments on commit bd79a60

Please sign in to comment.