Skip to content

Commit 8f1c8b5

Browse files
Merge pull request openshift#2024 from openshift-cherrypick-robot/cherry-pick-2022-to-release-4.19
[release-4.19] OCPBUGS-56511: Replace colon to hypen in the filename while extracting tar on Windows
2 parents c88fd60 + 3009b09 commit 8f1c8b5

File tree

1 file changed

+10
-1
lines changed
  • pkg/helpers/source-to-image/tar

1 file changed

+10
-1
lines changed

pkg/helpers/source-to-image/tar/tar.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path/filepath"
99
"regexp"
10+
"runtime"
1011
"strings"
1112
"time"
1213

@@ -456,7 +457,15 @@ func (t *stiTar) extractLink(dir string, header *tar.Header, tarReader io.Reader
456457
}
457458

458459
func (t *stiTar) extractFile(dir string, header *tar.Header, tarReader io.Reader) error {
459-
path := filepath.Join(dir, header.Name)
460+
fileName := header.Name
461+
if runtime.GOOS == "windows" {
462+
// ":" is special character on Windows. If file name contains ":",
463+
// extraction will fail. In order to overcome this problem, we are replacing ":"
464+
// to "-".
465+
fileName = strings.Replace(fileName, ":", "-", -1)
466+
}
467+
468+
path := filepath.Join(dir, fileName)
460469
if t.disallowOverwrite {
461470
if _, err := os.Stat(path); !os.IsNotExist(err) {
462471
log.Warningf("Refusing to overwrite existing file: %s", path)

0 commit comments

Comments
 (0)