@ -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] != "." {
|
||||
|
Reference in New Issue
Block a user