fix(smb): remount smb before each operation (close #2123 pr #2140)

This commit is contained in:
BoYanZh
2022-10-30 15:05:07 +08:00
committed by GitHub
parent 18165eb50d
commit a3b631f9e9
2 changed files with 63 additions and 1 deletions

View File

@ -6,11 +6,20 @@ import (
"net"
"os"
"path/filepath"
"time"
"github.com/alist-org/alist/v3/internal/model"
"github.com/hirochachacha/go-smb2"
)
func (d *SMB) updateLastConnTime() {
d.lastConnTime = time.Now()
}
func (d *SMB) cleanLastConnTime() {
d.lastConnTime = time.Now().AddDate(0, 0, -1)
}
func (d *SMB) initFS() error {
conn, err := net.Dial("tcp", d.Address)
if err != nil {
@ -30,9 +39,20 @@ func (d *SMB) initFS() error {
if err != nil {
return err
}
d.updateLastConnTime()
return err
}
func (d *SMB) checkConn() error {
if time.Since(d.lastConnTime) < 5*time.Minute {
return nil
}
if d.fs != nil {
_ = d.fs.Umount()
}
return d.initFS()
}
func (d *SMB) getSMBPath(dir model.Obj) string {
fullPath := dir.GetPath()
if fullPath[0:1] != "." {