Skip to content

Commit

Permalink
Fixes patch for WINDOWS OS
Browse files Browse the repository at this point in the history
Signed-off-by: Catalin Stratu <catalinstratu45@gmail.com>
  • Loading branch information
CatalinStratu committed Mar 15, 2022
1 parent bc89f8d commit f7ea935
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
18 changes: 14 additions & 4 deletions builder/builder2v1/build_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spdx/tools-golang/utils"
"path/filepath"
"regexp"
"runtime"
)

// BuildPackageSection2_1 creates an SPDX Package (version 2.1), returning
Expand All @@ -22,18 +23,27 @@ func BuildPackageSection2_1(packageName string, dirRoot string, pathsIgnore []st
if err != nil {
return nil, err
}
osType := runtime.GOOS

re, ok := regexp.Compile("/+")
if ok != nil {
return nil, err
}

dirRootLen := 0
if osType == "windows" {
dirRootLen = len(dirRoot)
}

files := map[spdx.ElementID]*spdx.File2_1{}
fileNumber := 0
//dirRootLen := len(dirRoot)
for _, fp := range filepaths {
newFileName := fp
newFilePatch := filepath.FromSlash("." + newFileName)
fmt.Println(newFilePatch)
newFilePatch := ""
if osType == "windows" {
newFilePatch = filepath.FromSlash("." + fp[dirRootLen:])
} else {
newFilePatch = filepath.FromSlash("./" + fp)
}
newFile, err := BuildFileSection2_1(re.ReplaceAllLiteralString(newFilePatch, string(filepath.Separator)), dirRoot, fileNumber)
if err != nil {
return nil, err
Expand Down
13 changes: 12 additions & 1 deletion builder/builder2v2/build_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spdx/tools-golang/utils"
"path/filepath"
"regexp"
"runtime"
)

// BuildPackageSection2_2 creates an SPDX Package (version 2.2), returning
Expand All @@ -19,6 +20,7 @@ func BuildPackageSection2_2(packageName string, dirRoot string, pathsIgnore []st
// build the file section first, so we'll have it available
// for calculating the package verification code
filepaths, err := utils.GetAllFilePaths(dirRoot, pathsIgnore)
osType := runtime.GOOS

if err != nil {
return nil, err
Expand All @@ -28,11 +30,20 @@ func BuildPackageSection2_2(packageName string, dirRoot string, pathsIgnore []st
if ok != nil {
return nil, err
}
dirRootLen := 0
if osType == "windows" {
dirRootLen = len(dirRoot)
}

files := map[spdx.ElementID]*spdx.File2_2{}
fileNumber := 0
for _, fp := range filepaths {
newFilePatch := filepath.FromSlash("." + fp)
newFilePatch := ""
if osType == "windows" {
newFilePatch = filepath.FromSlash("." + fp[dirRootLen:])
} else {
newFilePatch = filepath.FromSlash("./" + fp)
}
newFile, err := BuildFileSection2_2(re.ReplaceAllLiteralString(newFilePatch, string(filepath.Separator)), dirRoot, fileNumber)
if err != nil {
return nil, err
Expand Down

0 comments on commit f7ea935

Please sign in to comment.