detached 6af0a61

local.go RawHistoryFolder

1package filesystem
2
3import (
4	"fmt"
5	"os"
6
7	"github.com/bnema/archup/internal/domain/ports"
8)
9
10// LocalFileSystem implements the FileSystem port using the OS filesystem
11type LocalFileSystem struct{}
12
13// NewLocalFileSystem creates a new local filesystem adapter
14func NewLocalFileSystem() *LocalFileSystem {
15	return &LocalFileSystem{}
16}
17
18// Stat returns file info for the given path
19func (lfs *LocalFileSystem) Stat(name string) (os.FileInfo, error) {
20	return os.Stat(name)
21}
22
23// ReadFile reads entire file content
24func (lfs *LocalFileSystem) ReadFile(name string) ([]byte, error) {
25	return os.ReadFile(name)
26}
27
28// WriteFile writes data to a file with the given permissions
29func (lfs *LocalFileSystem) WriteFile(name string, data []byte, perm os.FileMode) error {
30	return os.WriteFile(name, data, perm)
31}
32
33// Create creates or truncates a file
34func (lfs *LocalFileSystem) Create(name string) (ports.File, error) {
35	file, err := os.Create(name)
36	if err != nil {
37		return nil, err
38	}
39	return &localFileHandle{file: file}, nil
40}
41
42// Chmod changes file permissions
43func (lfs *LocalFileSystem) Chmod(name string, perm os.FileMode) error {
44	return os.Chmod(name, perm)
45}
46
47// MkdirAll creates directory path with parents
48func (lfs *LocalFileSystem) MkdirAll(path string, perm os.FileMode) error {
49	return os.MkdirAll(path, perm)
50}
51
52// RemoveAll removes a file or directory recursively
53func (lfs *LocalFileSystem) RemoveAll(path string) error {
54	return os.RemoveAll(path)
55}
56
57// Exists checks if a file/directory exists
58func (lfs *LocalFileSystem) Exists(path string) (bool, error) {
59	_, err := os.Stat(path)
60	if err == nil {
61		return true, nil
62	}
63	if os.IsNotExist(err) {
64		return false, nil
65	}
66	return false, fmt.Errorf("failed to check file existence: %w", err)
67}
68
69// localFileHandle wraps os.File to implement the ports.File interface
70type localFileHandle struct {
71	file *os.File
72}
73
74// Read reads up to len(b) bytes from the file
75func (lfh *localFileHandle) Read(b []byte) (n int, err error) {
76	return lfh.file.Read(b)
77}
78
79// Write writes len(b) bytes to the file
80func (lfh *localFileHandle) Write(b []byte) (n int, err error) {
81	return lfh.file.Write(b)
82}
83
84// Close closes the file
85func (lfh *localFileHandle) Close() error {
86	return lfh.file.Close()
87}

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