Skip to content

Commit

Permalink
Fix path for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jan 23, 2024
1 parent 535ddd2 commit 45e3a86
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions central/central.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
"text/template"
"time"

"github.com/k1LoW/octocov/badge"
"github.com/k1LoW/octocov/datastore"
"github.com/k1LoW/octocov/datastore/local"
"github.com/k1LoW/octocov/gh"
"github.com/k1LoW/octocov/internal"
"github.com/k1LoW/octocov/badge"
"github.com/k1LoW/octocov/report"
)

Expand Down Expand Up @@ -266,8 +266,8 @@ func (c *Central) renderIndex(wr io.Writer) error {
d := map[string]any{
"Host": host,
"Reports": c.reports,
"BadgesLinkRel": badgesLinkRel,
"BadgesURLRel": badgesURLRel,
"BadgesLinkRel": filepath.ToSlash(badgesLinkRel),
"BadgesURLRel": filepath.ToSlash(badgesURLRel),
"RootURL": rootURL,
"IsPrivate": isPrivate,
"Query": query,
Expand Down
3 changes: 1 addition & 2 deletions config/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/k1LoW/octocov/internal"
)
Expand Down Expand Up @@ -45,7 +44,7 @@ func (c *Config) Build() {
if c.Central.Root == "" {
c.Central.Root = "."
}
if !strings.HasPrefix(c.Central.Root, "/") {
if !filepath.IsAbs(c.Central.Root) {
c.Central.Root = filepath.Clean(filepath.Join(c.Root(), c.Central.Root))
}
if len(c.Central.Reports.Datastores) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (c *Config) Load(path string) error {
if path == "" {
return nil
}
if strings.HasPrefix(path, "/") {
if filepath.IsAbs(path) {
c.path = path
} else {
c.path = filepath.Join(c.wd, path)
Expand Down
6 changes: 3 additions & 3 deletions coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (fc FileCoverages) FuzzyFindByFile(file string) (*FileCoverage, error) { //
continue
}
// When coverages are recorded in the package path. ( ex. org/repo/package/path/to/Target.kt
if !strings.HasPrefix(c.File, "/") && strings.HasSuffix(file, c.File) {
if !filepath.IsAbs(c.File) && strings.HasSuffix(file, c.File) {
if match == nil || len(match.File) > len(c.File) {
match = c
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func (fc FileCoverages) PathPrefix() (string, error) { //nostyle:recvtype
p = p[:i]
}
s := strings.Join(p, "/")
if s == "" && strings.HasPrefix(fc[0].File, "/") {
if s == "" && filepath.IsAbs(fc[0].File) {
s = "/"
}
if s == "." {
Expand Down Expand Up @@ -174,7 +174,7 @@ func (dc DiffFileCoverages) FuzzyFindByFile(file string) (*DiffFileCoverage, err
continue
}
// When coverages are recorded in the package path. ( ex. org/repo/package/path/to/Target.kt
if !strings.HasPrefix(c.File, "/") && strings.HasSuffix(file, c.File) {
if !filepath.IsAbs(c.File) && strings.HasSuffix(file, c.File) {
if match == nil || len(match.File) > len(c.File) {
match = c
}
Expand Down
2 changes: 1 addition & 1 deletion datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func parse(u, root string) (Type, []string, error) {
return Mackerel, []string{service}, nil
default:
p := strings.TrimSuffix(strings.TrimPrefix(strings.TrimPrefix(u, "file://"), "local://"), "/")
if strings.HasPrefix(p, "/") {
if filepath.IsAbs(p) {
root = p
} else {
root = filepath.Join(root, p)
Expand Down

0 comments on commit 45e3a86

Please sign in to comment.