Debian Codegraph @

phaul/images.go

raw symbols SCIP
1 package phaul
2
3 import (
4 "fmt"
5 "os"
6 "path/filepath"
7 )
8
9 type image struct {
10 cursor int
11 dir string
12 }
13
14 //nolint:unparam // suppress "error is always nil" warning
15 func preparePhaulImages(wdir string) (*image, error) {
16 return &image{dir: wdir}, nil
17 }
18
19 func (i *image) getPath(idx int) string {
20 return fmt.Sprintf(i.dir+"/%d", idx)
21 }
22
23 func (i *image) openNextDir() (*os.File, error) {
24 ipath := i.getPath(i.cursor)
25 err := os.Mkdir(ipath, 0o700)
26 if err != nil {
27 return nil, err
28 }
29
30 i.cursor++
31 return os.Open(ipath)
32 }
33
34 func (i *image) lastImagesDir() string {
35 var ret string
36 if i.cursor == 0 {
37 ret = ""
38 } else {
39 ret, _ = filepath.Abs(i.getPath(i.cursor - 1))
40 }
41 return ret
42 }