mirror of https://github.com/Xhofe/alist
parent
43de823058
commit
d06c605421
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/drivers/base"
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
|
@ -19,7 +18,7 @@ type SMB struct {
|
||||||
model.Storage
|
model.Storage
|
||||||
Addition
|
Addition
|
||||||
fs *smb2.Share
|
fs *smb2.Share
|
||||||
lastConnTime time.Time
|
lastConnTime int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SMB) Config() driver.Config {
|
func (d *SMB) Config() driver.Config {
|
||||||
|
|
|
@ -6,17 +6,22 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hirochachacha/go-smb2"
|
"github.com/hirochachacha/go-smb2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *SMB) updateLastConnTime() {
|
func (d *SMB) updateLastConnTime() {
|
||||||
d.lastConnTime = time.Now()
|
atomic.StoreInt64(&d.lastConnTime, time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SMB) cleanLastConnTime() {
|
func (d *SMB) cleanLastConnTime() {
|
||||||
d.lastConnTime = time.Now().AddDate(0, 0, -1)
|
atomic.StoreInt64(&d.lastConnTime, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *SMB) getLastConnTime() time.Time {
|
||||||
|
return time.Unix(atomic.LoadInt64(&d.lastConnTime), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SMB) initFS() error {
|
func (d *SMB) initFS() error {
|
||||||
|
@ -43,7 +48,7 @@ func (d *SMB) initFS() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SMB) checkConn() error {
|
func (d *SMB) checkConn() error {
|
||||||
if time.Since(d.lastConnTime) < 5*time.Minute {
|
if time.Since(d.getLastConnTime()) < 5*time.Minute {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if d.fs != nil {
|
if d.fs != nil {
|
||||||
|
|
Loading…
Reference in New Issue