latest cdbcd03

storeimages.go RawHistoryFolder

1package store
2
3import (
4	"fmt"
5	"io"
6	"os"
7	"path/filepath"
8
9	"github.com/bnema/gordon/internal/common"
10	"github.com/docker/docker/api/types"
11)
12
13type StorageConfig struct {
14	StorageDir string
15	ImageID    string
16	Images     []types.ImageSummary
17}
18
19func NewStorageConfig(config *common.Config) *StorageConfig {
20	return &StorageConfig{
21		StorageDir: config.General.StorageDir,
22	}
23}
24
25func SaveImageToStorage(config *common.Config, filename string, buf io.Reader) (string, error) {
26	// Check if the folder exist if not create it
27	if _, err := os.Stat(config.General.StorageDir); os.IsNotExist(err) {
28		err := os.MkdirAll(config.General.StorageDir, 0755)
29		if err != nil {
30			return "", fmt.Errorf("failed to create storage directory: %v", err)
31		}
32	}
33
34	// Define the path where the image will be saved
35	saveInPath := filepath.Join(config.General.StorageDir, filename)
36
37	// Create or open a file for appending.
38	outFile, err := os.Create(saveInPath)
39	if err != nil {
40		return "", fmt.Errorf("failed to open file: %v", err)
41	}
42
43	// Write the uploaded file's content to the outFile
44	_, err = io.Copy(outFile, buf)
45	if err != nil {
46		return "", fmt.Errorf("failed to write file: %v", err)
47	}
48
49	// Check if file exists
50	if _, err := os.Stat(saveInPath); os.IsNotExist(err) {
51		return "", fmt.Errorf("file does not exist: %v", err)
52	}
53
54	return saveInPath, nil
55}
56
57func (sc *StorageConfig) DeleteImageFromStorage(imageId string) error {
58	// Delete the image from the storage directory
59	imagePath := filepath.Join(sc.StorageDir, imageId+".tar")
60	err := os.Remove(imagePath)
61	if err != nil {
62		return fmt.Errorf("failed to delete image from storage directory: %v", err)
63	}
64
65	return nil
66}

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 7

Tags 106

↑↓ moveenter openesc close