Skip to content

Commit f728474

Browse files
committed
fix compression filename
1 parent 974e06f commit f728474

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v20251113
1+
v20251113.3

cmd/lens/ping.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ func ICMPPing(target string, interval float64) {
8787
}
8888
}
8989

90-
if err := compress(path.Join(DataDir, today), filename); err != nil {
90+
fullFilename, err = compress(path.Join(DataDir, today), filename)
91+
if err != nil {
9192
log.Error().Err(err).Msg("Error compressing ping output file")
9293
return
9394
}
@@ -98,7 +99,7 @@ func ICMPPing(target string, interval float64) {
9899
log.Error().Err(err).Msg("Error creating Swift client")
99100
return
100101
}
101-
localFilename := fullFilename + ".tar.zst"
102+
localFilename := fullFilename
102103

103104
year := strconv.Itoa(time.Now().Year())
104105
month := fmt.Sprintf("%02d", time.Now().Month())

cmd/lens/util.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,32 @@ func validResult(directory, filename string) error {
106106
return fmt.Errorf("%s contains no valid ping results", fullPath)
107107
}
108108

109-
func compress(directory, filename string) error {
109+
func compress(directory, filename string) (string, error) {
110110
fullFilename := path.Join(directory, filename)
111111
fileInfo, err := os.Stat(fullFilename)
112112
if err != nil {
113-
return fmt.Errorf("error stating file %s: %w", fullFilename, err)
113+
return "", fmt.Errorf("error stating file %s: %w", fullFilename, err)
114114
}
115115
if fileInfo.Size() == 0 {
116-
return fmt.Errorf("%s is empty, skipping compression", fullFilename)
116+
return "", fmt.Errorf("%s is empty, skipping compression", fullFilename)
117117
}
118118
if err := validResult(directory, filename); err != nil {
119-
return fmt.Errorf("no valid results in %s, skipping compression", fullFilename)
119+
return "", fmt.Errorf("no valid results in %s, skipping compression", fullFilename)
120120
}
121121

122-
cmd := exec.Command("tar", "--zstd", "-C", directory, "-cf", path.Join(directory, fmt.Sprintf("%s.tar.zst", filename)), filename, "--remove-files")
122+
var cmd *exec.Cmd
123123
if err := checkZstd(); err != nil {
124124
cmd = exec.Command("tar", "-C", directory, "-cf", path.Join(directory, fmt.Sprintf("%s.tar.gz", filename)), filename, "--remove-files")
125+
fullFilename = fmt.Sprintf("%s.tar.gz", fullFilename)
126+
} else {
127+
cmd = exec.Command("tar", "--zstd", "-C", directory, "-cf", path.Join(directory, fmt.Sprintf("%s.tar.zst", filename)), filename, "--remove-files")
128+
fullFilename = fmt.Sprintf("%s.tar.zst", fullFilename)
125129
}
126130
log.Debug().Msgf("Compression command: %s", cmd.String())
127131
cmd.Stdout = os.Stdout
128132
cmd.Stderr = os.Stderr
129133

130-
return cmd.Run()
134+
return fullFilename, cmd.Run()
131135
}
132136

133137
func getExternalIP(version int) string {

0 commit comments

Comments
 (0)