-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinstall_unix.go
36 lines (29 loc) · 943 Bytes
/
install_unix.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
//go:build linux || solaris || openbsd || freebsd
// +build linux solaris openbsd freebsd
package main
import (
"fmt"
"os"
"path"
"strings"
log "github.com/Crosse/gosimplelogger"
)
func platformDependentInstall(fontData *FontData) error {
// On Linux, fontconfig can understand subdirectories. So, to keep the
// font directory clean, install all font files for a particular font
// family into a subdirectory named after the family (with hyphens instead
// of spaces).
fullPath := path.Join(FontsDir,
strings.ToLower(strings.ReplaceAll(fontData.Family, " ", "-")),
path.Base(fontData.FileName))
log.Debugf("Installing \"%v\" to %v", fontData.Name, fullPath)
err := os.MkdirAll(path.Dir(fullPath), 0o700)
if err != nil {
return fmt.Errorf("failed to create directory: %w", err)
}
err = os.WriteFile(fullPath, fontData.Data, 0o644)
if err != nil {
return fmt.Errorf("cannot write file: %w", err)
}
return nil
}