Skip to content

Commit

Permalink
refactor(CSI-224): path not recognized as weka mount
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyberezansky committed Jul 28, 2024
1 parent 4b1448f commit cf1f6f6
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/wekafs/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"google.golang.org/grpc/status"
timestamp "google.golang.org/protobuf/types/known/timestamppb"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -272,10 +271,21 @@ func PathExists(p string) bool {
}

func PathIsWekaMount(ctx context.Context, path string) bool {
log.Ctx(ctx).Trace().Str("full_path", path).Msg("Checking if path is wekafs mount")
mountcmd := "mount -t wekafs | grep -w" + path
res, _ := exec.Command("sh", "-c", mountcmd).Output()
return strings.Contains(string(res), path)
file, err := os.Open("/proc/mounts")
if err != nil {
return false
}
defer func() { _ = file.Close() }()

scanner := bufio.NewScanner(file)
for scanner.Scan() {
fields := strings.Fields(scanner.Text())
if len(fields) >= 3 && fields[2] == "wekafs" && fields[1] == path {
return true
}
}

return false
}

func validateVolumeId(volumeId string) error {
Expand Down

0 comments on commit cf1f6f6

Please sign in to comment.