Skip to content

Commit

Permalink
[FIX]修复路径分隔符在不同操作系统中的错误 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifuhao authored Sep 20, 2023
1 parent 80a4ef3 commit 8936a99
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (c *CyclicDetector) Parse() error {
}

c.AbsPath = abs
c.RootPath = abs[strings.LastIndex(abs, "/")+1:]
c.RootPath = abs[strings.LastIndex(abs, string(os.PathSeparator))+1:]
c.ModuleName = modFile.Module.Mod.Path

if err = c.ParseFilters(c.SourceFilter); err != nil {
Expand Down Expand Up @@ -196,7 +196,8 @@ func (c *CyclicDetector) ParseNodeResolver(path string) ([]*NodeResolver, error)
continue
}
for _, imp := range value.Imports {
importValues[key] = append(importValues[key], imp.Path.Value[1:len(imp.Path.Value)-1])
impPathValue := imp.Path.Value[1 : len(imp.Path.Value)-1]
importValues[key] = append(importValues[key], strings.ReplaceAll(impPathValue, "/", string(os.PathSeparator)))
}
relFilePath := strings.ReplaceAll(filePath, c.AbsPath, "")
nodeResolvers = append(nodeResolvers, &NodeResolver{
Expand Down Expand Up @@ -227,11 +228,11 @@ func (c *CyclicDetector) ParseNodeResolver(path string) ([]*NodeResolver, error)
}

func GetNodePathName(content string) (filePath, nodeName string) {
contains := strings.Contains(content, "/")
contains := strings.Contains(content, string(os.PathSeparator))
if !contains {
return content, content
}
index := strings.LastIndex(content, "/")
index := strings.LastIndex(content, string(os.PathSeparator))
return content[:index], content[index+1:]
}

Expand All @@ -250,7 +251,7 @@ func (c *CyclicDetector) buildNodeRelation() ([][]*NodeResolver, map[string]int)
for _, node := range c.NodeResolvers {
depends := make([][]*NodeResolver, 0)
for _, in := range node.ImportValues {
subPkg := in[strings.LastIndex(in, "/")+1:]
subPkg := in[strings.LastIndex(in, string(os.PathSeparator))+1:]
pkgs := c.NodePackageMap[in]
pkgMap := make(map[string]int, 0)
simple := true
Expand Down

0 comments on commit 8936a99

Please sign in to comment.