-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile.go
70 lines (61 loc) · 1.64 KB
/
file.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package fsEngine
import (
"os"
"sync"
"time"
Header_ "github.com/fanap-infra/fsEngine/pkg/Header"
"github.com/fanap-infra/log"
lru "github.com/hashicorp/golang-lru"
)
// File
type FSEngine struct {
id uint32
file *os.File // file handle instance
header *Header_.HFileSystem
version uint32
size int64
CurrentFile string // name of the latest file to be created
LastFiletime time.Time // time where the first data of the file has been written
maxNumberOfBlocks uint32 // total number of blocks in Archiver
blockSize uint32 // in bytes, size of each block
blockSizeUsable uint32
openFiles map[uint32]*VFInfo
WMux sync.Mutex
RMux sync.Mutex
log *log.Logger
crudMutex sync.Mutex
Cache *lru.Cache
eventsHandler Events
cleaning uint32
Quit chan struct{}
}
// Close ...
func (fse *FSEngine) Close() error {
for _, vfInfo := range fse.openFiles {
for _, vf := range vfInfo.vfs {
err := vf.Close()
if err != nil {
fse.log.Warnv("Can not close virtual file", "err", err.Error())
return err
}
}
}
err := fse.header.UpdateFSHeader()
if err != nil {
fse.log.Warnv("Can not updateHeader", "err", err.Error())
return err
}
// ToDo:update file system
err = fse.file.Sync()
if err != nil {
fse.log.Warnv("Can not sync file", "err", err.Error())
return err
}
return fse.file.Close()
}
func (fse *FSEngine) GetFilePath() string {
return fse.file.Name()
}
func (fse *FSEngine) GetBlockSize() uint32 {
return fse.header.GetBlockSize()
}