@@ -53,8 +53,8 @@ func (d *Chunk) Drop(ctx context.Context) error {
5353 return nil
5454}
5555
56- func (Addition ) GetRootPath () string {
57- return "/ "
56+ func (* Chunk ) GetRootPath () string {
57+ return ""
5858}
5959
6060func (d * Chunk ) Get (ctx context.Context , path string ) (model.Obj , error ) {
@@ -80,7 +80,7 @@ func (d *Chunk) Get(ctx context.Context, path string) (model.Obj, error) {
8080 if err != nil {
8181 return nil , err
8282 }
83- var totalSize int64 = 0
83+ var totalSize int64
8484 // 0号块默认为-1 以支持空文件
8585 chunkSizes := []int64 {- 1 }
8686 h := make (map [* utils.HashType ]string )
@@ -119,6 +119,25 @@ func (d *Chunk) Get(ctx context.Context, path string) (model.Obj, error) {
119119 }
120120 }
121121 reqDir , _ := stdpath .Split (path )
122+ // 文件块不完整时,返回文件夹对象
123+ if chunkSizes [0 ] == - 1 {
124+ return & model.Object {
125+ Path : stdpath .Join (reqDir , chunkName ),
126+ Name : chunkName ,
127+ IsFolder : true ,
128+ Modified : d .Modified ,
129+ }, nil
130+ }
131+ for i , l := 1 , len (chunkSizes )- 1 ; i < l ; i ++ {
132+ if chunkSizes [i ] == 0 {
133+ return & model.Object {
134+ Path : stdpath .Join (reqDir , chunkName ),
135+ Name : chunkName ,
136+ IsFolder : true ,
137+ Modified : d .Modified ,
138+ }, nil
139+ }
140+ }
122141 objRes := chunkObject {
123142 Object : model.Object {
124143 Path : stdpath .Join (reqDir , chunkName ),
@@ -161,37 +180,69 @@ func (d *Chunk) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
161180 result = append (result , nil )
162181 listG .Go (func (ctx context.Context ) error {
163182 chunkObjs , err := op .List (ctx , remoteStorage , stdpath .Join (remoteActualDir , rawName ), model.ListArgs {
164- ReqPath : stdpath .Join (args .ReqPath , rawName ),
165183 Refresh : args .Refresh ,
166184 })
167185 if err != nil {
168186 return err
169187 }
170- totalSize := int64 (0 )
188+ var totalSize int64
189+ // 0号块默认为-1 以支持空文件
190+ chunkSizes := []int64 {- 1 }
171191 h := make (map [* utils.HashType ]string )
172- first := obj
192+ var first model. Obj
173193 for _ , o := range chunkObjs {
174194 if o .IsDir () {
175195 continue
176196 }
177- if after , ok := strings .CutPrefix (strings . TrimSuffix ( o .GetName (), d . CustomExt ), "hash_" ); ok {
178- hn , value , ok := strings .Cut (after , "_" )
197+ if after , ok := strings .CutPrefix (o .GetName (), "hash_" ); ok {
198+ hn , value , ok := strings .Cut (strings . TrimSuffix ( after , d . CustomExt ) , "_" )
179199 if ok {
180200 ht , ok := utils .GetHashByName (hn )
181201 if ok {
182202 h [ht ] = value
183203 }
184- continue
185204 }
205+ continue
186206 }
187207 idx , err := strconv .Atoi (strings .TrimSuffix (o .GetName (), d .CustomExt ))
188208 if err != nil {
189209 continue
190210 }
191- if idx == 0 {
192- first = o
193- }
194211 totalSize += o .GetSize ()
212+ if len (chunkSizes ) > idx {
213+ if idx == 0 {
214+ first = o
215+ }
216+ chunkSizes [idx ] = o .GetSize ()
217+ } else if len (chunkSizes ) == idx {
218+ chunkSizes = append (chunkSizes , o .GetSize ())
219+ } else {
220+ newChunkSizes := make ([]int64 , idx + 1 )
221+ copy (newChunkSizes , chunkSizes )
222+ chunkSizes = newChunkSizes
223+ chunkSizes [idx ] = o .GetSize ()
224+ }
225+ }
226+ // 文件块不完整时,返回文件夹对象
227+ if chunkSizes [0 ] == - 1 {
228+ result [resultIdx ] = & model.Object {
229+ Name : rawName ,
230+ Size : obj .GetSize (),
231+ Modified : obj .ModTime (),
232+ IsFolder : true ,
233+ }
234+ return nil
235+ }
236+ for i , l := 1 , len (chunkSizes )- 1 ; i < l ; i ++ {
237+ if chunkSizes [i ] == 0 {
238+ result [resultIdx ] = & model.Object {
239+ Name : rawName ,
240+ Size : obj .GetSize (),
241+ Modified : obj .ModTime (),
242+ IsFolder : true ,
243+ }
244+ return nil
245+ }
195246 }
196247 objRes := model.Object {
197248 Name : name ,
0 commit comments