aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/git-lfs-authenticate
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/git-lfs-authenticate')
-rw-r--r--cmd/git-lfs-authenticate/main.go30
1 files changed, 9 insertions, 21 deletions
diff --git a/cmd/git-lfs-authenticate/main.go b/cmd/git-lfs-authenticate/main.go
index d2dee21..dd39606 100644
--- a/cmd/git-lfs-authenticate/main.go
+++ b/cmd/git-lfs-authenticate/main.go
@@ -13,8 +13,6 @@ import (
13 "os/exec" 13 "os/exec"
14 "path" 14 "path"
15 "strings" 15 "strings"
16 "sync"
17 "sync/atomic"
18 "time" 16 "time"
19 17
20 "github.com/golang-jwt/jwt/v5" 18 "github.com/golang-jwt/jwt/v5"
@@ -24,9 +22,7 @@ import (
24type logger struct { 22type logger struct {
25 reqID string 23 reqID string
26 time time.Time 24 time time.Time
27 m sync.Mutex 25 wc io.WriteCloser
28 // Contained value must implement io.WriteCloser
29 wc atomic.Value
30} 26}
31 27
32func newLogger(reqID string) *logger { 28func newLogger(reqID string) *logger {
@@ -34,21 +30,13 @@ func newLogger(reqID string) *logger {
34} 30}
35 31
36func (l *logger) writer() io.WriteCloser { 32func (l *logger) writer() io.WriteCloser {
37 w := l.wc.Load() 33 if l.wc == nil {
38 if w == nil { 34 os.MkdirAll(".gitolfs3/logs/", 0o700) // Mode: drwx------
39 l.m.Lock() 35 ts := l.time.Format("2006-01-02")
40 if l.wc.Load() == nil { 36 path := fmt.Sprintf(".gitolfs3/logs/gitolfs3-%s-%s.log", ts, l.reqID)
41 os.MkdirAll(".gitolfs3/logs/", 0o700) // Mode: drwx------ 37 l.wc, _ = os.Create(path)
42 ts := l.time.Format("2006-01-02")
43 path := fmt.Sprintf(".gitolfs3/logs/gitolfs3-%s-%s.log", ts, l.reqID)
44 var err error
45 if w, err = os.Create(path); err == nil {
46 l.wc.Store(w)
47 }
48 }
49 l.m.Unlock()
50 } 38 }
51 return w.(io.WriteCloser) 39 return l.wc
52} 40}
53 41
54func (l *logger) logf(msg string, args ...any) { 42func (l *logger) logf(msg string, args ...any) {
@@ -56,8 +44,8 @@ func (l *logger) logf(msg string, args ...any) {
56} 44}
57 45
58func (l *logger) close() { 46func (l *logger) close() {
59 if wc := l.wc.Load(); wc != nil { 47 if l.wc != nil {
60 wc.(io.Closer).Close() 48 l.wc.Close()
61 } 49 }
62} 50}
63 51