mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Modify: close file in main routine
This commit is contained in:
1
pkg/filesystem/archive.go
Normal file
1
pkg/filesystem/archive.go
Normal file
@@ -0,0 +1 @@
|
||||
package filesystem
|
||||
@@ -93,7 +93,6 @@ func (fs *FileSystem) GetContent(ctx context.Context, path string) (io.ReadSeeke
|
||||
// 将当前存储策略重设为文件使用的
|
||||
fs.Policy = fs.FileTarget[0].GetPolicy()
|
||||
err = fs.dispatchHandler()
|
||||
defer fs.CleanTargets()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ func TestFileSystem_GetContent(t *testing.T) {
|
||||
rs, err := fs.GetContent(ctx, "not exist file")
|
||||
asserts.Equal(ErrObjectNotExist, err)
|
||||
asserts.Nil(rs)
|
||||
fs.CleanTargets()
|
||||
|
||||
// 未知存储策略
|
||||
file, err := os.Create("TestFileSystem_GetContent.txt")
|
||||
@@ -90,6 +91,7 @@ func TestFileSystem_GetContent(t *testing.T) {
|
||||
rs, err = fs.GetContent(ctx, "/TestFileSystem_GetContent.txt")
|
||||
asserts.Error(err)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
fs.CleanTargets()
|
||||
|
||||
// 打开文件失败
|
||||
mock.ExpectQuery("SELECT(.+)").
|
||||
@@ -101,6 +103,7 @@ func TestFileSystem_GetContent(t *testing.T) {
|
||||
rs, err = fs.GetContent(ctx, "/TestFileSystem_GetContent.txt")
|
||||
asserts.Equal(serializer.CodeIOFailed, err.(serializer.AppError).Code)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
fs.CleanTargets()
|
||||
|
||||
// 打开成功
|
||||
mock.ExpectQuery("SELECT(.+)").
|
||||
|
||||
@@ -32,12 +32,13 @@ func (handler Handler) Get(ctx context.Context, path string) (io.ReadSeeker, err
|
||||
}
|
||||
|
||||
// 开启一个协程,用于请求结束后关闭reader
|
||||
go closeReader(ctx, file)
|
||||
// go closeReader(ctx, file)
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
// closeReader 用于在请求结束后关闭reader
|
||||
// TODO 让业务代码自己关闭
|
||||
func closeReader(ctx context.Context, closer io.Closer) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
||||
@@ -35,9 +35,11 @@ type policy struct {
|
||||
}
|
||||
|
||||
type group struct {
|
||||
AllowShare bool `json:"allowShare"`
|
||||
AllowRemoteDownload bool `json:"allowRemoteDownload"`
|
||||
AllowTorrentDownload bool `json:"allowTorrentDownload"`
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
AllowShare bool `json:"allowShare"`
|
||||
AllowRemoteDownload bool `json:"allowRemoteDownload"`
|
||||
AllowTorrentDownload bool `json:"allowTorrentDownload"`
|
||||
}
|
||||
|
||||
type storage struct {
|
||||
@@ -65,6 +67,8 @@ func BuildUser(user model.User) User {
|
||||
AllowGetSource: user.Policy.IsOriginLinkEnable,
|
||||
},
|
||||
Group: group{
|
||||
ID: user.GroupID,
|
||||
Name: user.Group.Name,
|
||||
AllowShare: user.Group.ShareEnabled,
|
||||
AllowRemoteDownload: aria2Option[0],
|
||||
AllowTorrentDownload: aria2Option[2],
|
||||
|
||||
Reference in New Issue
Block a user