truncateData truncates data to maxBytes while respecting line boundaries. For origin "start", keeps the beginning and truncates at last newline before maxBytes. For origin "end", keeps the end and truncates from beginning at first newline after removing excess.
(data string, origin string, maxBytes int)
| 83 | // For origin "start", keeps the beginning and truncates at last newline before maxBytes. |
| 84 | // For origin "end", keeps the end and truncates from beginning at first newline after removing excess. |
| 85 | func truncateData(data string, origin string, maxBytes int) string { |
| 86 | if len(data) <= maxBytes { |
| 87 | return data |
| 88 | } |
| 89 | |
| 90 | if origin == "end" { |
| 91 | excessBytes := len(data) - maxBytes |
| 92 | truncateIdx := strings.Index(data[excessBytes:], "\n") |
| 93 | if truncateIdx == -1 { |
| 94 | return data[excessBytes:] |
| 95 | } |
| 96 | return data[excessBytes+truncateIdx+1:] |
| 97 | } |
| 98 | |
| 99 | truncateIdx := strings.LastIndex(data[:maxBytes], "\n") |
| 100 | if truncateIdx == -1 { |
| 101 | return data[:maxBytes] |
| 102 | } |
| 103 | return data[:truncateIdx+1] |
| 104 | } |
| 105 | |
| 106 | func isBlockedFile(expandedPath string) (bool, string) { |
| 107 | homeDir := os.Getenv("HOME") |
no outgoing calls
no test coverage detected