-
Notifications
You must be signed in to change notification settings - Fork 0
/
id.go
54 lines (41 loc) · 1.08 KB
/
id.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package id
import (
"os"
"path"
"path/filepath"
"strings"
"github.com/friedenberg/zit/src/alfa/errors"
"github.com/friedenberg/zit/src/alfa/schnittstellen"
)
type TypedId interface {
schnittstellen.GattungLike
schnittstellen.Setter
}
// func Path(i IdMitKorper, pc ...string) string {
// pc = append(pc, i.Kopf(), i.Schwanz())
// return path.Join(pc...)
// }
func Path(i schnittstellen.Korper, pc ...string) string {
pc = append(pc, i.Kopf(), i.Schwanz())
return path.Join(pc...)
}
func MakeDirIfNecessary(i schnittstellen.Korper, pc ...string) (p string, err error) {
p = Path(i, pc...)
dir := path.Dir(p)
if err = os.MkdirAll(dir, os.ModeDir|0o755); err != nil {
err = errors.Wrap(err)
return
}
return
}
// TODO-P2 determine if this is used
func HeadTailFromFileName(fileName string) (head string, tail string) {
head, tail = filepath.Split(fileName)
tail = tail[0 : len(tail)-len(path.Ext(tail))]
head = strings.TrimSuffix(head, string(filepath.Separator))
idx := strings.LastIndex(head, string(filepath.Separator))
if idx != -1 {
head = head[idx+1:]
}
return
}