/
fstab.go
36 lines (30 loc) · 914 Bytes
/
fstab.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
package v2
import (
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
"github.com/IceWhaleTech/CasaOS-LocalStorage/codegen"
"github.com/IceWhaleTech/CasaOS-LocalStorage/pkg/fstab"
"go.uber.org/zap"
)
func (s *LocalStorageService) SaveToFStab(m codegen.Mount) error {
ft := fstab.Get()
if err := ft.Add(fstab.Entry{
MountPoint: m.MountPoint,
Source: *m.Source,
FSType: *m.Fstype,
Options: *m.Options,
Dump: 0,
Pass: fstab.PassDoNotCheck,
}, true); err != nil {
logger.Error("Error when trying to persist mount", zap.Error(err), zap.Any("mount", m))
return err
}
return nil
}
func (s *LocalStorageService) RemoveFromFStab(mountpoint string) error {
ft := fstab.Get()
if err := ft.RemoveByMountPoint(mountpoint, false); err != nil {
logger.Error("Error when trying to unpersist mount", zap.Error(err), zap.String("mount point", mountpoint))
return err
}
return nil
}