Skip to content

Commit d4374c0

Browse files
committed
feat: include relative path in tarball
1 parent 4fcf927 commit d4374c0

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pkg/data_collector/data_collector.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ func NewDataCollector(namespaces ...string) (*DataCollector, error) {
6565

6666
func (c *DataCollector) WrapUp() error {
6767

68-
// Create the tarball file
69-
//wd, _ := os.Getwd()
7068
unixTime := time.Now().Unix()
7169
unixTimeString := strconv.FormatInt(unixTime, 10)
7270
tarballName := fmt.Sprintf("kic-supportpkg-%s.tar.gz", unixTimeString)
@@ -92,18 +90,22 @@ func (c *DataCollector) WrapUp() error {
9290
if err != nil {
9391
return err
9492
}
95-
header.Name = path
96-
//TODO: correct this to relative path
9793

98-
if err := tw.WriteHeader(header); err != nil {
94+
relativePath, err := filepath.Rel(c.BaseDir, path)
95+
if err != nil {
96+
return err
97+
}
98+
header.Name = relativePath
99+
100+
if err = tw.WriteHeader(header); err != nil {
99101
return err
100102
}
101103

102104
if !info.Mode().IsRegular() {
103105
return nil
104106
}
105107

106-
file, err := os.Open(path)
108+
file, err = os.Open(path)
107109
if err != nil {
108110
return err
109111
}
@@ -116,8 +118,6 @@ func (c *DataCollector) WrapUp() error {
116118

117119
return nil
118120
})
119-
120-
fmt.Println("Tarball created successfully:", tarballName)
121-
os.RemoveAll(c.BaseDir)
121+
_ = os.RemoveAll(c.BaseDir)
122122
return nil
123123
}

0 commit comments

Comments
 (0)