Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/115_open/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package _115_open
import (
"time"

sdk "github.com/OpenListTeam/115-sdk-go"
"github.com/OpenListTeam/OpenList/v4/internal/model"
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
sdk "github.com/OpenListTeam/115-sdk-go"
)

type Obj sdk.GetFilesResp_File
Expand Down
5 changes: 0 additions & 5 deletions drivers/189pc/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func (y *Cloud189PC) RapidUploadFromTorrent(ctx context.Context, dstDir model.Ob
sliceMd5Hex = strings.ToUpper(utils.GetMD5EncodeStr(strings.Join(upperSliceMD5s, "\n")))
}


// 使用与 Web 端一致的三步秒传流程
fullUrl := "https://upload.cloud.189.cn"
if isFamily {
Expand All @@ -110,7 +109,6 @@ func (y *Cloud189PC) RapidUploadFromTorrent(ctx context.Context, dstDir model.Ob
initParams.Set("familyId", y.FamilyID)
}


var uploadInfo InitMultiUploadResp
_, err = y.request(fullUrl+"/initMultiUpload", "GET", func(req *resty.Request) {
req.SetContext(ctx)
Expand All @@ -119,7 +117,6 @@ func (y *Cloud189PC) RapidUploadFromTorrent(ctx context.Context, dstDir model.Ob
return nil, fmt.Errorf("initMultiUpload 失败: %w", err)
}


uploadFileId := uploadInfo.Data.UploadFileID

// Step 2: checkTransSecond(用 fileMd5 + sliceMd5 + uploadFileId 检查秒传)
Expand All @@ -129,7 +126,6 @@ func (y *Cloud189PC) RapidUploadFromTorrent(ctx context.Context, dstDir model.Ob
"uploadFileId": uploadFileId,
}


var checkResp struct {
Data struct {
FileDataExists int `json:"fileDataExists"`
Expand All @@ -143,7 +139,6 @@ func (y *Cloud189PC) RapidUploadFromTorrent(ctx context.Context, dstDir model.Ob
return nil, fmt.Errorf("秒传检查失败: %w", err)
}


if checkResp.Data.FileDataExists != 1 {
return nil, fmt.Errorf("秒传失败:云端不存在该文件(fileMD5=%s, sliceMD5=%s, size=%d)", fileMD5Upper, sliceMd5Hex, fileSize)
}
Expand Down
41 changes: 25 additions & 16 deletions drivers/alias/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func (d *Alias) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
}
linkClosers := make([]io.Closer, 0, len(files))
rrf := make([]model.RangeReaderIF, 0, len(files))
requireReference := false
for _, f := range files {
link, fi, err := d.link(ctx, f.GetPath(), args)
if err != nil {
Expand All @@ -258,30 +259,41 @@ func (d *Alias) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
_ = link.Close()
continue
}
l := *link // 复制一份,避免修改到原始link
if l.ContentLength == 0 {
l.ContentLength = fi.GetSize()
l := &model.Link{
URL: link.URL,
Header: link.Header,
RangeReader: link.RangeReader,
Concurrency: link.Concurrency,
PartSize: link.PartSize,
ContentLength: link.ContentLength,
}
if d.DownloadConcurrency > 0 {
l.Concurrency = d.DownloadConcurrency
}
if d.DownloadPartSize > 0 {
l.PartSize = d.DownloadPartSize * utils.KB
}
rr, err := stream.GetRangeReaderFromLink(l.ContentLength, &l)
if l.ContentLength == 0 {
l.ContentLength = fi.GetSize()
}
rr, err := stream.GetRangeReaderFromLink(l.ContentLength, l)
if err != nil {
_ = link.Close()
continue
}
linkClosers = append(linkClosers, link)
if link.RequireReference {
requireReference = true
}
rrf = append(rrf, rr)
}
rr := func(ctx context.Context, httpRange http_range.Range) (io.ReadCloser, error) {
return rrf[rand.Intn(len(rrf))].RangeRead(ctx, httpRange)
}
return &model.Link{
RangeReader: stream.RangeReaderFunc(rr),
SyncClosers: utils.NewSyncClosers(linkClosers...),
RangeReader: stream.RangeReaderFunc(rr),
SyncClosers: utils.NewSyncClosers(linkClosers...),
RequireReference: requireReference,
}, nil
}

Expand Down Expand Up @@ -315,22 +327,21 @@ func (d *Alias) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
if err != nil {
return nil, err
}
resultLink := *link // 复制一份,避免修改到原始link
resultLink := link.Clone() // 复制一份,避免修改到原始link
resultLink.Expiration = nil
resultLink.SyncClosers = utils.NewSyncClosers(link)
if args.Redirect {
return &resultLink, nil
}
if resultLink.ContentLength == 0 {
resultLink.ContentLength = fi.GetSize()
return resultLink, nil
}
if d.DownloadConcurrency > 0 {
resultLink.Concurrency = d.DownloadConcurrency
}
if d.DownloadPartSize > 0 {
resultLink.PartSize = d.DownloadPartSize * utils.KB
}
return &resultLink, nil
if resultLink.ContentLength == 0 {
resultLink.ContentLength = fi.GetSize()
}
return resultLink, nil
}

func (d *Alias) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) {
Expand Down Expand Up @@ -501,9 +512,7 @@ func (d *Alias) Extract(ctx context.Context, obj model.Obj, args model.ArchiveIn
sign.SignArchive(reqPath)),
}, nil
}
resultLink := *link
resultLink.SyncClosers = utils.NewSyncClosers(link)
return &resultLink, nil
return link.Clone(), nil
}

func (d *Alias) ArchiveDecompress(ctx context.Context, srcObj, dstDir model.Obj, args model.ArchiveDecompressArgs) error {
Expand Down
4 changes: 1 addition & 3 deletions drivers/chunk/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ func (d *Chunk) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
if err != nil {
return nil, err
}
resultLink := *l
resultLink.SyncClosers = utils.NewSyncClosers(l)
return &resultLink, nil
return l.Clone(), nil
}
// 检查0号块不等于-1 以支持空文件
// 如果块数量大于1 最后一块不可能为0
Expand Down
3 changes: 2 additions & 1 deletion drivers/lanzou/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lanzou
import (
"context"
"net/http"
"sync/atomic"

"github.com/OpenListTeam/OpenList/v4/drivers/base"
"github.com/OpenListTeam/OpenList/v4/internal/driver"
Expand All @@ -18,7 +19,7 @@ type LanZou struct {
uid string
vei string

flag int32
flag atomic.Int32
}

func (d *LanZou) Config() driver.Config {
Expand Down
7 changes: 3 additions & 4 deletions drivers/lanzou/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/OpenListTeam/OpenList/v4/drivers/base"
Expand Down Expand Up @@ -43,17 +42,17 @@ func (d *LanZou) get(url string, callback base.ReqCallback) ([]byte, error) {
func (d *LanZou) post(url string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
data, err := d._post(url, callback, resp, false)
if err == ErrCookieExpiration && d.IsAccount() {
if atomic.CompareAndSwapInt32(&d.flag, 0, 1) {
if d.flag.CompareAndSwap(0, 1) {
_, err2 := d.Login()
atomic.SwapInt32(&d.flag, 0)
d.flag.Swap(0)
if err2 != nil {
err = errors.Join(err, err2)
d.Status = err.Error()
op.MustSaveDriverStorage(d)
return data, err
}
}
for atomic.LoadInt32(&d.flag) != 0 {
for d.flag.Load() != 0 {
runtime.Gosched()
}
return d._post(url, callback, resp, false)
Expand Down
1 change: 0 additions & 1 deletion drivers/mediafire/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,3 @@ func init() {
}
})
}

1 change: 0 additions & 1 deletion drivers/mediafire/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,3 @@ type MediafireUserInfoResponse struct {
CurrentAPIVersion string `json:"current_api_version"`
} `json:"response"`
}

1 change: 0 additions & 1 deletion drivers/mediafire/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,4 +732,3 @@ func (d *Mediafire) getFileByHash(ctx context.Context, hash string) (*model.ObjT
file := resp.Response.FileInfo[0]
return d.fileToObj(file), nil
}

3 changes: 2 additions & 1 deletion drivers/smb/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path"
"path/filepath"
"strings"
"sync/atomic"

"github.com/OpenListTeam/OpenList/v4/internal/driver"
"github.com/OpenListTeam/OpenList/v4/internal/model"
Expand All @@ -16,7 +17,7 @@ import (
)

type SMB struct {
lastConnTime int64
lastConnTime atomic.Int64
model.Storage
Addition
fs *smb2.Share
Expand Down
7 changes: 3 additions & 4 deletions drivers/smb/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io/fs"
"os"
"path/filepath"
"sync/atomic"
"time"

"github.com/OpenListTeam/OpenList/v4/pkg/singleflight"
Expand All @@ -16,15 +15,15 @@ import (
)

func (d *SMB) updateLastConnTime() {
atomic.StoreInt64(&d.lastConnTime, time.Now().Unix())
d.lastConnTime.Store(time.Now().Unix())
}

func (d *SMB) cleanLastConnTime() {
atomic.StoreInt64(&d.lastConnTime, 0)
d.lastConnTime.Store(0)
}

func (d *SMB) getLastConnTime() time.Time {
return time.Unix(atomic.LoadInt64(&d.lastConnTime), 0)
return time.Unix(d.lastConnTime.Load(), 0)
}

func (d *SMB) initFS(ctx context.Context) error {
Expand Down
4 changes: 1 addition & 3 deletions drivers/strm/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ func (d *Strm) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*
}, nil
}

resultLink := *link
resultLink.SyncClosers = utils.NewSyncClosers(link)
return &resultLink, nil
return link.Clone(), nil
}

var _ driver.Driver = (*Strm)(nil)
6 changes: 3 additions & 3 deletions drivers/webdav/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func TestGetMapsMissingPathToObjectNotFound(t *testing.T) {
}

func TestMakeDirAfterMissingWebDAVStat(t *testing.T) {
var mkcolCount int32
var mkcolCount atomic.Int32
d, cleanup := newTestDriver(t, func(w http.ResponseWriter, r *http.Request) bool {
if r.Method == "MKCOL" && (r.URL.Path == "/new" || r.URL.Path == "/new/") {
atomic.AddInt32(&mkcolCount, 1)
mkcolCount.Add(1)
w.WriteHeader(http.StatusCreated)
return true
}
Expand All @@ -37,7 +37,7 @@ func TestMakeDirAfterMissingWebDAVStat(t *testing.T) {
if err := op.MakeDir(context.Background(), d, "/new"); err != nil {
t.Fatalf("MakeDir failed: %v", err)
}
if got := atomic.LoadInt32(&mkcolCount); got != 1 {
if got := mkcolCount.Load(); got != 1 {
t.Fatalf("expected one MKCOL request, got %d", got)
}
}
Expand Down
38 changes: 19 additions & 19 deletions internal/fs/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func TestWhetherHide(t *testing.T) {
Hide: "secret",
HSub: true,
},
path: "/folder",
want: false,
path: "/folder",
want: false,
reason: "nil user (treated as admin) should not hide",
},
{
Expand All @@ -38,18 +38,18 @@ func TestWhetherHide(t *testing.T) {
Hide: "secret",
HSub: true,
},
path: "/folder",
want: false,
path: "/folder",
want: false,
reason: "user with can_see_hides permission should not hide",
},
{
name: "nil meta",
user: &model.User{
Role: model.GUEST,
},
meta: nil,
path: "/folder",
want: false,
meta: nil,
path: "/folder",
want: false,
reason: "nil meta should not hide",
},
{
Expand All @@ -62,8 +62,8 @@ func TestWhetherHide(t *testing.T) {
Hide: "",
HSub: true,
},
path: "/folder",
want: false,
path: "/folder",
want: false,
reason: "empty hide string should not hide",
},
{
Expand All @@ -76,8 +76,8 @@ func TestWhetherHide(t *testing.T) {
Hide: "secret",
HSub: false,
},
path: "/folder",
want: true,
path: "/folder",
want: true,
reason: "exact path match should hide for guest",
},
{
Expand All @@ -90,8 +90,8 @@ func TestWhetherHide(t *testing.T) {
Hide: "secret",
HSub: true,
},
path: "/folder/subfolder",
want: true,
path: "/folder/subfolder",
want: true,
reason: "sub path with HSub=true should hide for guest",
},
{
Expand All @@ -104,8 +104,8 @@ func TestWhetherHide(t *testing.T) {
Hide: "secret",
HSub: false,
},
path: "/folder/subfolder",
want: false,
path: "/folder/subfolder",
want: false,
reason: "sub path with HSub=false should not hide",
},
{
Expand All @@ -118,8 +118,8 @@ func TestWhetherHide(t *testing.T) {
Hide: "secret",
HSub: true,
},
path: "/other",
want: false,
path: "/other",
want: false,
reason: "non-sub path should not hide even with HSub=true",
},
{
Expand All @@ -133,8 +133,8 @@ func TestWhetherHide(t *testing.T) {
Hide: "secret",
HSub: true,
},
path: "/folder",
want: true,
path: "/folder",
want: true,
reason: "user without can_see_hides permission should hide",
},
}
Expand Down
Loading
Loading