A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/orgrim/pg_back/commit/921c5e4a4ecc7694843d56c9d4b76ff24cea0c5e below:

add fixes and unit tests for relative paths in windows · orgrim/pg_back@921c5e4 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+34

-2

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+34

-2

lines changed Original file line number Diff line number Diff line change

@@ -678,8 +678,9 @@ func relPath(basedir, path string) string {

678 678

target = path

679 679

}

680 680 681 -

for strings.HasPrefix(target, "../") {

682 -

target = strings.TrimPrefix(target, "../")

681 +

prefix := fmt.Sprintf("..%c", os.PathSeparator)

682 +

for strings.HasPrefix(target, prefix) {

683 +

target = strings.TrimPrefix(target, prefix)

683 684

}

684 685 685 686

return target

Original file line number Diff line number Diff line change

@@ -51,3 +51,34 @@ func TestExpandHomeDir(t *testing.T) {

51 51

})

52 52

}

53 53

}

54 + 55 +

func TestRelPath(t *testing.T) {

56 +

var tests = []struct {

57 +

basedir string

58 +

path string

59 +

want string

60 +

}{

61 +

{"/var/truc/dir", "/var/truc/dir/dump.d/file", "dump.d/file"},

62 +

{"/var/{dbname}/dir", "/var/b1/dir/b1.dump", "b1/dir/b1.dump"},

63 +

}

64 + 65 +

if runtime.GOOS == "windows" {

66 +

tests = []struct {

67 +

basedir string

68 +

path string

69 +

want string

70 +

}{

71 +

{"C:\\var\\truc\\dir", "C:\\var\\truc\\dir\\dump.d\\file", "dump.d\\file"},

72 +

{"C:\\var\\{dbname}\\dir", "C:\\var\\b1\\dir\\b1.dump", "b1\\dir\\b1.dump"},

73 +

}

74 +

}

75 + 76 +

for i, st := range tests {

77 +

t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {

78 +

got := relPath(st.basedir, st.path)

79 +

if got != st.want {

80 +

t.Errorf("got: %v, want %v", got, st.want)

81 +

}

82 +

})

83 +

}

84 +

}

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4