-
Notifications
You must be signed in to change notification settings - Fork 5
/
trcshmemfs.go
40 lines (33 loc) · 1006 Bytes
/
trcshmemfs.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
package trcsh
import (
"errors"
"os"
"strings"
"sync"
eUtils "github.com/trimble-oss/tierceron/pkg/utils"
"github.com/go-git/go-billy/v5"
)
type TrcshMemFs struct {
BillyFs billy.Filesystem
}
func (t *TrcshMemFs)WriteToMemFile(driverConfig *eUtils.DriverConfig, memCacheLocal *sync.Mutex, byteData *[]byte, path string){
configMemFs := driverConfig.MemFs.(*TrcshMemFs)
memCacheLocal.Lock()
if _, err := configMemFs.BillyFs.Stat(path); errors.Is(err, os.ErrNotExist) {
if strings.HasPrefix(path, "./") {
path = strings.TrimLeft(path, "./")
}
memFile, err := configMemFs.BillyFs.Create(path)
if err != nil {
eUtils.CheckError(&driverConfig.CoreConfig, err, true)
}
memFile.Write(*byteData)
memFile.Close()
memCacheLocal.Unlock()
eUtils.LogInfo(&driverConfig.CoreConfig, "Wrote memfile:"+path)
} else {
memCacheLocal.Unlock()
eUtils.LogInfo(&driverConfig.CoreConfig, "Unexpected memfile exists:"+path)
eUtils.CheckError(&driverConfig.CoreConfig, err, true)
}
}