main 6af0a61

file_repository.go RawHistoryFolder

1package persistence
2
3import (
4	"context"
5	"fmt"
6	"os"
7	"path/filepath"
8)
9
10// FileRepository implements the InstallationRepository port using filesystem storage
11type FileRepository struct {
12	basePath string
13}
14
15// NewFileRepository creates a new file-based repository
16// basePath is the directory where installation state files will be stored
17func NewFileRepository(basePath string) (*FileRepository, error) {
18	// Ensure base path exists
19	if err := os.MkdirAll(basePath, 0755); err != nil {
20		return nil, fmt.Errorf("failed to create repository base path: %w", err)
21	}
22
23	return &FileRepository{
24		basePath: basePath,
25	}, nil
26}
27
28// Save persists the installation state to a file
29func (fr *FileRepository) Save(ctx context.Context, installationID string, state string) error {
30	select {
31	case <-ctx.Done():
32		return ctx.Err()
33	default:
34	}
35
36	filePath := filepath.Join(fr.basePath, installationID+".state")
37
38	// Write state to file
39	if err := os.WriteFile(filePath, []byte(state), 0644); err != nil {
40		return fmt.Errorf("failed to save installation state: %w", err)
41	}
42
43	return nil
44}
45
46// Load retrieves the installation state from a file
47func (fr *FileRepository) Load(ctx context.Context, installationID string) (string, error) {
48	select {
49	case <-ctx.Done():
50		return "", ctx.Err()
51	default:
52	}
53
54	filePath := filepath.Join(fr.basePath, installationID+".state")
55
56	data, err := os.ReadFile(filePath)
57	if err != nil {
58		if os.IsNotExist(err) {
59			return "", fmt.Errorf("installation state not found: %w", err)
60		}
61		return "", fmt.Errorf("failed to load installation state: %w", err)
62	}
63
64	return string(data), nil
65}
66
67// Exists checks if an installation state exists
68func (fr *FileRepository) Exists(ctx context.Context, installationID string) (bool, error) {
69	select {
70	case <-ctx.Done():
71		return false, ctx.Err()
72	default:
73	}
74
75	filePath := filepath.Join(fr.basePath, installationID+".state")
76
77	_, err := os.Stat(filePath)
78	if err == nil {
79		return true, nil
80	}
81	if os.IsNotExist(err) {
82		return false, nil
83	}
84	return false, fmt.Errorf("failed to check installation existence: %w", err)
85}

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 1

Tags 0

    ↑↓ moveenter openesc close