Skip to content

Commit

Permalink
Running on Windows (#30)
Browse files Browse the repository at this point in the history
* forgot to use go's windows friendly path join

* move to cross platform compatible split

* useful to read the documentation first ^_^;;;;
  • Loading branch information
mbellotti committed Mar 25, 2023
1 parent 3ec9518 commit 2fca03b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
23 changes: 12 additions & 11 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fault/ast"
"fmt"
"os"
"path/filepath"
ospath "path/filepath"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -82,18 +82,19 @@ func Filepath(filepath string) string {
if path == "" {
filepath = right
} else {
filepath = fmt.Sprintf("%s/%s", path, right)
filepath = ospath.Join(path, right)
}

}

if len(filepath) < len(host) || host != filepath[0:len(host)] {
filepath = strings.Join([]string{host, filepath}, "/")
filepath = ospath.Join(host, filepath)
}

if strings.Contains(filepath, "//") {
path := strings.Split(filepath, "//")
filepath = strings.Join(path, "/")
dup := fmt.Sprintf("%s%s", string(ospath.Separator), string(ospath.Separator))
if strings.Contains(filepath, dup) {
path := strings.Split(filepath, dup)
filepath = ospath.Join(path...)
}

}
Expand All @@ -102,20 +103,20 @@ func Filepath(filepath string) string {

func home(host string, filepath string) string {
path := strings.Split(filepath, "~")
if string(path[1][0]) == "/" {
if string(path[1][0]) == string(ospath.Separator) {
filepath = path[1][1:]
} else {
filepath = path[1]
}
return strings.Join([]string{host, filepath}, "/")
return ospath.Join(host, filepath)
}

func uplevel(path string, host bool) string {
parts := strings.Split(path, "/")
parts := strings.Split(path, string(ospath.Separator))
parts = trimSlashes(parts, host)

if len(parts) > 0 {
return strings.Join(parts[0:len(parts)-1], "/")
return ospath.Join(parts[0 : len(parts)-1]...)
}
return ""
}
Expand Down Expand Up @@ -359,7 +360,7 @@ func IsCompare(op string) bool {
}

func DetectMode(filename string) string {
switch filepath.Ext(filename) {
switch ospath.Ext(filename) {
case ".fspec":
return "fspec"
case ".fsystem":
Expand Down
4 changes: 2 additions & 2 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func TestFilepath(t *testing.T) {

filepath7 := "/.."
filepath7a := Filepath(filepath7)
if filepath7a != "/host/" {
t.Fatalf("filepath not correct. want=/host/ got=%s", filepath7a)
if filepath7a != "/host" {
t.Fatalf("filepath not correct. want=/host got=%s", filepath7a)
}

filepath8 := "/host/test.spec"
Expand Down

0 comments on commit 2fca03b

Please sign in to comment.