MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / gatherOutput

Function gatherOutput

cmd/exec.go:332–358  ·  view source on GitHub ↗
(tempFile *os.File, truncateForPingOutput bool)

Source from the content-addressed store, hash-verified

330}
331
332func gatherOutput(tempFile *os.File, truncateForPingOutput bool) []byte {
333 var outputBytes []byte
334 const outputForPingMaxLen int64 = 1000
335 const outputForLogUploadMaxLen int64 = 100000000
336 if noStdoutPassthru || tempFile == nil {
337 outputBytes = []byte{}
338 } else {
339
340 if size, err := getFileSize(tempFile); err == nil {
341 // In all cases, if we have to truncate, we want to read the END
342 // of the log file, because it is more informative.
343 if truncateForPingOutput && size > outputForPingMaxLen {
344 outputBytes = make([]byte, outputForPingMaxLen)
345 tempFile.Seek(outputForPingMaxLen*-1, 2)
346 } else if !truncateForPingOutput && size > outputForLogUploadMaxLen {
347 outputBytes = make([]byte, outputForLogUploadMaxLen)
348 tempFile.Seek(outputForLogUploadMaxLen*-1, 2)
349 } else {
350 outputBytes = make([]byte, size)
351 tempFile.Seek(0, 0)
352 }
353 tempFile.Read(outputBytes)
354 }
355 }
356
357 return outputBytes
358}
359
360func isStaleFile(file os.FileInfo) bool {
361 var timeLimit = 3 * 24 * time.Hour

Callers 2

RunCommandFunction · 0.85
shipLogDataFunction · 0.85

Calls 1

getFileSizeFunction · 0.85

Tested by

no test coverage detected