main ece7682

rotate.go RawHistoryFolder

1package logging
2
3import (
4	"os"
5	"sync"
6)
7
8type rotatingWriter struct {
9	mu      sync.Mutex
10	path    string
11	max     int64
12	runtime bool
13	file    *os.File
14	size    int64
15	closed  bool
16}
17
18func newRotatingWriter(path string, maxBytes int64, rotateAtRuntime bool) (*rotatingWriter, error) {
19	if maxBytes <= 0 {
20		maxBytes = DefaultMaxBytes
21	}
22	rw := &rotatingWriter{path: path, max: maxBytes, runtime: rotateAtRuntime}
23	if err := rw.open(); err != nil {
24		return nil, err
25	}
26	if !rotateAtRuntime && rw.size >= rw.max {
27		rw.rotateLocked()
28	}
29	return rw, nil
30}
31
32func (w *rotatingWriter) Write(p []byte) (int, error) {
33	w.mu.Lock()
34	defer w.mu.Unlock()
35
36	if w.closed {
37		return 0, os.ErrClosed
38	}
39	n, err := w.file.Write(p)
40	w.size += int64(n)
41	if err == nil && w.runtime && w.size >= w.max {
42		w.rotateLocked()
43	}
44	return n, err
45}
46
47func (w *rotatingWriter) Close() error {
48	w.mu.Lock()
49	defer w.mu.Unlock()
50
51	if w.closed {
52		return nil
53	}
54	w.closed = true
55	return w.file.Close()
56}
57
58func (w *rotatingWriter) open() error {
59	f, err := os.OpenFile(w.path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o600)
60	if err != nil {
61		return err
62	}
63	info, err := f.Stat()
64	if err != nil {
65		_ = f.Close()
66		return err
67	}
68	w.file = f
69	w.size = info.Size()
70	return nil
71}
72
73func (w *rotatingWriter) rotateLocked() {
74	old := w.file
75	_ = os.Rename(w.path, w.path+".old")
76	if err := w.open(); err != nil {
77		w.file = old
78		w.size = w.max
79		return
80	}
81	_ = old.Close()
82}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 12

Tags 11

↑↓ moveenter openesc close