• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13440912774

20 Feb 2025 05:14PM UTC coverage: 57.697% (-1.1%) from 58.802%
13440912774

Pull #9535

github

guggero
GitHub: remove duplicate caching

Turns out that actions/setup-go starting with @v4 also adds caching.
With that, our cache size on disk has almost doubled, leading to the
GitHub runner running out of space in certain situation.
We fix that by disabling the automated caching since we already have our
own, custom-tailored version.
Pull Request #9535: GitHub: remove duplicate caching

103519 of 179417 relevant lines covered (57.7%)

24825.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.45
/build/logrotator.go
1
package build
2

3
import (
4
        "compress/gzip"
5
        "fmt"
6
        "io"
7
        "os"
8
        "path/filepath"
9

10
        "github.com/jrick/logrotate/rotator"
11
        "github.com/klauspost/compress/zstd"
12
)
13

14
// RotatingLogWriter is a wrapper around the LogWriter that supports log file
15
// rotation.
16
type RotatingLogWriter struct {
17
        // pipe is the write-end pipe for writing to the log rotator.
18
        pipe *io.PipeWriter
19

20
        rotator *rotator.Rotator
21
}
22

23
// NewRotatingLogWriter creates a new file rotating log writer.
24
//
25
// NOTE: `InitLogRotator` must be called to set up log rotation after creating
26
// the writer.
27
func NewRotatingLogWriter() *RotatingLogWriter {
1✔
28
        return &RotatingLogWriter{}
1✔
29
}
1✔
30

31
// InitLogRotator initializes the log file rotator to write logs to logFile and
32
// create roll files in the same directory. It should be called as early on
33
// startup and possible and must be closed on shutdown by calling `Close`.
34
func (r *RotatingLogWriter) InitLogRotator(cfg *FileLoggerConfig,
35
        logFile string) error {
×
36

×
37
        logDir, _ := filepath.Split(logFile)
×
38
        err := os.MkdirAll(logDir, 0700)
×
39
        if err != nil {
×
40
                return fmt.Errorf("failed to create log directory: %w", err)
×
41
        }
×
42

43
        r.rotator, err = rotator.New(
×
44
                logFile, int64(cfg.MaxLogFileSize*1024), false, cfg.MaxLogFiles,
×
45
        )
×
46
        if err != nil {
×
47
                return fmt.Errorf("failed to create file rotator: %w", err)
×
48
        }
×
49

50
        // Reject unknown compressors.
51
        if !SupportedLogCompressor(cfg.Compressor) {
×
52
                return fmt.Errorf("unknown log compressor: %v", cfg.Compressor)
×
53
        }
×
54

55
        var c rotator.Compressor
×
56
        switch cfg.Compressor {
×
57
        case Gzip:
×
58
                c = gzip.NewWriter(nil)
×
59

60
        case Zstd:
×
61
                c, err = zstd.NewWriter(nil)
×
62
                if err != nil {
×
63
                        return fmt.Errorf("failed to create zstd compressor: "+
×
64
                                "%w", err)
×
65
                }
×
66
        }
67

68
        // Apply the compressor and its file suffix to the log rotator.
69
        r.rotator.SetCompressor(c, logCompressors[cfg.Compressor])
×
70

×
71
        // Run rotator as a goroutine now but make sure we catch any errors
×
72
        // that happen in case something with the rotation goes wrong during
×
73
        // runtime (like running out of disk space or not being allowed to
×
74
        // create a new logfile for whatever reason).
×
75
        pr, pw := io.Pipe()
×
76
        go func() {
×
77
                err := r.rotator.Run(pr)
×
78
                if err != nil {
×
79
                        _, _ = fmt.Fprintf(os.Stderr,
×
80
                                "failed to run file rotator: %v\n", err)
×
81
                }
×
82
        }()
83

84
        r.pipe = pw
×
85

×
86
        return nil
×
87
}
88

89
// Write writes the byte slice to the log rotator, if present.
90
func (r *RotatingLogWriter) Write(b []byte) (int, error) {
×
91
        if r.rotator != nil {
×
92
                return r.rotator.Write(b)
×
93
        }
×
94

95
        return len(b), nil
×
96
}
97

98
// Close closes the underlying log rotator if it has already been created.
99
func (r *RotatingLogWriter) Close() error {
×
100
        if r.rotator != nil {
×
101
                return r.rotator.Close()
×
102
        }
×
103

104
        return nil
×
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc