| @@ -3,7 +3,7 @@ package ioswitch2 | |||||
| import ( | import ( | ||||
| "gitlink.org.cn/cloudream/common/utils/math2" | "gitlink.org.cn/cloudream/common/utils/math2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -211,7 +211,7 @@ func (t *ToShardStore) GetRange() math2.Range { | |||||
| type ToBaseStore struct { | type ToBaseStore struct { | ||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| ObjectPath jcstypes.JPath | ObjectPath jcstypes.JPath | ||||
| Option types.WriteOption | |||||
| Option stgtypes.WriteOption | |||||
| } | } | ||||
| func NewToBaseStore(space jcstypes.UserSpaceDetail, objectPath jcstypes.JPath) *ToBaseStore { | func NewToBaseStore(space jcstypes.UserSpaceDetail, objectPath jcstypes.JPath) *ToBaseStore { | ||||
| @@ -12,7 +12,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -45,7 +45,7 @@ type BaseRead struct { | |||||
| Output exec.VarID | Output exec.VarID | ||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Path jcstypes.JPath | Path jcstypes.JPath | ||||
| Option types.OpenOption | |||||
| Option stgtypes.OpenOption | |||||
| } | } | ||||
| func (o *BaseRead) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | func (o *BaseRead) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | ||||
| @@ -104,7 +104,7 @@ type BaseReadDyn struct { | |||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Output exec.VarID | Output exec.VarID | ||||
| FileInfo exec.VarID | FileInfo exec.VarID | ||||
| Option types.OpenOption | |||||
| Option stgtypes.OpenOption | |||||
| } | } | ||||
| func (o *BaseReadDyn) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | func (o *BaseReadDyn) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | ||||
| @@ -170,7 +170,7 @@ type BaseWrite struct { | |||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Path jcstypes.JPath | Path jcstypes.JPath | ||||
| FileInfo exec.VarID | FileInfo exec.VarID | ||||
| Option types.WriteOption | |||||
| Option stgtypes.WriteOption | |||||
| } | } | ||||
| func (o *BaseWrite) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | func (o *BaseWrite) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | ||||
| @@ -215,10 +215,10 @@ type BaseReadNode struct { | |||||
| From ioswitch2.From | From ioswitch2.From | ||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Path jcstypes.JPath | Path jcstypes.JPath | ||||
| Option types.OpenOption | |||||
| Option stgtypes.OpenOption | |||||
| } | } | ||||
| func (b *GraphNodeBuilder) NewBaseRead(from ioswitch2.From, userSpace jcstypes.UserSpaceDetail, path jcstypes.JPath, opt types.OpenOption) *BaseReadNode { | |||||
| func (b *GraphNodeBuilder) NewBaseRead(from ioswitch2.From, userSpace jcstypes.UserSpaceDetail, path jcstypes.JPath, opt stgtypes.OpenOption) *BaseReadNode { | |||||
| node := &BaseReadNode{ | node := &BaseReadNode{ | ||||
| From: from, | From: from, | ||||
| UserSpace: userSpace, | UserSpace: userSpace, | ||||
| @@ -255,10 +255,10 @@ type BaseReadDynNode struct { | |||||
| dag.NodeBase | dag.NodeBase | ||||
| From ioswitch2.From | From ioswitch2.From | ||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Option types.OpenOption | |||||
| Option stgtypes.OpenOption | |||||
| } | } | ||||
| func (b *GraphNodeBuilder) NewBaseReadDyn(from ioswitch2.From, userSpace jcstypes.UserSpaceDetail, opt types.OpenOption) *BaseReadDynNode { | |||||
| func (b *GraphNodeBuilder) NewBaseReadDyn(from ioswitch2.From, userSpace jcstypes.UserSpaceDetail, opt stgtypes.OpenOption) *BaseReadDynNode { | |||||
| node := &BaseReadDynNode{ | node := &BaseReadDynNode{ | ||||
| From: from, | From: from, | ||||
| UserSpace: userSpace, | UserSpace: userSpace, | ||||
| @@ -303,10 +303,10 @@ type BaseWriteNode struct { | |||||
| To ioswitch2.To | To ioswitch2.To | ||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Path jcstypes.JPath | Path jcstypes.JPath | ||||
| Option types.WriteOption | |||||
| Option stgtypes.WriteOption | |||||
| } | } | ||||
| func (b *GraphNodeBuilder) NewBaseWrite(to ioswitch2.To, userSpace jcstypes.UserSpaceDetail, path jcstypes.JPath, opt types.WriteOption) *BaseWriteNode { | |||||
| func (b *GraphNodeBuilder) NewBaseWrite(to ioswitch2.To, userSpace jcstypes.UserSpaceDetail, path jcstypes.JPath, opt stgtypes.WriteOption) *BaseWriteNode { | |||||
| node := &BaseWriteNode{ | node := &BaseWriteNode{ | ||||
| To: to, | To: to, | ||||
| UserSpace: userSpace, | UserSpace: userSpace, | ||||
| @@ -6,7 +6,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/dag" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/dag" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -23,7 +23,7 @@ type GetShardHTTPRequest struct { | |||||
| } | } | ||||
| type HTTPRequestValue struct { | type HTTPRequestValue struct { | ||||
| types.HTTPRequest | |||||
| stgtypes.HTTPRequest | |||||
| } | } | ||||
| func (v *HTTPRequestValue) Clone() exec.VarValue { | func (v *HTTPRequestValue) Clone() exec.VarValue { | ||||
| @@ -43,7 +43,7 @@ func (o *GetShardHTTPRequest) Execute(ctx *exec.ExecContext, e *exec.Executor) e | |||||
| return err | return err | ||||
| } | } | ||||
| br, ok := shardStore.(types.HTTPShardRead) | |||||
| br, ok := shardStore.(stgtypes.HTTPShardRead) | |||||
| if !ok { | if !ok { | ||||
| return fmt.Errorf("shard store %v not support bypass read", o.UserSpace) | return fmt.Errorf("shard store %v not support bypass read", o.UserSpace) | ||||
| } | } | ||||
| @@ -12,7 +12,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/utils" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/utils" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -170,7 +170,7 @@ func (o *CallECMultiplier) Execute(ctx *exec.ExecContext, e *exec.Executor) erro | |||||
| return err | return err | ||||
| } | } | ||||
| reqs := make([]types.HTTPRequest, 0, len(inputs)) | |||||
| reqs := make([]stgtypes.HTTPRequest, 0, len(inputs)) | |||||
| for _, input := range inputs { | for _, input := range inputs { | ||||
| reqs = append(reqs, input.HTTPRequest) | reqs = append(reqs, input.HTTPRequest) | ||||
| } | } | ||||
| @@ -8,7 +8,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/dag" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/dag" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -20,7 +20,7 @@ func init() { | |||||
| } | } | ||||
| type MultipartUploadArgsValue struct { | type MultipartUploadArgsValue struct { | ||||
| InitState types.MultipartInitState | |||||
| InitState stgtypes.MultipartInitState | |||||
| } | } | ||||
| func (v *MultipartUploadArgsValue) Clone() exec.VarValue { | func (v *MultipartUploadArgsValue) Clone() exec.VarValue { | ||||
| @@ -30,7 +30,7 @@ func (v *MultipartUploadArgsValue) Clone() exec.VarValue { | |||||
| } | } | ||||
| type UploadedPartInfoValue struct { | type UploadedPartInfoValue struct { | ||||
| types.UploadedPartInfo | |||||
| stgtypes.UploadedPartInfo | |||||
| } | } | ||||
| func (v *UploadedPartInfoValue) Clone() exec.VarValue { | func (v *UploadedPartInfoValue) Clone() exec.VarValue { | ||||
| @@ -75,7 +75,7 @@ func (o *MultipartInitiator) Execute(ctx *exec.ExecContext, e *exec.Executor) er | |||||
| return fmt.Errorf("getting uploaded parts: %v", err) | return fmt.Errorf("getting uploaded parts: %v", err) | ||||
| } | } | ||||
| partInfos := make([]types.UploadedPartInfo, len(partInfoValues)) | |||||
| partInfos := make([]stgtypes.UploadedPartInfo, len(partInfoValues)) | |||||
| for i, v := range partInfoValues { | for i, v := range partInfoValues { | ||||
| partInfos[i] = v.UploadedPartInfo | partInfos[i] = v.UploadedPartInfo | ||||
| } | } | ||||
| @@ -5,7 +5,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/plan/ops" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/plan/ops" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| ) | ) | ||||
| type GraphNodeBuilder struct { | type GraphNodeBuilder struct { | ||||
| @@ -29,7 +29,7 @@ type ToNode interface { | |||||
| } | } | ||||
| type FileInfoValue struct { | type FileInfoValue struct { | ||||
| types.FileInfo | |||||
| stgtypes.FileInfo | |||||
| } | } | ||||
| func (v *FileInfoValue) Clone() exec.VarValue { | func (v *FileInfoValue) Clone() exec.VarValue { | ||||
| @@ -11,7 +11,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/ops2" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/ops2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/parser/state" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/parser/state" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -261,7 +261,7 @@ func buildFromNode(ctx *state.GenerateState, f ioswitch2.From) (ops2.FromNode, e | |||||
| getShard := ctx.DAG.NewGetShardInfo(f.UserSpace, f.FileHash) | getShard := ctx.DAG.NewGetShardInfo(f.UserSpace, f.FileHash) | ||||
| getShard.Env().ToEnvDriver(true) | getShard.Env().ToEnvDriver(true) | ||||
| read := ctx.DAG.NewBaseReadDyn(f, f.UserSpace, types.DefaultOpen()) | |||||
| read := ctx.DAG.NewBaseReadDyn(f, f.UserSpace, stgtypes.DefaultOpen()) | |||||
| getShard.FileInfoVar().ToSlot(read.FileInfoSlot()) | getShard.FileInfoVar().ToSlot(read.FileInfoSlot()) | ||||
| @@ -332,7 +332,7 @@ func buildFromNode(ctx *state.GenerateState, f ioswitch2.From) (ops2.FromNode, e | |||||
| case *ioswitch2.FromBaseStore: | case *ioswitch2.FromBaseStore: | ||||
| // TODO 可以考虑支持设置读取范围 | // TODO 可以考虑支持设置读取范围 | ||||
| n := ctx.DAG.NewBaseRead(f, f.UserSpace, f.Path, types.DefaultOpen()) | |||||
| n := ctx.DAG.NewBaseRead(f, f.UserSpace, f.Path, stgtypes.DefaultOpen()) | |||||
| if err := setEnvBySpace(n, &f.UserSpace); err != nil { | if err := setEnvBySpace(n, &f.UserSpace); err != nil { | ||||
| return nil, fmt.Errorf("set node env by user space: %w", err) | return nil, fmt.Errorf("set node env by user space: %w", err) | ||||
| } | } | ||||
| @@ -347,9 +347,9 @@ func buildFromNode(ctx *state.GenerateState, f ioswitch2.From) (ops2.FromNode, e | |||||
| func buildToNode(ctx *state.GenerateState, t ioswitch2.To) (ops2.ToNode, error) { | func buildToNode(ctx *state.GenerateState, t ioswitch2.To) (ops2.ToNode, error) { | ||||
| switch t := t.(type) { | switch t := t.(type) { | ||||
| case *ioswitch2.ToShardStore: | case *ioswitch2.ToShardStore: | ||||
| tempFileName := types.MakeTempDirPath(&t.UserSpace, os2.GenerateRandomFileName(20)) | |||||
| tempFileName := stgtypes.MakeTempDirPath(&t.UserSpace, os2.GenerateRandomFileName(20)) | |||||
| write := ctx.DAG.NewBaseWrite(t, t.UserSpace, tempFileName, types.WriteOption{}) | |||||
| write := ctx.DAG.NewBaseWrite(t, t.UserSpace, tempFileName, stgtypes.WriteOption{}) | |||||
| if err := setEnvBySpace(write, &t.UserSpace); err != nil { | if err := setEnvBySpace(write, &t.UserSpace); err != nil { | ||||
| return nil, fmt.Errorf("set node env by user space: %w", err) | return nil, fmt.Errorf("set node env by user space: %w", err) | ||||
| } | } | ||||
| @@ -7,7 +7,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/ops2" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/ops2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/parser/state" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/parser/state" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| ) | ) | ||||
| // 减少未使用的Multiply指令的输出流。如果减少到0,则删除该指令 | // 减少未使用的Multiply指令的输出流。如果减少到0,则删除该指令 | ||||
| @@ -102,7 +102,7 @@ func UseECMultiplier(ctx *state.GenerateState) { | |||||
| if err != nil { | if err != nil { | ||||
| return true | return true | ||||
| } | } | ||||
| _, ok = store.(types.HTTPShardRead) | |||||
| _, ok = store.(stgtypes.HTTPShardRead) | |||||
| if !ok { | if !ok { | ||||
| return true | return true | ||||
| } | } | ||||
| @@ -7,7 +7,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/plan" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/plan" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/ops2" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/ops2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -27,7 +27,7 @@ func CompleteMultipart(blocks []jcstypes.ObjectBlock, blockSpaces []jcstypes.Use | |||||
| gs := da.NewGetShardInfo(blockSpaces[i], blk.FileHash) | gs := da.NewGetShardInfo(blockSpaces[i], blk.FileHash) | ||||
| gs.Env().ToEnvDriver(true) | gs.Env().ToEnvDriver(true) | ||||
| br := da.NewBaseReadDyn(nil, blockSpaces[i], types.DefaultOpen()) | |||||
| br := da.NewBaseReadDyn(nil, blockSpaces[i], stgtypes.DefaultOpen()) | |||||
| if err := setEnvBySpace(br, &blockSpaces[i]); err != nil { | if err := setEnvBySpace(br, &blockSpaces[i]); err != nil { | ||||
| return fmt.Errorf("set node env by user space: %w", err) | return fmt.Errorf("set node env by user space: %w", err) | ||||
| } | } | ||||
| @@ -38,7 +38,7 @@ func CompleteMultipart(blocks []jcstypes.ObjectBlock, blockSpaces []jcstypes.Use | |||||
| } | } | ||||
| // TODO 应该采取更合理的方式同时支持Parser和直接生成DAG | // TODO 应该采取更合理的方式同时支持Parser和直接生成DAG | ||||
| br := da.NewBaseWrite(nil, targetSpace, types.MakeTempDirPath(&targetSpace, os2.GenerateRandomFileName(20)), types.WriteOption{}) | |||||
| br := da.NewBaseWrite(nil, targetSpace, stgtypes.MakeTempDirPath(&targetSpace, os2.GenerateRandomFileName(20)), stgtypes.WriteOption{}) | |||||
| if err := setEnvBySpace(br, &targetSpace); err != nil { | if err := setEnvBySpace(br, &targetSpace); err != nil { | ||||
| return fmt.Errorf("set node env by user space: %w", err) | return fmt.Errorf("set node env by user space: %w", err) | ||||
| } | } | ||||
| @@ -3,7 +3,7 @@ package ioswitchlrc | |||||
| import ( | import ( | ||||
| "gitlink.org.cn/cloudream/common/utils/math2" | "gitlink.org.cn/cloudream/common/utils/math2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -92,7 +92,7 @@ type ToNode struct { | |||||
| DataIndex int | DataIndex int | ||||
| Range math2.Range | Range math2.Range | ||||
| FileHashStoreKey string | FileHashStoreKey string | ||||
| Option types.WriteOption | |||||
| Option stgtypes.WriteOption | |||||
| } | } | ||||
| func NewToStorage(space jcstypes.UserSpaceDetail, dataIndex int, fileHashStoreKey string) *ToNode { | func NewToStorage(space jcstypes.UserSpaceDetail, dataIndex int, fileHashStoreKey string) *ToNode { | ||||
| @@ -11,7 +11,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitchlrc" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitchlrc" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/pool" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -25,7 +25,7 @@ type BaseRead struct { | |||||
| Output exec.VarID | Output exec.VarID | ||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Path jcstypes.JPath | Path jcstypes.JPath | ||||
| Option types.OpenOption | |||||
| Option stgtypes.OpenOption | |||||
| } | } | ||||
| func (o *BaseRead) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | func (o *BaseRead) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | ||||
| @@ -70,7 +70,7 @@ type BaseReadDyn struct { | |||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Output exec.VarID | Output exec.VarID | ||||
| Path exec.VarID | Path exec.VarID | ||||
| Option types.OpenOption | |||||
| Option stgtypes.OpenOption | |||||
| } | } | ||||
| func (o *BaseReadDyn) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | func (o *BaseReadDyn) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | ||||
| @@ -121,7 +121,7 @@ type BaseWrite struct { | |||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Path jcstypes.JPath | Path jcstypes.JPath | ||||
| WriteResult exec.VarID | WriteResult exec.VarID | ||||
| Option types.WriteOption | |||||
| Option stgtypes.WriteOption | |||||
| } | } | ||||
| func (o *BaseWrite) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | func (o *BaseWrite) Execute(ctx *exec.ExecContext, e *exec.Executor) error { | ||||
| @@ -166,10 +166,10 @@ type BaseReadNode struct { | |||||
| From ioswitchlrc.From | From ioswitchlrc.From | ||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Path jcstypes.JPath | Path jcstypes.JPath | ||||
| Option types.OpenOption | |||||
| Option stgtypes.OpenOption | |||||
| } | } | ||||
| func (b *GraphNodeBuilder) NewBaseRead(from ioswitchlrc.From, userSpace jcstypes.UserSpaceDetail, path jcstypes.JPath, opt types.OpenOption) *BaseReadNode { | |||||
| func (b *GraphNodeBuilder) NewBaseRead(from ioswitchlrc.From, userSpace jcstypes.UserSpaceDetail, path jcstypes.JPath, opt stgtypes.OpenOption) *BaseReadNode { | |||||
| node := &BaseReadNode{ | node := &BaseReadNode{ | ||||
| From: from, | From: from, | ||||
| UserSpace: userSpace, | UserSpace: userSpace, | ||||
| @@ -206,10 +206,10 @@ type BaseReadDynNode struct { | |||||
| dag.NodeBase | dag.NodeBase | ||||
| From ioswitchlrc.From | From ioswitchlrc.From | ||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Option types.OpenOption | |||||
| Option stgtypes.OpenOption | |||||
| } | } | ||||
| func (b *GraphNodeBuilder) NewBaseReadDyn(from ioswitchlrc.From, userSpace jcstypes.UserSpaceDetail, opt types.OpenOption) *BaseReadDynNode { | |||||
| func (b *GraphNodeBuilder) NewBaseReadDyn(from ioswitchlrc.From, userSpace jcstypes.UserSpaceDetail, opt stgtypes.OpenOption) *BaseReadDynNode { | |||||
| node := &BaseReadDynNode{ | node := &BaseReadDynNode{ | ||||
| From: from, | From: from, | ||||
| UserSpace: userSpace, | UserSpace: userSpace, | ||||
| @@ -254,10 +254,10 @@ type BaseWriteNode struct { | |||||
| To ioswitchlrc.To | To ioswitchlrc.To | ||||
| UserSpace jcstypes.UserSpaceDetail | UserSpace jcstypes.UserSpaceDetail | ||||
| Path jcstypes.JPath | Path jcstypes.JPath | ||||
| Option types.WriteOption | |||||
| Option stgtypes.WriteOption | |||||
| } | } | ||||
| func (b *GraphNodeBuilder) NewBaseWrite(to ioswitchlrc.To, userSpace jcstypes.UserSpaceDetail, path jcstypes.JPath, opt types.WriteOption) *BaseWriteNode { | |||||
| func (b *GraphNodeBuilder) NewBaseWrite(to ioswitchlrc.To, userSpace jcstypes.UserSpaceDetail, path jcstypes.JPath, opt stgtypes.WriteOption) *BaseWriteNode { | |||||
| node := &BaseWriteNode{ | node := &BaseWriteNode{ | ||||
| To: to, | To: to, | ||||
| UserSpace: userSpace, | UserSpace: userSpace, | ||||
| @@ -4,7 +4,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/dag" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/dag" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/plan/ops" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/plan/ops" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| ) | ) | ||||
| type GraphNodeBuilder struct { | type GraphNodeBuilder struct { | ||||
| @@ -26,7 +26,7 @@ type ToNode interface { | |||||
| } | } | ||||
| type FileInfoValue struct { | type FileInfoValue struct { | ||||
| types.FileInfo | |||||
| stgtypes.FileInfo | |||||
| } | } | ||||
| func (v *FileInfoValue) Clone() exec.VarValue { | func (v *FileInfoValue) Clone() exec.VarValue { | ||||
| @@ -9,7 +9,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/dag" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/dag" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitchlrc" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitchlrc" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitchlrc/ops2" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitchlrc/ops2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| ) | ) | ||||
| // 计算输入流的打开范围。会把流的范围按条带大小取整 | // 计算输入流的打开范围。会把流的范围按条带大小取整 | ||||
| @@ -66,7 +66,7 @@ func buildFromNode(ctx *GenerateContext, f ioswitchlrc.From) (ops2.FromNode, err | |||||
| getShard := ctx.DAG.NewGetShardInfo(f.UserSpace, f.FileHash) | getShard := ctx.DAG.NewGetShardInfo(f.UserSpace, f.FileHash) | ||||
| getShard.Env().ToEnvDriver(true) | getShard.Env().ToEnvDriver(true) | ||||
| read := ctx.DAG.NewBaseReadDyn(f, f.UserSpace, types.DefaultOpen()) | |||||
| read := ctx.DAG.NewBaseReadDyn(f, f.UserSpace, stgtypes.DefaultOpen()) | |||||
| if f.DataIndex == -1 { | if f.DataIndex == -1 { | ||||
| read.Option.WithNullableLength(repRange.Offset, repRange.Length) | read.Option.WithNullableLength(repRange.Offset, repRange.Length) | ||||
| @@ -102,7 +102,7 @@ func buildFromNode(ctx *GenerateContext, f ioswitchlrc.From) (ops2.FromNode, err | |||||
| func buildToNode(ctx *GenerateContext, t ioswitchlrc.To) (ops2.ToNode, error) { | func buildToNode(ctx *GenerateContext, t ioswitchlrc.To) (ops2.ToNode, error) { | ||||
| switch t := t.(type) { | switch t := t.(type) { | ||||
| case *ioswitchlrc.ToNode: | case *ioswitchlrc.ToNode: | ||||
| tempFileName := types.MakeTempDirPath(&t.UserSpace, os2.GenerateRandomFileName(20)) | |||||
| tempFileName := stgtypes.MakeTempDirPath(&t.UserSpace, os2.GenerateRandomFileName(20)) | |||||
| write := ctx.DAG.NewBaseWrite(t, t.UserSpace, tempFileName, t.Option) | write := ctx.DAG.NewBaseWrite(t, t.UserSpace, tempFileName, t.Option) | ||||
| if err := setEnvBySpace(write, &t.UserSpace); err != nil { | if err := setEnvBySpace(write, &t.UserSpace); err != nil { | ||||
| @@ -9,7 +9,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/common/utils/http2" | "gitlink.org.cn/cloudream/common/utils/http2" | ||||
| "gitlink.org.cn/cloudream/common/utils/os2" | "gitlink.org.cn/cloudream/common/utils/os2" | ||||
| "gitlink.org.cn/cloudream/common/utils/serder" | "gitlink.org.cn/cloudream/common/utils/serder" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -22,12 +22,12 @@ type ECMultiplier struct { | |||||
| // 进行EC运算,coef * inputs。coef为编码矩阵,inputs为待编码数据,chunkSize为分块大小。 | // 进行EC运算,coef * inputs。coef为编码矩阵,inputs为待编码数据,chunkSize为分块大小。 | ||||
| // 输出为每一个块文件的路径,数组长度 = len(coef) | // 输出为每一个块文件的路径,数组长度 = len(coef) | ||||
| func (m *ECMultiplier) Multiply(coef [][]byte, inputs []types.HTTPRequest, chunkSize int) ([]types.FileInfo, error) { | |||||
| func (m *ECMultiplier) Multiply(coef [][]byte, inputs []stgtypes.HTTPRequest, chunkSize int) ([]stgtypes.FileInfo, error) { | |||||
| type Request struct { | type Request struct { | ||||
| Inputs []types.HTTPRequest `json:"inputs"` | |||||
| Outputs []string `json:"outputs"` | |||||
| Coefs [][]int `json:"coefs"` // 用int防止被base64编码 | |||||
| ChunkSize int `json:"chunkSize"` | |||||
| Inputs []stgtypes.HTTPRequest `json:"inputs"` | |||||
| Outputs []string `json:"outputs"` | |||||
| Coefs [][]int `json:"coefs"` // 用int防止被base64编码 | |||||
| ChunkSize int `json:"chunkSize"` | |||||
| } | } | ||||
| type Response struct { | type Response struct { | ||||
| Code string `json:"code"` | Code string `json:"code"` | ||||
| @@ -47,7 +47,7 @@ func (m *ECMultiplier) Multiply(coef [][]byte, inputs []types.HTTPRequest, chunk | |||||
| } | } | ||||
| fileName := os2.GenerateRandomFileName(10) | fileName := os2.GenerateRandomFileName(10) | ||||
| tempDir := path.Join(m.blder.detail.UserSpace.WorkingDir.String(), types.TempWorkingDir) | |||||
| tempDir := path.Join(m.blder.detail.UserSpace.WorkingDir.String(), stgtypes.TempWorkingDir) | |||||
| m.outputs = make([]string, len(coef)) | m.outputs = make([]string, len(coef)) | ||||
| for i := range m.outputs { | for i := range m.outputs { | ||||
| m.outputs[i] = path.Join(tempDir, fmt.Sprintf("%s_%d", fileName, i)) | m.outputs[i] = path.Join(tempDir, fmt.Sprintf("%s_%d", fileName, i)) | ||||
| @@ -93,9 +93,9 @@ func (m *ECMultiplier) Multiply(coef [][]byte, inputs []types.HTTPRequest, chunk | |||||
| return nil, fmt.Errorf("data length not match outputs length") | return nil, fmt.Errorf("data length not match outputs length") | ||||
| } | } | ||||
| ret := make([]types.FileInfo, len(r.Data)) | |||||
| ret := make([]stgtypes.FileInfo, len(r.Data)) | |||||
| for i, data := range r.Data { | for i, data := range r.Data { | ||||
| ret[i] = types.FileInfo{ | |||||
| ret[i] = stgtypes.FileInfo{ | |||||
| // TODO 要确认一下output的格式 | // TODO 要确认一下output的格式 | ||||
| Path: jcstypes.PathFromJcsPathString(m.outputs[i]), | Path: jcstypes.PathFromJcsPathString(m.outputs[i]), | ||||
| Size: data.Size, | Size: data.Size, | ||||
| @@ -9,12 +9,12 @@ import ( | |||||
| "gitlink.org.cn/cloudream/common/utils/http2" | "gitlink.org.cn/cloudream/common/utils/http2" | ||||
| "gitlink.org.cn/cloudream/common/utils/serder" | "gitlink.org.cn/cloudream/common/utils/serder" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| func init() { | func init() { | ||||
| reg.RegisterBuilder[*jcstypes.EFileType](func(detail *jcstypes.UserSpaceDetail) types.StorageBuilder { | |||||
| reg.RegisterBuilder[*jcstypes.EFileType](func(detail *jcstypes.UserSpaceDetail) stgtypes.StorageBuilder { | |||||
| return &builder{ | return &builder{ | ||||
| detail: detail, | detail: detail, | ||||
| } | } | ||||
| @@ -22,7 +22,7 @@ func init() { | |||||
| } | } | ||||
| type builder struct { | type builder struct { | ||||
| types.EmptyBuilder | |||||
| stgtypes.EmptyBuilder | |||||
| detail *jcstypes.UserSpaceDetail | detail *jcstypes.UserSpaceDetail | ||||
| token string | token string | ||||
| tokenLock sync.Mutex | tokenLock sync.Mutex | ||||
| @@ -89,8 +89,8 @@ func (b *builder) getToken() (string, error) { | |||||
| return "", fmt.Errorf("clusterID %s not found", stgType.ClusterID) | return "", fmt.Errorf("clusterID %s not found", stgType.ClusterID) | ||||
| } | } | ||||
| func (b *builder) CreateECMultiplier(typeOnly bool) (types.ECMultiplier, error) { | |||||
| feat := types.FindFeature[*jcstypes.ECMultiplierFeature](b.detail) | |||||
| func (b *builder) CreateECMultiplier(typeOnly bool) (stgtypes.ECMultiplier, error) { | |||||
| feat := stgtypes.FindFeature[*jcstypes.ECMultiplierFeature](b.detail) | |||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature ECMultiplier not found") | return nil, fmt.Errorf("feature ECMultiplier not found") | ||||
| } | } | ||||
| @@ -5,18 +5,18 @@ import ( | |||||
| _ "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage" | _ "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| // 此函数永远不会返回nil。如果找不到对应的Builder,则会返回EmptyBuilder, | // 此函数永远不会返回nil。如果找不到对应的Builder,则会返回EmptyBuilder, | ||||
| // 此Builder的所有函数都会返回否定值或者封装后的ErrUnsupported错误(需要使用errors.Is检查) | // 此Builder的所有函数都会返回否定值或者封装后的ErrUnsupported错误(需要使用errors.Is检查) | ||||
| func GetBuilder(detail *jcstypes.UserSpaceDetail) types.StorageBuilder { | |||||
| func GetBuilder(detail *jcstypes.UserSpaceDetail) stgtypes.StorageBuilder { | |||||
| typ := reflect.TypeOf(detail.UserSpace.Storage) | typ := reflect.TypeOf(detail.UserSpace.Storage) | ||||
| ctor, ok := reg.StorageBuilders[typ] | ctor, ok := reg.StorageBuilders[typ] | ||||
| if !ok { | if !ok { | ||||
| return &types.EmptyBuilder{} | |||||
| return &stgtypes.EmptyBuilder{} | |||||
| } | } | ||||
| return ctor(detail) | return ctor(detail) | ||||
| @@ -4,11 +4,11 @@ import ( | |||||
| "reflect" | "reflect" | ||||
| "gitlink.org.cn/cloudream/common/utils/reflect2" | "gitlink.org.cn/cloudream/common/utils/reflect2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| type BuilderCtor func(detail *jcstypes.UserSpaceDetail) types.StorageBuilder | |||||
| type BuilderCtor func(detail *jcstypes.UserSpaceDetail) stgtypes.StorageBuilder | |||||
| var StorageBuilders = make(map[reflect.Type]BuilderCtor) | var StorageBuilders = make(map[reflect.Type]BuilderCtor) | ||||
| @@ -20,12 +20,12 @@ func RegisterBuilder[T jcstypes.StorageType](ctor BuilderCtor) { | |||||
| // 注:此函数只给storage包内部使用,外部包请使用外层的factory.GetBuilder | // 注:此函数只给storage包内部使用,外部包请使用外层的factory.GetBuilder | ||||
| // 此函数永远不会返回nil。如果找不到对应的Builder,则会返回EmptyBuilder, | // 此函数永远不会返回nil。如果找不到对应的Builder,则会返回EmptyBuilder, | ||||
| // 此Builder的所有函数都会返回否定值或者封装后的ErrUnsupported错误(需要使用errors.Is检查) | // 此Builder的所有函数都会返回否定值或者封装后的ErrUnsupported错误(需要使用errors.Is检查) | ||||
| func GetBuilderInternal(detail *jcstypes.UserSpaceDetail) types.StorageBuilder { | |||||
| func GetBuilderInternal(detail *jcstypes.UserSpaceDetail) stgtypes.StorageBuilder { | |||||
| typ := reflect.TypeOf(detail.UserSpace.Storage) | typ := reflect.TypeOf(detail.UserSpace.Storage) | ||||
| ctor, ok := StorageBuilders[typ] | ctor, ok := StorageBuilders[typ] | ||||
| if !ok { | if !ok { | ||||
| return &types.EmptyBuilder{} | |||||
| return &stgtypes.EmptyBuilder{} | |||||
| } | } | ||||
| return ctor(detail) | return ctor(detail) | ||||
| @@ -8,7 +8,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/common/pkgs/logger" | "gitlink.org.cn/cloudream/common/pkgs/logger" | ||||
| "gitlink.org.cn/cloudream/common/utils/io2" | "gitlink.org.cn/cloudream/common/utils/io2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -24,19 +24,19 @@ func NewBaseStore(root string, detail *jcstypes.UserSpaceDetail) (*BaseStore, er | |||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *BaseStore) Write(pat jcstypes.JPath, stream io.Reader, opt types.WriteOption) (types.FileInfo, error) { | |||||
| func (s *BaseStore) Write(pat jcstypes.JPath, stream io.Reader, opt stgtypes.WriteOption) (stgtypes.FileInfo, error) { | |||||
| log := s.getLogger() | log := s.getLogger() | ||||
| absObjPath := filepath.Join(s.root, pat.String()) | absObjPath := filepath.Join(s.root, pat.String()) | ||||
| err := os.MkdirAll(filepath.Dir(absObjPath), 0755) | err := os.MkdirAll(filepath.Dir(absObjPath), 0755) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| f, err := os.Create(absObjPath) | f, err := os.Create(absObjPath) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| defer f.Close() | defer f.Close() | ||||
| @@ -45,7 +45,7 @@ func (s *BaseStore) Write(pat jcstypes.JPath, stream io.Reader, opt types.WriteO | |||||
| _, err = io.Copy(f, hasher) | _, err = io.Copy(f, hasher) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| if !opt.ModTime.IsZero() { | if !opt.ModTime.IsZero() { | ||||
| @@ -55,14 +55,14 @@ func (s *BaseStore) Write(pat jcstypes.JPath, stream io.Reader, opt types.WriteO | |||||
| } | } | ||||
| } | } | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Path: pat, | Path: pat, | ||||
| Size: counter.Count(), | Size: counter.Count(), | ||||
| Hash: jcstypes.NewFullHash(hasher.Sum()), | Hash: jcstypes.NewFullHash(hasher.Sum()), | ||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *BaseStore) Read(objPath jcstypes.JPath, opt types.OpenOption) (io.ReadCloser, error) { | |||||
| func (s *BaseStore) Read(objPath jcstypes.JPath, opt stgtypes.OpenOption) (io.ReadCloser, error) { | |||||
| absObjPath := filepath.Join(s.root, objPath.JoinOSPath()) | absObjPath := filepath.Join(s.root, objPath.JoinOSPath()) | ||||
| file, err := os.Open(absObjPath) | file, err := os.Open(absObjPath) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -96,7 +96,7 @@ func (s *BaseStore) Mkdir(path jcstypes.JPath) error { | |||||
| return nil | return nil | ||||
| } | } | ||||
| func (s *BaseStore) ReadDir(pat jcstypes.JPath) types.DirReader { | |||||
| func (s *BaseStore) ReadDir(pat jcstypes.JPath) stgtypes.DirReader { | |||||
| return &DirReader{ | return &DirReader{ | ||||
| absRootPath: filepath.Join(s.root, pat.JoinOSPath()), | absRootPath: filepath.Join(s.root, pat.JoinOSPath()), | ||||
| rootJPath: pat.Clone(), | rootJPath: pat.Clone(), | ||||
| @@ -106,7 +106,7 @@ func (s *BaseStore) ReadDir(pat jcstypes.JPath) types.DirReader { | |||||
| func (s *BaseStore) CleanTemps() { | func (s *BaseStore) CleanTemps() { | ||||
| log := s.getLogger() | log := s.getLogger() | ||||
| tempDir := filepath.Join(s.root, s.detail.UserSpace.WorkingDir.JoinOSPath(), types.TempWorkingDir) | |||||
| tempDir := filepath.Join(s.root, s.detail.UserSpace.WorkingDir.JoinOSPath(), stgtypes.TempWorkingDir) | |||||
| entries, err := os.ReadDir(tempDir) | entries, err := os.ReadDir(tempDir) | ||||
| if err != nil { | if err != nil { | ||||
| log.Warnf("read temp dir: %v", err) | log.Warnf("read temp dir: %v", err) | ||||
| @@ -5,7 +5,7 @@ import ( | |||||
| "os" | "os" | ||||
| "path/filepath" | "path/filepath" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -18,16 +18,16 @@ type DirReader struct { | |||||
| curEntries []dirEntry | curEntries []dirEntry | ||||
| } | } | ||||
| func (r *DirReader) Next() (types.DirEntry, error) { | |||||
| func (r *DirReader) Next() (stgtypes.DirEntry, error) { | |||||
| if !r.init { | if !r.init { | ||||
| info, err := os.Stat(r.absRootPath) | info, err := os.Stat(r.absRootPath) | ||||
| if err != nil { | if err != nil { | ||||
| return types.DirEntry{}, err | |||||
| return stgtypes.DirEntry{}, err | |||||
| } | } | ||||
| if !info.IsDir() { | if !info.IsDir() { | ||||
| r.init = true | r.init = true | ||||
| return types.DirEntry{ | |||||
| return stgtypes.DirEntry{ | |||||
| Path: r.rootJPath, | Path: r.rootJPath, | ||||
| Size: info.Size(), | Size: info.Size(), | ||||
| ModTime: info.ModTime(), | ModTime: info.ModTime(), | ||||
| @@ -37,7 +37,7 @@ func (r *DirReader) Next() (types.DirEntry, error) { | |||||
| es, err := os.ReadDir(r.absRootPath) | es, err := os.ReadDir(r.absRootPath) | ||||
| if err != nil { | if err != nil { | ||||
| return types.DirEntry{}, err | |||||
| return stgtypes.DirEntry{}, err | |||||
| } | } | ||||
| for _, e := range es { | for _, e := range es { | ||||
| @@ -50,7 +50,7 @@ func (r *DirReader) Next() (types.DirEntry, error) { | |||||
| r.init = true | r.init = true | ||||
| } | } | ||||
| if len(r.curEntries) == 0 { | if len(r.curEntries) == 0 { | ||||
| return types.DirEntry{}, io.EOF | |||||
| return stgtypes.DirEntry{}, io.EOF | |||||
| } | } | ||||
| entry := r.curEntries[0] | entry := r.curEntries[0] | ||||
| @@ -59,7 +59,7 @@ func (r *DirReader) Next() (types.DirEntry, error) { | |||||
| if entry.entry.IsDir() { | if entry.entry.IsDir() { | ||||
| es, err := os.ReadDir(filepath.Join(r.absRootPath, entry.dir.JoinOSPath(), entry.entry.Name())) | es, err := os.ReadDir(filepath.Join(r.absRootPath, entry.dir.JoinOSPath(), entry.entry.Name())) | ||||
| if err != nil { | if err != nil { | ||||
| return types.DirEntry{}, err | |||||
| return stgtypes.DirEntry{}, err | |||||
| } | } | ||||
| // 多个entry对象共享同一个JPath对象,但因为不会修改JPath,所以没问题 | // 多个entry对象共享同一个JPath对象,但因为不会修改JPath,所以没问题 | ||||
| @@ -75,14 +75,14 @@ func (r *DirReader) Next() (types.DirEntry, error) { | |||||
| info, err := entry.entry.Info() | info, err := entry.entry.Info() | ||||
| if err != nil { | if err != nil { | ||||
| return types.DirEntry{}, err | |||||
| return stgtypes.DirEntry{}, err | |||||
| } | } | ||||
| p := r.rootJPath.ConcatNew(entry.dir) | p := r.rootJPath.ConcatNew(entry.dir) | ||||
| p.Push(entry.entry.Name()) | p.Push(entry.entry.Name()) | ||||
| if entry.entry.IsDir() { | if entry.entry.IsDir() { | ||||
| return types.DirEntry{ | |||||
| return stgtypes.DirEntry{ | |||||
| Path: p, | Path: p, | ||||
| Size: 0, | Size: 0, | ||||
| ModTime: info.ModTime(), | ModTime: info.ModTime(), | ||||
| @@ -90,7 +90,7 @@ func (r *DirReader) Next() (types.DirEntry, error) { | |||||
| }, nil | }, nil | ||||
| } | } | ||||
| return types.DirEntry{ | |||||
| return stgtypes.DirEntry{ | |||||
| Path: p, | Path: p, | ||||
| Size: info.Size(), | Size: info.Size(), | ||||
| ModTime: info.ModTime(), | ModTime: info.ModTime(), | ||||
| @@ -4,12 +4,12 @@ import ( | |||||
| "fmt" | "fmt" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| func init() { | func init() { | ||||
| reg.RegisterBuilder[*jcstypes.LocalType](func(detail *jcstypes.UserSpaceDetail) types.StorageBuilder { | |||||
| reg.RegisterBuilder[*jcstypes.LocalType](func(detail *jcstypes.UserSpaceDetail) stgtypes.StorageBuilder { | |||||
| return &builder{ | return &builder{ | ||||
| detail: detail, | detail: detail, | ||||
| } | } | ||||
| @@ -17,15 +17,15 @@ func init() { | |||||
| } | } | ||||
| type builder struct { | type builder struct { | ||||
| types.EmptyBuilder | |||||
| stgtypes.EmptyBuilder | |||||
| detail *jcstypes.UserSpaceDetail | detail *jcstypes.UserSpaceDetail | ||||
| } | } | ||||
| func (b *builder) FeatureDesc() types.FeatureDesc { | |||||
| return types.FeatureDesc{} | |||||
| func (b *builder) FeatureDesc() stgtypes.FeatureDesc { | |||||
| return stgtypes.FeatureDesc{} | |||||
| } | } | ||||
| func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | |||||
| func (b *builder) CreateShardStore(typeOnly bool) (stgtypes.ShardStore, error) { | |||||
| cred, ok := b.detail.UserSpace.Credential.(*jcstypes.LocalCred) | cred, ok := b.detail.UserSpace.Credential.(*jcstypes.LocalCred) | ||||
| if !ok { | if !ok { | ||||
| return nil, fmt.Errorf("invalid storage credential type %T for local storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for local storage", b.detail.UserSpace.Credential) | ||||
| @@ -38,7 +38,7 @@ func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | |||||
| return NewShardStore(cred.RootDir, b.detail) | return NewShardStore(cred.RootDir, b.detail) | ||||
| } | } | ||||
| func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | |||||
| func (b *builder) CreateBaseStore(typeOnly bool) (stgtypes.BaseStore, error) { | |||||
| cred, ok := b.detail.UserSpace.Credential.(*jcstypes.LocalCred) | cred, ok := b.detail.UserSpace.Credential.(*jcstypes.LocalCred) | ||||
| if !ok { | if !ok { | ||||
| return nil, fmt.Errorf("invalid storage credential type %T for local storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for local storage", b.detail.UserSpace.Credential) | ||||
| @@ -51,8 +51,8 @@ func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | |||||
| return NewBaseStore(cred.RootDir, b.detail) | return NewBaseStore(cred.RootDir, b.detail) | ||||
| } | } | ||||
| func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | |||||
| feat := types.FindFeature[*jcstypes.MultipartUploadFeature](b.detail) | |||||
| func (b *builder) CreateMultiparter(typeOnly bool) (stgtypes.Multiparter, error) { | |||||
| feat := stgtypes.FindFeature[*jcstypes.MultipartUploadFeature](b.detail) | |||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature %T not found", jcstypes.MultipartUploadFeature{}) | return nil, fmt.Errorf("feature %T not found", jcstypes.MultipartUploadFeature{}) | ||||
| } | } | ||||
| @@ -66,8 +66,8 @@ func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | |||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (b *builder) CreateS2STransfer(typeOnly bool) (types.S2STransfer, error) { | |||||
| feat := types.FindFeature[*jcstypes.S2STransferFeature](b.detail) | |||||
| func (b *builder) CreateS2STransfer(typeOnly bool) (stgtypes.S2STransfer, error) { | |||||
| feat := stgtypes.FindFeature[*jcstypes.S2STransferFeature](b.detail) | |||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature %T not found", jcstypes.S2STransferFeature{}) | return nil, fmt.Errorf("feature %T not found", jcstypes.S2STransferFeature{}) | ||||
| } | } | ||||
| @@ -12,7 +12,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/common/utils/io2" | "gitlink.org.cn/cloudream/common/utils/io2" | ||||
| "gitlink.org.cn/cloudream/common/utils/os2" | "gitlink.org.cn/cloudream/common/utils/os2" | ||||
| "gitlink.org.cn/cloudream/common/utils/sort2" | "gitlink.org.cn/cloudream/common/utils/sort2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -30,8 +30,8 @@ func (*Multiparter) MaxPartSize() int64 { | |||||
| return 5 * 1024 * 1024 * 1024 // 5GB | return 5 * 1024 * 1024 * 1024 // 5GB | ||||
| } | } | ||||
| func (m *Multiparter) Initiate(ctx context.Context) (types.MultipartTask, error) { | |||||
| tempDir := filepath.Join(m.localStg.RootDir, m.detail.UserSpace.WorkingDir.JoinOSPath(), types.TempWorkingDir) | |||||
| func (m *Multiparter) Initiate(ctx context.Context) (stgtypes.MultipartTask, error) { | |||||
| tempDir := filepath.Join(m.localStg.RootDir, m.detail.UserSpace.WorkingDir.JoinOSPath(), stgtypes.TempWorkingDir) | |||||
| absTempDir, err := filepath.Abs(tempDir) | absTempDir, err := filepath.Abs(tempDir) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, fmt.Errorf("get abs temp dir %v: %v", tempDir, err) | return nil, fmt.Errorf("get abs temp dir %v: %v", tempDir, err) | ||||
| @@ -51,25 +51,25 @@ func (m *Multiparter) Initiate(ctx context.Context) (types.MultipartTask, error) | |||||
| absTempDir: absTempDir, | absTempDir: absTempDir, | ||||
| tempFileName: tempFileName, | tempFileName: tempFileName, | ||||
| tempPartsDir: tempPartsDir, | tempPartsDir: tempPartsDir, | ||||
| joinedFileJPath: m.detail.UserSpace.WorkingDir.ConcatCompsNew(types.TempWorkingDir, tempFileName+".joined"), | |||||
| joinedFileJPath: m.detail.UserSpace.WorkingDir.ConcatCompsNew(stgtypes.TempWorkingDir, tempFileName+".joined"), | |||||
| absJoinedFilePath: absJoinedFilePath, | absJoinedFilePath: absJoinedFilePath, | ||||
| uploadID: tempPartsDir, | uploadID: tempPartsDir, | ||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (m *Multiparter) UploadPart(ctx context.Context, init types.MultipartInitState, partSize int64, partNumber int, stream io.Reader) (types.UploadedPartInfo, error) { | |||||
| func (m *Multiparter) UploadPart(ctx context.Context, init stgtypes.MultipartInitState, partSize int64, partNumber int, stream io.Reader) (stgtypes.UploadedPartInfo, error) { | |||||
| partFilePath := filepath.Join(init.UploadID, fmt.Sprintf("%v", partNumber)) | partFilePath := filepath.Join(init.UploadID, fmt.Sprintf("%v", partNumber)) | ||||
| partFile, err := os.Create(partFilePath) | partFile, err := os.Create(partFilePath) | ||||
| if err != nil { | if err != nil { | ||||
| return types.UploadedPartInfo{}, err | |||||
| return stgtypes.UploadedPartInfo{}, err | |||||
| } | } | ||||
| defer partFile.Close() | defer partFile.Close() | ||||
| _, err = io.Copy(partFile, stream) | _, err = io.Copy(partFile, stream) | ||||
| if err != nil { | if err != nil { | ||||
| return types.UploadedPartInfo{}, err | |||||
| return stgtypes.UploadedPartInfo{}, err | |||||
| } | } | ||||
| return types.UploadedPartInfo{ | |||||
| return stgtypes.UploadedPartInfo{ | |||||
| ETag: partFilePath, | ETag: partFilePath, | ||||
| PartNumber: partNumber, | PartNumber: partNumber, | ||||
| }, nil | }, nil | ||||
| @@ -84,20 +84,20 @@ type MultipartTask struct { | |||||
| uploadID string | uploadID string | ||||
| } | } | ||||
| func (i *MultipartTask) InitState() types.MultipartInitState { | |||||
| return types.MultipartInitState{ | |||||
| func (i *MultipartTask) InitState() stgtypes.MultipartInitState { | |||||
| return stgtypes.MultipartInitState{ | |||||
| UploadID: i.uploadID, | UploadID: i.uploadID, | ||||
| } | } | ||||
| } | } | ||||
| func (i *MultipartTask) JoinParts(ctx context.Context, parts []types.UploadedPartInfo) (types.FileInfo, error) { | |||||
| parts = sort2.Sort(parts, func(l, r types.UploadedPartInfo) int { | |||||
| func (i *MultipartTask) JoinParts(ctx context.Context, parts []stgtypes.UploadedPartInfo) (stgtypes.FileInfo, error) { | |||||
| parts = sort2.Sort(parts, func(l, r stgtypes.UploadedPartInfo) int { | |||||
| return l.PartNumber - r.PartNumber | return l.PartNumber - r.PartNumber | ||||
| }) | }) | ||||
| joined, err := os.Create(i.absJoinedFilePath) | joined, err := os.Create(i.absJoinedFilePath) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| defer joined.Close() | defer joined.Close() | ||||
| @@ -107,21 +107,21 @@ func (i *MultipartTask) JoinParts(ctx context.Context, parts []types.UploadedPar | |||||
| for _, part := range parts { | for _, part := range parts { | ||||
| partSize, err := i.writePart(part, joined, hasher) | partSize, err := i.writePart(part, joined, hasher) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| size += partSize | size += partSize | ||||
| } | } | ||||
| h := hasher.Sum(nil) | h := hasher.Sum(nil) | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Path: i.joinedFileJPath, | Path: i.joinedFileJPath, | ||||
| Size: size, | Size: size, | ||||
| Hash: jcstypes.NewFullHash(h), | Hash: jcstypes.NewFullHash(h), | ||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (i *MultipartTask) writePart(partInfo types.UploadedPartInfo, joined *os.File, hasher hash.Hash) (int64, error) { | |||||
| func (i *MultipartTask) writePart(partInfo stgtypes.UploadedPartInfo, joined *os.File, hasher hash.Hash) (int64, error) { | |||||
| part, err := os.Open(partInfo.ETag) | part, err := os.Open(partInfo.ETag) | ||||
| if err != nil { | if err != nil { | ||||
| return 0, err | return 0, err | ||||
| @@ -6,7 +6,7 @@ import ( | |||||
| "os" | "os" | ||||
| "path/filepath" | "path/filepath" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -19,7 +19,7 @@ type S2STransfer struct { | |||||
| // 只有同一个机器的存储之间才可以进行数据直传 | // 只有同一个机器的存储之间才可以进行数据直传 | ||||
| func (*S2STransfer) CanTransfer(src, dst *jcstypes.UserSpaceDetail) bool { | func (*S2STransfer) CanTransfer(src, dst *jcstypes.UserSpaceDetail) bool { | ||||
| if types.FindFeature[*jcstypes.S2STransferFeature](dst) == nil { | |||||
| if stgtypes.FindFeature[*jcstypes.S2STransferFeature](dst) == nil { | |||||
| return false | return false | ||||
| } | } | ||||
| @@ -36,27 +36,27 @@ func (*S2STransfer) CanTransfer(src, dst *jcstypes.UserSpaceDetail) bool { | |||||
| } | } | ||||
| // 执行数据直传 | // 执行数据直传 | ||||
| func (s *S2STransfer) Transfer(ctx context.Context, src *jcstypes.UserSpaceDetail, srcPath jcstypes.JPath, dstPath jcstypes.JPath) (types.FileInfo, error) { | |||||
| func (s *S2STransfer) Transfer(ctx context.Context, src *jcstypes.UserSpaceDetail, srcPath jcstypes.JPath, dstPath jcstypes.JPath) (stgtypes.FileInfo, error) { | |||||
| s.dstPath = dstPath | s.dstPath = dstPath | ||||
| copy, err := os.OpenFile(filepath.Join(s.localStg.RootDir, s.dstPath.JoinOSPath()), os.O_WRONLY|os.O_CREATE, 0644) | copy, err := os.OpenFile(filepath.Join(s.localStg.RootDir, s.dstPath.JoinOSPath()), os.O_WRONLY|os.O_CREATE, 0644) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| defer copy.Close() | defer copy.Close() | ||||
| srcFile, err := os.Open(filepath.Join(s.localStg.RootDir, srcPath.JoinOSPath())) | srcFile, err := os.Open(filepath.Join(s.localStg.RootDir, srcPath.JoinOSPath())) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| defer srcFile.Close() | defer srcFile.Close() | ||||
| n, err := io.Copy(copy, srcFile) | n, err := io.Copy(copy, srcFile) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Path: dstPath, | Path: dstPath, | ||||
| Size: n, | Size: n, | ||||
| Hash: "", | Hash: "", | ||||
| @@ -9,7 +9,7 @@ import ( | |||||
| "sync" | "sync" | ||||
| "gitlink.org.cn/cloudream/common/pkgs/logger" | "gitlink.org.cn/cloudream/common/pkgs/logger" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -22,7 +22,7 @@ type ShardStore struct { | |||||
| } | } | ||||
| func NewShardStore(root string, detail *jcstypes.UserSpaceDetail) (*ShardStore, error) { | func NewShardStore(root string, detail *jcstypes.UserSpaceDetail) (*ShardStore, error) { | ||||
| storeAbsRoot, err := filepath.Abs(filepath.Join(root, detail.UserSpace.WorkingDir.JoinOSPath(), types.ShardStoreWorkingDir)) | |||||
| storeAbsRoot, err := filepath.Abs(filepath.Join(root, detail.UserSpace.WorkingDir.JoinOSPath(), stgtypes.ShardStoreWorkingDir)) | |||||
| if err != nil { | if err != nil { | ||||
| return nil, fmt.Errorf("get abs root: %w", err) | return nil, fmt.Errorf("get abs root: %w", err) | ||||
| } | } | ||||
| @@ -35,7 +35,7 @@ func NewShardStore(root string, detail *jcstypes.UserSpaceDetail) (*ShardStore, | |||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *ShardStore) Start(ch *types.StorageEventChan) { | |||||
| func (s *ShardStore) Start(ch *stgtypes.StorageEventChan) { | |||||
| s.getLogger().Infof("component start, root: %v, max size: %v", s.storeAbsRoot, s.detail.UserSpace.ShardStore.MaxSize) | s.getLogger().Infof("component start, root: %v, max size: %v", s.storeAbsRoot, s.detail.UserSpace.ShardStore.MaxSize) | ||||
| } | } | ||||
| @@ -43,7 +43,7 @@ func (s *ShardStore) Stop() { | |||||
| s.getLogger().Infof("component stop") | s.getLogger().Infof("component stop") | ||||
| } | } | ||||
| func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int64) (types.FileInfo, error) { | |||||
| func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int64) (stgtypes.FileInfo, error) { | |||||
| fullTempPath := filepath.Join(s.stgRoot, path.JoinOSPath()) | fullTempPath := filepath.Join(s.stgRoot, path.JoinOSPath()) | ||||
| s.lock.Lock() | s.lock.Lock() | ||||
| @@ -57,7 +57,7 @@ func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int | |||||
| err := os.MkdirAll(blockDir, 0755) | err := os.MkdirAll(blockDir, 0755) | ||||
| if err != nil { | if err != nil { | ||||
| log.Warnf("make block dir %v: %v", blockDir, err) | log.Warnf("make block dir %v: %v", blockDir, err) | ||||
| return types.FileInfo{}, fmt.Errorf("making block dir: %w", err) | |||||
| return stgtypes.FileInfo{}, fmt.Errorf("making block dir: %w", err) | |||||
| } | } | ||||
| newPath := filepath.Join(blockDir, string(hash)) | newPath := filepath.Join(blockDir, string(hash)) | ||||
| @@ -66,43 +66,43 @@ func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int | |||||
| err = os.Rename(fullTempPath, newPath) | err = os.Rename(fullTempPath, newPath) | ||||
| if err != nil { | if err != nil { | ||||
| log.Warnf("rename %v to %v: %v", fullTempPath, newPath, err) | log.Warnf("rename %v to %v: %v", fullTempPath, newPath, err) | ||||
| return types.FileInfo{}, fmt.Errorf("rename file: %w", err) | |||||
| return stgtypes.FileInfo{}, fmt.Errorf("rename file: %w", err) | |||||
| } | } | ||||
| } else if err != nil { | } else if err != nil { | ||||
| log.Warnf("get file %v stat: %v", newPath, err) | log.Warnf("get file %v stat: %v", newPath, err) | ||||
| return types.FileInfo{}, fmt.Errorf("get file stat: %w", err) | |||||
| return stgtypes.FileInfo{}, fmt.Errorf("get file stat: %w", err) | |||||
| } | } | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Hash: hash, | Hash: hash, | ||||
| Size: size, | Size: size, | ||||
| Path: s.getJPathFromHash(hash), | Path: s.getJPathFromHash(hash), | ||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *ShardStore) Info(hash jcstypes.FileHash) (types.FileInfo, error) { | |||||
| func (s *ShardStore) Info(hash jcstypes.FileHash) (stgtypes.FileInfo, error) { | |||||
| s.lock.Lock() | s.lock.Lock() | ||||
| defer s.lock.Unlock() | defer s.lock.Unlock() | ||||
| filePath := s.getFilePathFromHash(hash) | filePath := s.getFilePathFromHash(hash) | ||||
| info, err := os.Stat(filePath) | info, err := os.Stat(filePath) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Hash: hash, | Hash: hash, | ||||
| Size: info.Size(), | Size: info.Size(), | ||||
| Path: s.getJPathFromHash(hash), | Path: s.getJPathFromHash(hash), | ||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *ShardStore) ListAll() ([]types.FileInfo, error) { | |||||
| func (s *ShardStore) ListAll() ([]stgtypes.FileInfo, error) { | |||||
| s.lock.Lock() | s.lock.Lock() | ||||
| defer s.lock.Unlock() | defer s.lock.Unlock() | ||||
| var infos []types.FileInfo | |||||
| var infos []stgtypes.FileInfo | |||||
| err := filepath.WalkDir(s.storeAbsRoot, func(path string, d fs.DirEntry, err error) error { | err := filepath.WalkDir(s.storeAbsRoot, func(path string, d fs.DirEntry, err error) error { | ||||
| if err != nil { | if err != nil { | ||||
| @@ -123,7 +123,7 @@ func (s *ShardStore) ListAll() ([]types.FileInfo, error) { | |||||
| return nil | return nil | ||||
| } | } | ||||
| infos = append(infos, types.FileInfo{ | |||||
| infos = append(infos, stgtypes.FileInfo{ | |||||
| Hash: fileHash, | Hash: fileHash, | ||||
| Size: info.Size(), | Size: info.Size(), | ||||
| Path: s.getJPathFromHash(fileHash), | Path: s.getJPathFromHash(fileHash), | ||||
| @@ -188,10 +188,10 @@ func (s *ShardStore) GC(avaiables []jcstypes.FileHash) error { | |||||
| return nil | return nil | ||||
| } | } | ||||
| func (s *ShardStore) Stats() types.Stats { | |||||
| func (s *ShardStore) Stats() stgtypes.Stats { | |||||
| // TODO 统计本地存储的相关信息 | // TODO 统计本地存储的相关信息 | ||||
| return types.Stats{ | |||||
| Status: types.StatusOK, | |||||
| return stgtypes.Stats{ | |||||
| Status: stgtypes.StatusOK, | |||||
| } | } | ||||
| } | } | ||||
| @@ -208,5 +208,5 @@ func (s *ShardStore) getFilePathFromHash(hash jcstypes.FileHash) string { | |||||
| } | } | ||||
| func (s *ShardStore) getJPathFromHash(hash jcstypes.FileHash) jcstypes.JPath { | func (s *ShardStore) getJPathFromHash(hash jcstypes.FileHash) jcstypes.JPath { | ||||
| return s.detail.UserSpace.WorkingDir.ConcatCompsNew(types.ShardStoreWorkingDir, hash.GetHashPrefix(2), string(hash)) | |||||
| return s.detail.UserSpace.WorkingDir.ConcatCompsNew(stgtypes.ShardStoreWorkingDir, hash.GetHashPrefix(2), string(hash)) | |||||
| } | } | ||||
| @@ -8,7 +8,7 @@ import ( | |||||
| "github.com/aws/aws-sdk-go-v2/service/s3" | "github.com/aws/aws-sdk-go-v2/service/s3" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | ||||
| s3stg "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/s3" | s3stg "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/s3" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -17,21 +17,21 @@ func init() { | |||||
| } | } | ||||
| type builder struct { | type builder struct { | ||||
| types.EmptyBuilder | |||||
| stgtypes.EmptyBuilder | |||||
| detail *jcstypes.UserSpaceDetail | detail *jcstypes.UserSpaceDetail | ||||
| } | } | ||||
| func newBuilder(detail *jcstypes.UserSpaceDetail) types.StorageBuilder { | |||||
| func newBuilder(detail *jcstypes.UserSpaceDetail) stgtypes.StorageBuilder { | |||||
| return &builder{ | return &builder{ | ||||
| detail: detail, | detail: detail, | ||||
| } | } | ||||
| } | } | ||||
| func (b *builder) FeatureDesc() types.FeatureDesc { | |||||
| return types.FeatureDesc{} | |||||
| func (b *builder) FeatureDesc() stgtypes.FeatureDesc { | |||||
| return stgtypes.FeatureDesc{} | |||||
| } | } | ||||
| func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | |||||
| func (b *builder) CreateShardStore(typeOnly bool) (stgtypes.ShardStore, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*jcstypes.OBSType) | stgType := b.detail.UserSpace.Storage.(*jcstypes.OBSType) | ||||
| cred, ok := b.detail.UserSpace.Credential.(*jcstypes.OBSCred) | cred, ok := b.detail.UserSpace.Credential.(*jcstypes.OBSCred) | ||||
| if !ok { | if !ok { | ||||
| @@ -50,7 +50,7 @@ func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | |||||
| return NewShardStore(b.detail, stgType, cred, cli, bucket) | return NewShardStore(b.detail, stgType, cred, cli, bucket) | ||||
| } | } | ||||
| func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | |||||
| func (b *builder) CreateBaseStore(typeOnly bool) (stgtypes.BaseStore, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*jcstypes.OBSType) | stgType := b.detail.UserSpace.Storage.(*jcstypes.OBSType) | ||||
| cred, ok := b.detail.UserSpace.Credential.(*jcstypes.OBSCred) | cred, ok := b.detail.UserSpace.Credential.(*jcstypes.OBSCred) | ||||
| if !ok { | if !ok { | ||||
| @@ -89,9 +89,9 @@ func createClient(stgType *jcstypes.OBSType, cred *jcstypes.OBSCred) (*s3.Client | |||||
| return cli, stgType.Bucket, nil | return cli, stgType.Bucket, nil | ||||
| } | } | ||||
| func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | |||||
| func (b *builder) CreateMultiparter(typeOnly bool) (stgtypes.Multiparter, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*jcstypes.OBSType) | stgType := b.detail.UserSpace.Storage.(*jcstypes.OBSType) | ||||
| feat := types.FindFeature[*jcstypes.MultipartUploadFeature](b.detail) | |||||
| feat := stgtypes.FindFeature[*jcstypes.MultipartUploadFeature](b.detail) | |||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature %T not found", jcstypes.MultipartUploadFeature{}) | return nil, fmt.Errorf("feature %T not found", jcstypes.MultipartUploadFeature{}) | ||||
| } | } | ||||
| @@ -118,9 +118,9 @@ func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | |||||
| ), nil | ), nil | ||||
| } | } | ||||
| func (b *builder) CreateS2STransfer(typeOnly bool) (types.S2STransfer, error) { | |||||
| func (b *builder) CreateS2STransfer(typeOnly bool) (stgtypes.S2STransfer, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*jcstypes.OBSType) | stgType := b.detail.UserSpace.Storage.(*jcstypes.OBSType) | ||||
| feat := types.FindFeature[*jcstypes.S2STransferFeature](b.detail) | |||||
| feat := stgtypes.FindFeature[*jcstypes.S2STransferFeature](b.detail) | |||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature %T not found", jcstypes.S2STransferFeature{}) | return nil, fmt.Errorf("feature %T not found", jcstypes.S2STransferFeature{}) | ||||
| } | } | ||||
| @@ -14,7 +14,7 @@ import ( | |||||
| omsregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2/region" | omsregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2/region" | ||||
| "gitlink.org.cn/cloudream/common/utils/os2" | "gitlink.org.cn/cloudream/common/utils/os2" | ||||
| stgs3 "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/s3" | stgs3 "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/s3" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -43,10 +43,10 @@ func (*S2STransfer) CanTransfer(src, dst *jcstypes.UserSpaceDetail) bool { | |||||
| } | } | ||||
| // 执行数据直传。返回传输后的文件路径 | // 执行数据直传。返回传输后的文件路径 | ||||
| func (s *S2STransfer) Transfer(ctx context.Context, src *jcstypes.UserSpaceDetail, srcPath jcstypes.JPath, dstPath jcstypes.JPath) (types.FileInfo, error) { | |||||
| func (s *S2STransfer) Transfer(ctx context.Context, src *jcstypes.UserSpaceDetail, srcPath jcstypes.JPath, dstPath jcstypes.JPath) (stgtypes.FileInfo, error) { | |||||
| req := makeRequest(src, srcPath) | req := makeRequest(src, srcPath) | ||||
| if req == nil { | if req == nil { | ||||
| return types.FileInfo{}, fmt.Errorf("unsupported source storage type: %T", src.UserSpace.Storage) | |||||
| return stgtypes.FileInfo{}, fmt.Errorf("unsupported source storage type: %T", src.UserSpace.Storage) | |||||
| } | } | ||||
| auth, err := basic.NewCredentialsBuilder(). | auth, err := basic.NewCredentialsBuilder(). | ||||
| @@ -55,12 +55,12 @@ func (s *S2STransfer) Transfer(ctx context.Context, src *jcstypes.UserSpaceDetai | |||||
| WithProjectId(s.stgType.ProjectID). | WithProjectId(s.stgType.ProjectID). | ||||
| SafeBuild() | SafeBuild() | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| region, err := omsregion.SafeValueOf(s.stgType.Region) | region, err := omsregion.SafeValueOf(s.stgType.Region) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| cli, err := oms.OmsClientBuilder(). | cli, err := oms.OmsClientBuilder(). | ||||
| @@ -68,11 +68,11 @@ func (s *S2STransfer) Transfer(ctx context.Context, src *jcstypes.UserSpaceDetai | |||||
| WithCredential(auth). | WithCredential(auth). | ||||
| SafeBuild() | SafeBuild() | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| // 先上传成一个临时文件 | // 先上传成一个临时文件 | ||||
| tempDir := stgs3.JoinKey(s.detail.UserSpace.WorkingDir.String(), types.TempWorkingDir) | |||||
| tempDir := stgs3.JoinKey(s.detail.UserSpace.WorkingDir.String(), stgtypes.TempWorkingDir) | |||||
| tempPrefix := stgs3.JoinKey(tempDir, os2.GenerateRandomFileName(10)) + "/" | tempPrefix := stgs3.JoinKey(tempDir, os2.GenerateRandomFileName(10)) + "/" | ||||
| taskType := model.GetCreateTaskReqTaskTypeEnum().OBJECT | taskType := model.GetCreateTaskReqTaskTypeEnum().OBJECT | ||||
| @@ -91,7 +91,7 @@ func (s *S2STransfer) Transfer(ctx context.Context, src *jcstypes.UserSpaceDetai | |||||
| }, | }, | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, fmt.Errorf("create task: %w", err) | |||||
| return stgtypes.FileInfo{}, fmt.Errorf("create task: %w", err) | |||||
| } | } | ||||
| s.taskID = resp.Id | s.taskID = resp.Id | ||||
| @@ -99,13 +99,13 @@ func (s *S2STransfer) Transfer(ctx context.Context, src *jcstypes.UserSpaceDetai | |||||
| // 轮询任务状态,直到完成 | // 轮询任务状态,直到完成 | ||||
| size, err := s.waitTask(ctx, *resp.Id) | size, err := s.waitTask(ctx, *resp.Id) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, fmt.Errorf("wait task: %w", err) | |||||
| return stgtypes.FileInfo{}, fmt.Errorf("wait task: %w", err) | |||||
| } | } | ||||
| // 传输完成后,将文件名改成目标路径 | // 传输完成后,将文件名改成目标路径 | ||||
| obsCli, bkt, err := createClient(s.stgType, s.cred) | obsCli, bkt, err := createClient(s.stgType, s.cred) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| _, err = obsCli.CopyObject(ctx, &awss3.CopyObjectInput{ | _, err = obsCli.CopyObject(ctx, &awss3.CopyObjectInput{ | ||||
| @@ -114,10 +114,10 @@ func (s *S2STransfer) Transfer(ctx context.Context, src *jcstypes.UserSpaceDetai | |||||
| Key: aws.String(dstPath.String()), | Key: aws.String(dstPath.String()), | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, fmt.Errorf("copy object: %w", err) | |||||
| return stgtypes.FileInfo{}, fmt.Errorf("copy object: %w", err) | |||||
| } | } | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Path: dstPath, | Path: dstPath, | ||||
| Size: size, | Size: size, | ||||
| Hash: "", | Hash: "", | ||||
| @@ -4,7 +4,7 @@ import ( | |||||
| awss3 "github.com/aws/aws-sdk-go-v2/service/s3" | awss3 "github.com/aws/aws-sdk-go-v2/service/s3" | ||||
| "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" | "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/s3" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/s3" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -31,10 +31,10 @@ func NewShardStore(detail *jcstypes.UserSpaceDetail, stgType *jcstypes.OBSType, | |||||
| return &sd, nil | return &sd, nil | ||||
| } | } | ||||
| func (s *ShardStore) MakeHTTPReadRequest(fileHash jcstypes.FileHash) (types.HTTPRequest, error) { | |||||
| func (s *ShardStore) MakeHTTPReadRequest(fileHash jcstypes.FileHash) (stgtypes.HTTPRequest, error) { | |||||
| cli, err := obs.New(s.cred.AK, s.cred.SK, s.stgType.Endpoint) | cli, err := obs.New(s.cred.AK, s.cred.SK, s.stgType.Endpoint) | ||||
| if err != nil { | if err != nil { | ||||
| return types.HTTPRequest{}, err | |||||
| return stgtypes.HTTPRequest{}, err | |||||
| } | } | ||||
| filePath := s.GetFilePathFromHash(fileHash) | filePath := s.GetFilePathFromHash(fileHash) | ||||
| @@ -45,10 +45,10 @@ func (s *ShardStore) MakeHTTPReadRequest(fileHash jcstypes.FileHash) (types.HTTP | |||||
| Expires: 3600, | Expires: 3600, | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| return types.HTTPRequest{}, err | |||||
| return stgtypes.HTTPRequest{}, err | |||||
| } | } | ||||
| return types.HTTPRequest{ | |||||
| return stgtypes.HTTPRequest{ | |||||
| URL: getSigned.SignedUrl, | URL: getSigned.SignedUrl, | ||||
| Method: "GET", | Method: "GET", | ||||
| }, nil | }, nil | ||||
| @@ -5,13 +5,13 @@ import ( | |||||
| "gitlink.org.cn/cloudream/common/pkgs/async" | "gitlink.org.cn/cloudream/common/pkgs/async" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| type userSpace struct { | type userSpace struct { | ||||
| detail *jcstypes.UserSpaceDetail | detail *jcstypes.UserSpaceDetail | ||||
| store types.ShardStore | |||||
| store stgtypes.ShardStore | |||||
| } | } | ||||
| func (u *userSpace) Drop() { | func (u *userSpace) Drop() { | ||||
| @@ -29,13 +29,13 @@ type userSpaceKey struct { | |||||
| type Pool struct { | type Pool struct { | ||||
| spaces map[userSpaceKey]*userSpace | spaces map[userSpaceKey]*userSpace | ||||
| lock sync.Mutex | lock sync.Mutex | ||||
| eventChan *types.StorageEventChan | |||||
| eventChan *stgtypes.StorageEventChan | |||||
| } | } | ||||
| func NewPool() *Pool { | func NewPool() *Pool { | ||||
| return &Pool{ | return &Pool{ | ||||
| spaces: make(map[userSpaceKey]*userSpace), | spaces: make(map[userSpaceKey]*userSpace), | ||||
| eventChan: async.NewUnboundChannel[types.StorageEvent](), | |||||
| eventChan: async.NewUnboundChannel[stgtypes.StorageEvent](), | |||||
| } | } | ||||
| } | } | ||||
| @@ -55,7 +55,7 @@ func (p *Pool) Drop(userID jcstypes.UserID, spaceID jcstypes.UserSpaceID) { | |||||
| delete(p.spaces, key) | delete(p.spaces, key) | ||||
| } | } | ||||
| func (p *Pool) GetShardStore(spaceDetail *jcstypes.UserSpaceDetail) (types.ShardStore, error) { | |||||
| func (p *Pool) GetShardStore(spaceDetail *jcstypes.UserSpaceDetail) (stgtypes.ShardStore, error) { | |||||
| p.lock.Lock() | p.lock.Lock() | ||||
| defer p.lock.Unlock() | defer p.lock.Unlock() | ||||
| @@ -90,18 +90,18 @@ func (p *Pool) GetShardStore(spaceDetail *jcstypes.UserSpaceDetail) (types.Shard | |||||
| return space.store, nil | return space.store, nil | ||||
| } | } | ||||
| func (p *Pool) GetBaseStore(spaceDetail *jcstypes.UserSpaceDetail) (types.BaseStore, error) { | |||||
| func (p *Pool) GetBaseStore(spaceDetail *jcstypes.UserSpaceDetail) (stgtypes.BaseStore, error) { | |||||
| return factory.GetBuilder(spaceDetail).CreateBaseStore(false) | return factory.GetBuilder(spaceDetail).CreateBaseStore(false) | ||||
| } | } | ||||
| func (p *Pool) GetMultiparter(spaceDetail *jcstypes.UserSpaceDetail) (types.Multiparter, error) { | |||||
| func (p *Pool) GetMultiparter(spaceDetail *jcstypes.UserSpaceDetail) (stgtypes.Multiparter, error) { | |||||
| return factory.GetBuilder(spaceDetail).CreateMultiparter(false) | return factory.GetBuilder(spaceDetail).CreateMultiparter(false) | ||||
| } | } | ||||
| func (p *Pool) GetS2STransfer(spaceDetail *jcstypes.UserSpaceDetail) (types.S2STransfer, error) { | |||||
| func (p *Pool) GetS2STransfer(spaceDetail *jcstypes.UserSpaceDetail) (stgtypes.S2STransfer, error) { | |||||
| return factory.GetBuilder(spaceDetail).CreateS2STransfer(false) | return factory.GetBuilder(spaceDetail).CreateS2STransfer(false) | ||||
| } | } | ||||
| func (p *Pool) GetECMultiplier(spaceDetail *jcstypes.UserSpaceDetail) (types.ECMultiplier, error) { | |||||
| func (p *Pool) GetECMultiplier(spaceDetail *jcstypes.UserSpaceDetail) (stgtypes.ECMultiplier, error) { | |||||
| return factory.GetBuilder(spaceDetail).CreateECMultiplier(false) | return factory.GetBuilder(spaceDetail).CreateECMultiplier(false) | ||||
| } | } | ||||
| @@ -2,7 +2,7 @@ package pubshards | |||||
| import ( | import ( | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -11,21 +11,21 @@ func init() { | |||||
| } | } | ||||
| type builder struct { | type builder struct { | ||||
| types.EmptyBuilder | |||||
| stgtypes.EmptyBuilder | |||||
| detail *jcstypes.UserSpaceDetail | detail *jcstypes.UserSpaceDetail | ||||
| } | } | ||||
| func newBuilder(detail *jcstypes.UserSpaceDetail) types.StorageBuilder { | |||||
| func newBuilder(detail *jcstypes.UserSpaceDetail) stgtypes.StorageBuilder { | |||||
| return &builder{ | return &builder{ | ||||
| detail: detail, | detail: detail, | ||||
| } | } | ||||
| } | } | ||||
| func (b *builder) FeatureDesc() types.FeatureDesc { | |||||
| return types.FeatureDesc{} | |||||
| func (b *builder) FeatureDesc() stgtypes.FeatureDesc { | |||||
| return stgtypes.FeatureDesc{} | |||||
| } | } | ||||
| func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | |||||
| func (b *builder) CreateShardStore(typeOnly bool) (stgtypes.ShardStore, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*jcstypes.PubShardsType) | stgType := b.detail.UserSpace.Storage.(*jcstypes.PubShardsType) | ||||
| if typeOnly { | if typeOnly { | ||||
| @@ -35,7 +35,7 @@ func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | |||||
| return NewShardStore(b.detail, stgType) | return NewShardStore(b.detail, stgType) | ||||
| } | } | ||||
| func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | |||||
| func (b *builder) CreateBaseStore(typeOnly bool) (stgtypes.BaseStore, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*jcstypes.PubShardsType) | stgType := b.detail.UserSpace.Storage.(*jcstypes.PubShardsType) | ||||
| newDeatil := jcstypes.UserSpaceDetail{ | newDeatil := jcstypes.UserSpaceDetail{ | ||||
| UserID: b.detail.UserID, | UserID: b.detail.UserID, | ||||
| @@ -6,7 +6,7 @@ import ( | |||||
| stgglb "gitlink.org.cn/cloudream/jcs-pub/common/globals" | stgglb "gitlink.org.cn/cloudream/jcs-pub/common/globals" | ||||
| hubrpc "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc/hub" | hubrpc "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc/hub" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -27,7 +27,7 @@ func NewShardStore(detail *jcstypes.UserSpaceDetail, stgType *jcstypes.PubShards | |||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *ShardStore) Start(ch *types.StorageEventChan) { | |||||
| func (s *ShardStore) Start(ch *stgtypes.StorageEventChan) { | |||||
| s.hubCli = stgglb.HubRPCPool.GetByID(s.stgType.MasterHub) | s.hubCli = stgglb.HubRPCPool.GetByID(s.stgType.MasterHub) | ||||
| } | } | ||||
| @@ -38,7 +38,7 @@ func (s *ShardStore) Stop() { | |||||
| } | } | ||||
| } | } | ||||
| func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int64) (types.FileInfo, error) { | |||||
| func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int64) (stgtypes.FileInfo, error) { | |||||
| resp, cerr := s.hubCli.PubShardsStore(context.Background(), &hubrpc.PubShardsStore{ | resp, cerr := s.hubCli.PubShardsStore(context.Background(), &hubrpc.PubShardsStore{ | ||||
| PubShardsID: s.stgType.PubShardsID, | PubShardsID: s.stgType.PubShardsID, | ||||
| Password: s.stgType.Password, | Password: s.stgType.Password, | ||||
| @@ -47,25 +47,25 @@ func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int | |||||
| Size: size, | Size: size, | ||||
| }) | }) | ||||
| if cerr != nil { | if cerr != nil { | ||||
| return types.FileInfo{}, cerr.ToError() | |||||
| return stgtypes.FileInfo{}, cerr.ToError() | |||||
| } | } | ||||
| return resp.Info, nil | return resp.Info, nil | ||||
| } | } | ||||
| func (s *ShardStore) Info(hash jcstypes.FileHash) (types.FileInfo, error) { | |||||
| func (s *ShardStore) Info(hash jcstypes.FileHash) (stgtypes.FileInfo, error) { | |||||
| resp, cerr := s.hubCli.PubShardsInfo(context.Background(), &hubrpc.PubShardsInfo{ | resp, cerr := s.hubCli.PubShardsInfo(context.Background(), &hubrpc.PubShardsInfo{ | ||||
| PubShardsID: s.stgType.PubShardsID, | PubShardsID: s.stgType.PubShardsID, | ||||
| Password: s.stgType.Password, | Password: s.stgType.Password, | ||||
| FileHash: hash, | FileHash: hash, | ||||
| }) | }) | ||||
| if cerr != nil { | if cerr != nil { | ||||
| return types.FileInfo{}, cerr.ToError() | |||||
| return stgtypes.FileInfo{}, cerr.ToError() | |||||
| } | } | ||||
| return resp.Info, nil | return resp.Info, nil | ||||
| } | } | ||||
| func (s *ShardStore) ListAll() ([]types.FileInfo, error) { | |||||
| func (s *ShardStore) ListAll() ([]stgtypes.FileInfo, error) { | |||||
| resp, cerr := s.hubCli.PubShardsListAll(context.Background(), &hubrpc.PubShardsListAll{ | resp, cerr := s.hubCli.PubShardsListAll(context.Background(), &hubrpc.PubShardsListAll{ | ||||
| PubShardsID: s.stgType.PubShardsID, | PubShardsID: s.stgType.PubShardsID, | ||||
| Password: s.stgType.Password, | Password: s.stgType.Password, | ||||
| @@ -88,13 +88,13 @@ func (s *ShardStore) GC(avaiables []jcstypes.FileHash) error { | |||||
| return nil | return nil | ||||
| } | } | ||||
| func (s *ShardStore) Stats() types.Stats { | |||||
| func (s *ShardStore) Stats() stgtypes.Stats { | |||||
| resp, cerr := s.hubCli.PubShardsStats(context.Background(), &hubrpc.PubShardsStats{ | resp, cerr := s.hubCli.PubShardsStats(context.Background(), &hubrpc.PubShardsStats{ | ||||
| PubShardsID: s.stgType.PubShardsID, | PubShardsID: s.stgType.PubShardsID, | ||||
| Password: s.stgType.Password, | Password: s.stgType.Password, | ||||
| }) | }) | ||||
| if cerr != nil { | if cerr != nil { | ||||
| return types.Stats{} | |||||
| return stgtypes.Stats{} | |||||
| } | } | ||||
| return resp.Stats | return resp.Stats | ||||
| } | } | ||||
| @@ -15,7 +15,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/common/pkgs/logger" | "gitlink.org.cn/cloudream/common/pkgs/logger" | ||||
| "gitlink.org.cn/cloudream/common/utils/io2" | "gitlink.org.cn/cloudream/common/utils/io2" | ||||
| "gitlink.org.cn/cloudream/common/utils/math2" | "gitlink.org.cn/cloudream/common/utils/math2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -43,7 +43,7 @@ func NewBaseStore(detail *jcstypes.UserSpaceDetail, cli *s3.Client, bkt string, | |||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *BaseStore) Write(pat jcstypes.JPath, stream io.Reader, opt types.WriteOption) (types.FileInfo, error) { | |||||
| func (s *BaseStore) Write(pat jcstypes.JPath, stream io.Reader, opt stgtypes.WriteOption) (stgtypes.FileInfo, error) { | |||||
| key := pat | key := pat | ||||
| meta := make(map[string]string) | meta := make(map[string]string) | ||||
| if opt.ModTime.IsZero() { | if opt.ModTime.IsZero() { | ||||
| @@ -52,7 +52,7 @@ func (s *BaseStore) Write(pat jcstypes.JPath, stream io.Reader, opt types.WriteO | |||||
| } else { | } else { | ||||
| mt, err := opt.ModTime.MarshalText() | mt, err := opt.ModTime.MarshalText() | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| meta[ModTimeHeader] = string(mt) | meta[ModTimeHeader] = string(mt) | ||||
| } | } | ||||
| @@ -68,18 +68,18 @@ func (s *BaseStore) Write(pat jcstypes.JPath, stream io.Reader, opt types.WriteO | |||||
| Metadata: meta, | Metadata: meta, | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| if resp.ChecksumSHA256 == nil { | if resp.ChecksumSHA256 == nil { | ||||
| return types.FileInfo{}, errors.New("SHA256 checksum not found in response") | |||||
| return stgtypes.FileInfo{}, errors.New("SHA256 checksum not found in response") | |||||
| } | } | ||||
| hash, err := DecodeBase64Hash(*resp.ChecksumSHA256) | hash, err := DecodeBase64Hash(*resp.ChecksumSHA256) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, fmt.Errorf("decode SHA256 checksum: %v", err) | |||||
| return stgtypes.FileInfo{}, fmt.Errorf("decode SHA256 checksum: %v", err) | |||||
| } | } | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Path: key, | Path: key, | ||||
| Hash: jcstypes.NewFullHash(hash), | Hash: jcstypes.NewFullHash(hash), | ||||
| Size: counter.Count(), | Size: counter.Count(), | ||||
| @@ -94,17 +94,17 @@ func (s *BaseStore) Write(pat jcstypes.JPath, stream io.Reader, opt types.WriteO | |||||
| Metadata: meta, | Metadata: meta, | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Path: key, | Path: key, | ||||
| Hash: jcstypes.NewFullHash(hashStr.Sum()), | Hash: jcstypes.NewFullHash(hashStr.Sum()), | ||||
| Size: counter.Count(), | Size: counter.Count(), | ||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *BaseStore) Read(pat jcstypes.JPath, opt types.OpenOption) (io.ReadCloser, error) { | |||||
| func (s *BaseStore) Read(pat jcstypes.JPath, opt stgtypes.OpenOption) (io.ReadCloser, error) { | |||||
| key := pat | key := pat | ||||
| input := &s3.GetObjectInput{ | input := &s3.GetObjectInput{ | ||||
| @@ -137,7 +137,7 @@ func (s *BaseStore) Mkdir(path jcstypes.JPath) error { | |||||
| return err | return err | ||||
| } | } | ||||
| func (s *BaseStore) ReadDir(path jcstypes.JPath) types.DirReader { | |||||
| func (s *BaseStore) ReadDir(path jcstypes.JPath) stgtypes.DirReader { | |||||
| return &DirReader{ | return &DirReader{ | ||||
| cli: s.cli, | cli: s.cli, | ||||
| bucket: s.Bucket, | bucket: s.Bucket, | ||||
| @@ -154,7 +154,7 @@ func (s *BaseStore) CleanTemps() { | |||||
| for { | for { | ||||
| resp, err := s.cli.ListObjects(context.Background(), &s3.ListObjectsInput{ | resp, err := s.cli.ListObjects(context.Background(), &s3.ListObjectsInput{ | ||||
| Bucket: aws.String(s.Bucket), | Bucket: aws.String(s.Bucket), | ||||
| Prefix: aws.String(JoinKey(s.Detail.UserSpace.WorkingDir.String(), types.TempWorkingDir, "/")), | |||||
| Prefix: aws.String(JoinKey(s.Detail.UserSpace.WorkingDir.String(), stgtypes.TempWorkingDir, "/")), | |||||
| Marker: marker, | Marker: marker, | ||||
| }) | }) | ||||
| @@ -6,7 +6,7 @@ import ( | |||||
| "github.com/aws/aws-sdk-go-v2/aws" | "github.com/aws/aws-sdk-go-v2/aws" | ||||
| "github.com/aws/aws-sdk-go-v2/service/s3" | "github.com/aws/aws-sdk-go-v2/service/s3" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -15,18 +15,18 @@ type DirReader struct { | |||||
| bucket string | bucket string | ||||
| rootPath jcstypes.JPath | rootPath jcstypes.JPath | ||||
| marker *string | marker *string | ||||
| curInfos []types.DirEntry | |||||
| curInfos []stgtypes.DirEntry | |||||
| eof bool | eof bool | ||||
| } | } | ||||
| func (r *DirReader) Next() (types.DirEntry, error) { | |||||
| func (r *DirReader) Next() (stgtypes.DirEntry, error) { | |||||
| if len(r.curInfos) > 0 { | if len(r.curInfos) > 0 { | ||||
| e := r.curInfos[0] | e := r.curInfos[0] | ||||
| r.curInfos = r.curInfos[1:] | r.curInfos = r.curInfos[1:] | ||||
| return e, nil | return e, nil | ||||
| } | } | ||||
| if r.eof { | if r.eof { | ||||
| return types.DirEntry{}, io.EOF | |||||
| return stgtypes.DirEntry{}, io.EOF | |||||
| } | } | ||||
| resp, err := r.cli.ListObjects(context.Background(), &s3.ListObjectsInput{ | resp, err := r.cli.ListObjects(context.Background(), &s3.ListObjectsInput{ | ||||
| @@ -35,13 +35,13 @@ func (r *DirReader) Next() (types.DirEntry, error) { | |||||
| Marker: r.marker, | Marker: r.marker, | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| return types.DirEntry{}, err | |||||
| return stgtypes.DirEntry{}, err | |||||
| } | } | ||||
| for _, obj := range resp.Contents { | for _, obj := range resp.Contents { | ||||
| key := jcstypes.PathFromJcsPathString(*obj.Key) | key := jcstypes.PathFromJcsPathString(*obj.Key) | ||||
| r.curInfos = append(r.curInfos, types.DirEntry{ | |||||
| r.curInfos = append(r.curInfos, stgtypes.DirEntry{ | |||||
| Path: key, | Path: key, | ||||
| Size: *obj.Size, | Size: *obj.Size, | ||||
| ModTime: *obj.LastModified, | ModTime: *obj.LastModified, | ||||
| @@ -11,7 +11,7 @@ import ( | |||||
| "gitlink.org.cn/cloudream/common/utils/io2" | "gitlink.org.cn/cloudream/common/utils/io2" | ||||
| "gitlink.org.cn/cloudream/common/utils/os2" | "gitlink.org.cn/cloudream/common/utils/os2" | ||||
| "gitlink.org.cn/cloudream/common/utils/sort2" | "gitlink.org.cn/cloudream/common/utils/sort2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -39,10 +39,10 @@ func (*Multiparter) MaxPartSize() int64 { | |||||
| return 5 * 1024 * 1024 * 1024 // 5GB | return 5 * 1024 * 1024 * 1024 // 5GB | ||||
| } | } | ||||
| func (m *Multiparter) Initiate(ctx context.Context) (types.MultipartTask, error) { | |||||
| func (m *Multiparter) Initiate(ctx context.Context) (stgtypes.MultipartTask, error) { | |||||
| tempFileName := os2.GenerateRandomFileName(10) | tempFileName := os2.GenerateRandomFileName(10) | ||||
| tempDir := m.detail.UserSpace.WorkingDir.Clone() | tempDir := m.detail.UserSpace.WorkingDir.Clone() | ||||
| tempDir.Push(types.TempWorkingDir) | |||||
| tempDir.Push(stgtypes.TempWorkingDir) | |||||
| tempFilePath := tempDir.Clone() | tempFilePath := tempDir.Clone() | ||||
| tempFilePath.Push(tempFileName) | tempFilePath.Push(tempFileName) | ||||
| @@ -65,7 +65,7 @@ func (m *Multiparter) Initiate(ctx context.Context) (types.MultipartTask, error) | |||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (m *Multiparter) UploadPart(ctx context.Context, init types.MultipartInitState, partSize int64, partNumber int, stream io.Reader) (types.UploadedPartInfo, error) { | |||||
| func (m *Multiparter) UploadPart(ctx context.Context, init stgtypes.MultipartInitState, partSize int64, partNumber int, stream io.Reader) (stgtypes.UploadedPartInfo, error) { | |||||
| hashStr := io2.NewReadHasher(sha256.New(), stream) | hashStr := io2.NewReadHasher(sha256.New(), stream) | ||||
| resp, err := m.cli.UploadPart(ctx, &s3.UploadPartInput{ | resp, err := m.cli.UploadPart(ctx, &s3.UploadPartInput{ | ||||
| Bucket: aws.String(init.Bucket), | Bucket: aws.String(init.Bucket), | ||||
| @@ -75,10 +75,10 @@ func (m *Multiparter) UploadPart(ctx context.Context, init types.MultipartInitSt | |||||
| Body: hashStr, | Body: hashStr, | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| return types.UploadedPartInfo{}, err | |||||
| return stgtypes.UploadedPartInfo{}, err | |||||
| } | } | ||||
| return types.UploadedPartInfo{ | |||||
| return stgtypes.UploadedPartInfo{ | |||||
| ETag: *resp.ETag, | ETag: *resp.ETag, | ||||
| PartNumber: partNumber, | PartNumber: partNumber, | ||||
| PartHash: hashStr.Sum(), | PartHash: hashStr.Sum(), | ||||
| @@ -94,16 +94,16 @@ type MultipartTask struct { | |||||
| uploadID string | uploadID string | ||||
| } | } | ||||
| func (i *MultipartTask) InitState() types.MultipartInitState { | |||||
| return types.MultipartInitState{ | |||||
| func (i *MultipartTask) InitState() stgtypes.MultipartInitState { | |||||
| return stgtypes.MultipartInitState{ | |||||
| UploadID: i.uploadID, | UploadID: i.uploadID, | ||||
| Bucket: i.bucket, | Bucket: i.bucket, | ||||
| Key: i.tempFilePath.String(), | Key: i.tempFilePath.String(), | ||||
| } | } | ||||
| } | } | ||||
| func (i *MultipartTask) JoinParts(ctx context.Context, parts []types.UploadedPartInfo) (types.FileInfo, error) { | |||||
| parts = sort2.Sort(parts, func(l, r types.UploadedPartInfo) int { | |||||
| func (i *MultipartTask) JoinParts(ctx context.Context, parts []stgtypes.UploadedPartInfo) (stgtypes.FileInfo, error) { | |||||
| parts = sort2.Sort(parts, func(l, r stgtypes.UploadedPartInfo) int { | |||||
| return l.PartNumber - r.PartNumber | return l.PartNumber - r.PartNumber | ||||
| }) | }) | ||||
| @@ -128,7 +128,7 @@ func (i *MultipartTask) JoinParts(ctx context.Context, parts []types.UploadedPar | |||||
| }, | }, | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| headResp, err := i.cli.HeadObject(ctx, &s3.HeadObjectInput{ | headResp, err := i.cli.HeadObject(ctx, &s3.HeadObjectInput{ | ||||
| @@ -136,12 +136,12 @@ func (i *MultipartTask) JoinParts(ctx context.Context, parts []types.UploadedPar | |||||
| Key: aws.String(i.tempFilePath.String()), | Key: aws.String(i.tempFilePath.String()), | ||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| hash := jcstypes.CalculateCompositeHash(partHashes) | hash := jcstypes.CalculateCompositeHash(partHashes) | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Path: i.tempFilePath, | Path: i.tempFilePath, | ||||
| Size: *headResp.ContentLength, | Size: *headResp.ContentLength, | ||||
| Hash: hash, | Hash: hash, | ||||
| @@ -7,7 +7,7 @@ import ( | |||||
| "github.com/aws/aws-sdk-go-v2/credentials" | "github.com/aws/aws-sdk-go-v2/credentials" | ||||
| "github.com/aws/aws-sdk-go-v2/service/s3" | "github.com/aws/aws-sdk-go-v2/service/s3" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -16,21 +16,21 @@ func init() { | |||||
| } | } | ||||
| type builder struct { | type builder struct { | ||||
| types.EmptyBuilder | |||||
| stgtypes.EmptyBuilder | |||||
| detail *jcstypes.UserSpaceDetail | detail *jcstypes.UserSpaceDetail | ||||
| } | } | ||||
| func newBuilder(detail *jcstypes.UserSpaceDetail) types.StorageBuilder { | |||||
| func newBuilder(detail *jcstypes.UserSpaceDetail) stgtypes.StorageBuilder { | |||||
| return &builder{ | return &builder{ | ||||
| detail: detail, | detail: detail, | ||||
| } | } | ||||
| } | } | ||||
| func (b *builder) FeatureDesc() types.FeatureDesc { | |||||
| return types.FeatureDesc{} | |||||
| func (b *builder) FeatureDesc() stgtypes.FeatureDesc { | |||||
| return stgtypes.FeatureDesc{} | |||||
| } | } | ||||
| func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | |||||
| func (b *builder) CreateShardStore(typeOnly bool) (stgtypes.ShardStore, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*jcstypes.S3Type) | stgType := b.detail.UserSpace.Storage.(*jcstypes.S3Type) | ||||
| s3Cred, ok := b.detail.UserSpace.Credential.(*jcstypes.S3Cred) | s3Cred, ok := b.detail.UserSpace.Credential.(*jcstypes.S3Cred) | ||||
| if !ok { | if !ok { | ||||
| @@ -49,7 +49,7 @@ func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | |||||
| return NewShardStore(b.detail, cli, bkt, ShardStoreOption{UseAWSSha256: true}) | return NewShardStore(b.detail, cli, bkt, ShardStoreOption{UseAWSSha256: true}) | ||||
| } | } | ||||
| func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | |||||
| func (b *builder) CreateBaseStore(typeOnly bool) (stgtypes.BaseStore, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*jcstypes.S3Type) | stgType := b.detail.UserSpace.Storage.(*jcstypes.S3Type) | ||||
| s3Cred, ok := b.detail.UserSpace.Credential.(*jcstypes.S3Cred) | s3Cred, ok := b.detail.UserSpace.Credential.(*jcstypes.S3Cred) | ||||
| if !ok { | if !ok { | ||||
| @@ -90,9 +90,9 @@ func createClient(stgType *jcstypes.S3Type, cred *jcstypes.S3Cred) (*s3.Client, | |||||
| return cli, stgType.Bucket, nil | return cli, stgType.Bucket, nil | ||||
| } | } | ||||
| func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | |||||
| func (b *builder) CreateMultiparter(typeOnly bool) (stgtypes.Multiparter, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*jcstypes.S3Type) | stgType := b.detail.UserSpace.Storage.(*jcstypes.S3Type) | ||||
| feat := types.FindFeature[*jcstypes.MultipartUploadFeature](b.detail) | |||||
| feat := stgtypes.FindFeature[*jcstypes.MultipartUploadFeature](b.detail) | |||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature %T not found", jcstypes.MultipartUploadFeature{}) | return nil, fmt.Errorf("feature %T not found", jcstypes.MultipartUploadFeature{}) | ||||
| } | } | ||||
| @@ -9,7 +9,7 @@ import ( | |||||
| s3types "github.com/aws/aws-sdk-go-v2/service/s3/types" | s3types "github.com/aws/aws-sdk-go-v2/service/s3/types" | ||||
| "gitlink.org.cn/cloudream/common/pkgs/logger" | "gitlink.org.cn/cloudream/common/pkgs/logger" | ||||
| "gitlink.org.cn/cloudream/common/utils/math2" | "gitlink.org.cn/cloudream/common/utils/math2" | ||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| ) | ) | ||||
| @@ -28,7 +28,7 @@ type ShardStore struct { | |||||
| func NewShardStore(detail *jcstypes.UserSpaceDetail, cli *s3.Client, bkt string, opt ShardStoreOption) (*ShardStore, error) { | func NewShardStore(detail *jcstypes.UserSpaceDetail, cli *s3.Client, bkt string, opt ShardStoreOption) (*ShardStore, error) { | ||||
| wd := detail.UserSpace.WorkingDir.Clone() | wd := detail.UserSpace.WorkingDir.Clone() | ||||
| wd.Push(types.ShardStoreWorkingDir) | |||||
| wd.Push(stgtypes.ShardStoreWorkingDir) | |||||
| return &ShardStore{ | return &ShardStore{ | ||||
| Detail: detail, | Detail: detail, | ||||
| Bucket: bkt, | Bucket: bkt, | ||||
| @@ -38,7 +38,7 @@ func NewShardStore(detail *jcstypes.UserSpaceDetail, cli *s3.Client, bkt string, | |||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *ShardStore) Start(ch *types.StorageEventChan) { | |||||
| func (s *ShardStore) Start(ch *stgtypes.StorageEventChan) { | |||||
| s.getLogger().Infof("start, root: %v", s.workingDir) | s.getLogger().Infof("start, root: %v", s.workingDir) | ||||
| } | } | ||||
| @@ -46,7 +46,7 @@ func (s *ShardStore) Stop() { | |||||
| s.getLogger().Infof("component stop") | s.getLogger().Infof("component stop") | ||||
| } | } | ||||
| func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int64) (types.FileInfo, error) { | |||||
| func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int64) (stgtypes.FileInfo, error) { | |||||
| s.lock.Lock() | s.lock.Lock() | ||||
| defer s.lock.Unlock() | defer s.lock.Unlock() | ||||
| @@ -63,17 +63,17 @@ func (s *ShardStore) Store(path jcstypes.JPath, hash jcstypes.FileHash, size int | |||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| log.Warnf("copy file %v to %v: %v", path, newPath, err) | log.Warnf("copy file %v to %v: %v", path, newPath, err) | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Hash: hash, | Hash: hash, | ||||
| Size: size, | Size: size, | ||||
| Path: newPath, | Path: newPath, | ||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *ShardStore) Info(hash jcstypes.FileHash) (types.FileInfo, error) { | |||||
| func (s *ShardStore) Info(hash jcstypes.FileHash) (stgtypes.FileInfo, error) { | |||||
| s.lock.Lock() | s.lock.Lock() | ||||
| defer s.lock.Unlock() | defer s.lock.Unlock() | ||||
| @@ -84,21 +84,21 @@ func (s *ShardStore) Info(hash jcstypes.FileHash) (types.FileInfo, error) { | |||||
| }) | }) | ||||
| if err != nil { | if err != nil { | ||||
| s.getLogger().Warnf("get file %v: %v", filePath, err) | s.getLogger().Warnf("get file %v: %v", filePath, err) | ||||
| return types.FileInfo{}, err | |||||
| return stgtypes.FileInfo{}, err | |||||
| } | } | ||||
| return types.FileInfo{ | |||||
| return stgtypes.FileInfo{ | |||||
| Hash: hash, | Hash: hash, | ||||
| Size: *info.ContentLength, | Size: *info.ContentLength, | ||||
| Path: filePath, | Path: filePath, | ||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (s *ShardStore) ListAll() ([]types.FileInfo, error) { | |||||
| func (s *ShardStore) ListAll() ([]stgtypes.FileInfo, error) { | |||||
| s.lock.Lock() | s.lock.Lock() | ||||
| defer s.lock.Unlock() | defer s.lock.Unlock() | ||||
| var infos []types.FileInfo | |||||
| var infos []stgtypes.FileInfo | |||||
| var marker *string | var marker *string | ||||
| for { | for { | ||||
| @@ -121,7 +121,7 @@ func (s *ShardStore) ListAll() ([]types.FileInfo, error) { | |||||
| continue | continue | ||||
| } | } | ||||
| infos = append(infos, types.FileInfo{ | |||||
| infos = append(infos, stgtypes.FileInfo{ | |||||
| Hash: fileHash, | Hash: fileHash, | ||||
| Size: *obj.Size, | Size: *obj.Size, | ||||
| Path: jcstypes.PathFromJcsPathString(*obj.Key), | Path: jcstypes.PathFromJcsPathString(*obj.Key), | ||||
| @@ -205,10 +205,10 @@ func (s *ShardStore) GC(avaiables []jcstypes.FileHash) error { | |||||
| return nil | return nil | ||||
| } | } | ||||
| func (s *ShardStore) Stats() types.Stats { | |||||
| func (s *ShardStore) Stats() stgtypes.Stats { | |||||
| // TODO 统计本地存储的相关信息 | // TODO 统计本地存储的相关信息 | ||||
| return types.Stats{ | |||||
| Status: types.StatusOK, | |||||
| return stgtypes.Stats{ | |||||
| Status: stgtypes.StatusOK, | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,4 +1,4 @@ | |||||
| package types | |||||
| package stgtypes | |||||
| import ( | import ( | ||||
| "fmt" | "fmt" | ||||
| @@ -1,4 +1,4 @@ | |||||
| package types | |||||
| package stgtypes | |||||
| import ( | import ( | ||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| @@ -1,4 +1,4 @@ | |||||
| package types | |||||
| package stgtypes | |||||
| type ECMultiplier interface { | type ECMultiplier interface { | ||||
| // 进行EC运算,coef * inputs。coef为编码矩阵,inputs为待编码数据,chunkSize为分块大小。 | // 进行EC运算,coef * inputs。coef为编码矩阵,inputs为待编码数据,chunkSize为分块大小。 | ||||
| @@ -1,4 +1,4 @@ | |||||
| package types | |||||
| package stgtypes | |||||
| import ( | import ( | ||||
| "fmt" | "fmt" | ||||
| @@ -1,4 +1,4 @@ | |||||
| package types | |||||
| package stgtypes | |||||
| import "context" | import "context" | ||||
| @@ -1,4 +1,4 @@ | |||||
| package types | |||||
| package stgtypes | |||||
| import ( | import ( | ||||
| "context" | "context" | ||||
| @@ -1,4 +1,4 @@ | |||||
| package types | |||||
| package stgtypes | |||||
| import ( | import ( | ||||
| "context" | "context" | ||||
| @@ -1,4 +1,4 @@ | |||||
| package types | |||||
| package stgtypes | |||||
| import ( | import ( | ||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||
| @@ -1,4 +1,4 @@ | |||||
| package types | |||||
| package stgtypes | |||||
| import ( | import ( | ||||
| "errors" | "errors" | ||||
| @@ -1,4 +1,4 @@ | |||||
| package types | |||||
| package stgtypes | |||||
| import ( | import ( | ||||
| jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" | ||||