Skip to content

Commit

Permalink
windows related fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Lewis Ojile <[email protected]>
  • Loading branch information
lewisojile committed Jun 11, 2021
1 parent f4254c4 commit bf61d9b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ build-mac: mod
.PHONY: build-win
build-win: mod
@echo "Building spdx-sbom-generator version:$(VERSION)"
@GO111MODULE=on GOFLAGS=-mod=vendor GOOS=win GOARCH=amd64 go build -o bin/spdx-sbom-generator.exe cmd/generator/generator.go
@GO111MODULE=on GOFLAGS=-mod=vendor GOOS=windows GOARCH=amd64 go build -o bin/spdx-sbom-generator.exe cmd/generator/generator.go
@chmod +x bin/spdx-sbom-generator.exe

.PHONY: lint
Expand Down
74 changes: 28 additions & 46 deletions internal/modules/gem/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"os"
"os/exec"
"path/filepath"
"reflect"
"runtime"
"spdx-sbom-generator/internal/helper"
"spdx-sbom-generator/internal/models"
Expand Down Expand Up @@ -337,18 +336,18 @@ func BuildSpecDependencies(path string, isFullPath bool, module *Spec) {
}

if !isFullPath {
for _, f := range files {
if f.IsDir() {
fullPath := filepath.Join(path, f.Name(), SPEC_DEFAULT_DIR)
for _, dir := range files {
if dir.IsDir() {
fullPath := filepath.Join(path, dir.Name(), SPEC_DEFAULT_DIR)
BuildSpecDependencies(fullPath, true, module)
break
return
}
}
}

cachePath := strings.Replace(path, SPEC_DEFAULT_DIR, CACHE_DEFAULT_DIR, 1)

name, version, err := rootGem(cachePath, cleanName(module.Name), true)
name, version, err := rootGem(cachePath, cleanName(module.Name))
versionedName := fmt.Sprintf("%s-%s", name, version)
if err == nil {
module.Name = versionedName
Expand Down Expand Up @@ -650,53 +649,36 @@ func checkSum(path string, filename string, isFullPath bool) (string, error) {
}

// Gets the root dependency name and version
func rootGem(path string, filename string, isFullPath bool) (string, string, error) {
func rootGem(path string, filename string) (string, string, error) {

var name *string
var version *string
if !isFullPath {
files, err := ioutil.ReadDir(path)
if err != nil {
return "", "", err
var name, version string
files, err := ioutil.ReadDir(path)
if err != nil {
log.Fatal(err)
}
for _, f := range files {

if strings.LastIndex(f.Name(), "-") == -1 {
continue
}
stp := strings.LastIndex(f.Name(), "-")
runes := []rune(f.Name())
n := string(runes[0:stp])

for _, f := range files {
v := strings.Replace(string(runes[stp+1:]), ".gem", "", 1)

if f.IsDir() {
fullPath := filepath.Join(path, f.Name(), CACHE_DEFAULT_DIR)
return rootGem(fullPath, cleanName(filename), true)
}
filename = strings.ReplaceAll(filename, `="`, "")
filename = strings.ReplaceAll(filename, `"`, "")

}
name = n

} else {
files, err := ioutil.ReadDir(path)
if err != nil {
return "", "", err
}
for _, f := range files {
if strings.LastIndex(f.Name(), "-") == -1 {
continue
}
stp := strings.LastIndex(f.Name(), "-")
runes := []rune(f.Name())
n := string(runes[0:stp])
v := strings.Replace(string(runes[stp+1:]), ".gem", "", 1)
filename = strings.ReplaceAll(filename, `="`, "")
filename = strings.ReplaceAll(filename, `"`, "")

name = &n
if *name == cleanName(filename) {
version = &v
break
}
if name == filename {
version = v
break
}
}

if reflect.ValueOf(name).IsNil() || reflect.ValueOf(version).IsNil() {
return filename, "", errors.New("unable to compute Checksum for " + filename)
}
return *name, *version, nil
return name, version, nil

}

Expand Down Expand Up @@ -1296,12 +1278,12 @@ func gemDir() string {
func getSHA(filename string) (string, error) {
f, err := os.Open(filename)
if err != nil {
log.Fatal(err)
return "",nil
}
defer f.Close()
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
return "",nil
}
return hex.EncodeToString(h.Sum(nil)), nil
}

0 comments on commit bf61d9b

Please sign in to comment.