@@ -181,6 +181,9 @@ func allowedFragcount(file *storage.FileInformation, minBpf int) int {
181
181
// Note that when we will do the deduplication more clever (comparing all blocks of all files), we may also need to do
182
182
// the defragmentation in a more clever way.
183
183
func reorderAndDefragIfNeeded (ctx context , files []* storage.FileInformation , minBpf int , noact bool ) (copy []* storage.FileInformation ) {
184
+ if len (files ) == 0 {
185
+ return files
186
+ }
184
187
copy = make ([]* storage.FileInformation , len (files ), len (files ))
185
188
for idx , file := range files {
186
189
copy [idx ] = file
@@ -198,6 +201,7 @@ func reorderAndDefragIfNeeded(ctx context, files []*storage.FileInformation, min
198
201
}
199
202
fragcount := len (copy [0 ].Fragments )
200
203
allowedFragcount := allowedFragcount (copy [0 ], minBpf )
204
+ allowedFragcount = 1
201
205
if fragcount <= allowedFragcount {
202
206
return
203
207
}
@@ -247,9 +251,10 @@ func reorderAndDefragIfNeeded(ctx context, files []*storage.FileInformation, min
247
251
248
252
if newFile , err := readFileMeta (file .Path , path ); err != nil {
249
253
log .Printf ("Error while reading the fragmentation table again: %v" , err )
254
+ return reorderAndDefragIfNeeded (ctx , copy [1 :], minBpf , noact )
250
255
} else if newFile == nil {
251
256
log .Printf ("File can not be deduplicated after defragmentation" )
252
- copy = copy [1 :]
257
+ return reorderAndDefragIfNeeded ( ctx , copy [1 :], minBpf , noact )
253
258
} else {
254
259
copy [0 ] = newFile
255
260
log .Printf ("Number of fragments was %d and is now %d for file %s" , fragcount , len (newFile .Fragments ), path )
0 commit comments