Skip to content

Commit

Permalink
fix windows line endings
Browse files Browse the repository at this point in the history
Signed-off-by: Asra Ali <asraa@google.com>
  • Loading branch information
asraa committed May 31, 2022
1 parent b8a5075 commit 410d6cf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/cosign/tuf/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -474,7 +475,15 @@ func maybeDownloadRemoteTarget(name string, meta data.TargetFileMeta, t *TUF) er
return errors.New("fs.ReadFileFS unimplemented for embedded repo")
}
b, err := rd.ReadFile(path.Join("repository", "targets", name))

if err == nil {
// Unfortunately go:embed appears to somehow replace our line endings on windows, we need to switch them back.
// It should theoretically be safe to do this everywhere - but the files only seem to get mutated on Windows so
// let's only change them back there.
if runtime.GOOS == "windows" {
b = bytes.ReplaceAll(b, []byte("\r\n"), []byte("\n"))
}

if isValidTarget(b, meta) {
if _, err := io.Copy(&w, bytes.NewReader(b)); err != nil {
return fmt.Errorf("using embedded target: %w", err)
Expand Down

0 comments on commit 410d6cf

Please sign in to comment.