Skip to content

Commit

Permalink
Fix os separator paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kipz committed Dec 19, 2023
1 parent f3d6510 commit 4907216
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/cli/tuf-client/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func verifyEnv() (*localConfig, error) {
return nil, fmt.Errorf("no local download folder: %w", err)
}
// verify there's a local root.json available for bootstrapping trust
_, err = os.Stat(fmt.Sprintf("%s/%s.json", env.MetadataDir, metadata.ROOT))
_, err = os.Stat(filepath.Join(env.MetadataDir, fmt.Sprintf("%s.json", metadata.ROOT)))
if err != nil {
return nil, fmt.Errorf("no local download folder: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/cli/tuf-client/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func InitializeCmd() error {
if err != nil {
return err
}
rootPath = fmt.Sprintf("%s/%s.json", rootPath, metadata.ROOT)
rootPath = filepath.Join(rootPath, fmt.Sprintf("%s.json", metadata.ROOT))
// no need to copy root.json to the metadata folder as we already download it in the expected location
copyTrusted = false
}
Expand Down
2 changes: 1 addition & 1 deletion metadata/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (update *Updater) DownloadTarget(targetFile *metadata.TargetFiles, filePath
targetFilePath = fmt.Sprintf("%s.%s", hashes, dirName)
} else {
// <dir-prefix>/<hash>.<target-name>
targetFilePath = fmt.Sprintf("%s/%s.%s", dirName, hashes, baseName)
targetFilePath = filepath.Join(dirName, hashes, fmt.Sprintf(".%s", baseName))
}
}
fullURL := fmt.Sprintf("%s%s", targetBaseURL, targetFilePath)
Expand Down
11 changes: 6 additions & 5 deletions metadata/updater/updater_top_level_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package updater
import (
"fmt"
"os"
"path/filepath"
"testing"
"time"

Expand Down Expand Up @@ -83,7 +84,7 @@ func runRefresh(updaterConfig *config.UpdaterConfig, moveInTime time.Time) (Upda

updater, err := New(updaterConfig)
if err != nil {
log.Errorf("failed to create new updater config: %v", err)
log.Debugf("failed to create new updater config: %v", err)
return Updater{}, err
}
if moveInTime != time.Now() {
Expand Down Expand Up @@ -147,13 +148,13 @@ func assertContentEquals(t *testing.T, role string, version *int) {
expectedContent, err := simulator.Sim.FetchMetadata(role, version)
assert.NoError(t, err)

content, err := os.ReadFile(fmt.Sprintf("%s/%s.json", simulator.MetadataDir, role))
content, err := os.ReadFile(filepath.Join(simulator.MetadataDir, fmt.Sprintf("%s.json", role)))
assert.NoError(t, err)
assert.Equal(t, string(expectedContent), string(content))
}

func assertVersionEquals(t *testing.T, role string, expectedVersion int64) {
path := fmt.Sprintf("%s/%s.json", simulator.MetadataDir, role)
path := filepath.Join(simulator.MetadataDir, fmt.Sprintf("%s.json", role))
switch role {
case metadata.ROOT:
md, err := simulator.Sim.MDRoot.FromFile(path)
Expand Down Expand Up @@ -347,7 +348,7 @@ func TestTrustedRootUnsigned(t *testing.T) {
err := loadOrResetTrustedRootMetadata()
assert.NoError(t, err)

rootPath := fmt.Sprintf("%s/%s.json", simulator.MetadataDir, metadata.ROOT)
rootPath := filepath.Join(simulator.MetadataDir, fmt.Sprintf("%s.json", metadata.ROOT))
mdRoot, err := simulator.Sim.MDRoot.FromFile(rootPath)
assert.NoError(t, err)

Expand Down Expand Up @@ -388,7 +389,7 @@ func TestMaxRootRotations(t *testing.T) {
simulator.Sim.PublishRoot()
}

rootPath := fmt.Sprintf("%s/%s.json", simulator.MetadataDir, metadata.ROOT)
rootPath := filepath.Join(simulator.MetadataDir, fmt.Sprintf("%s.json", metadata.ROOT))
mdRoot, err := simulator.Sim.MDRoot.FromFile(rootPath)
assert.NoError(t, err)
initialRootVersion := mdRoot.Signed.Version
Expand Down
4 changes: 2 additions & 2 deletions testutils/testutils/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func Copy(fromPath string, toPath string) error {
return fmt.Errorf("failed to read path %s: %w", fromPath, err)
}
for _, file := range files {
data, err := os.ReadFile(fmt.Sprintf("%s/%s", fromPath, file.Name()))
data, err := os.ReadFile(filepath.Join(fromPath, file.Name()))
if err != nil {
return fmt.Errorf("failed to read file %s: %w", file.Name(), err)
}
filePath := fmt.Sprintf("%s/%s", toPath, file.Name())
filePath := filepath.Join(toPath, file.Name())
err = os.WriteFile(filePath, data, 0750)
if err != nil {
return fmt.Errorf("failed to write file %s: %w", filePath, err)
Expand Down

0 comments on commit 4907216

Please sign in to comment.