@@ -111,11 +111,13 @@ func (fs *FileSystem) Finalize(options FinalizeOptions) error {
111
111
b []byte
112
112
)
113
113
location += superblockSize
114
+ dataBlocksOffset := int64 (superblockSize )
114
115
if options .Compression != nil {
115
116
b = options .Compression .optionsBytes ()
116
117
if len (b ) > 0 {
117
118
_ , _ = f .WriteAt (b , location )
118
119
location += int64 (len (b ))
120
+ dataBlocksOffset += int64 (len (b ))
119
121
}
120
122
}
121
123
@@ -137,11 +139,11 @@ func (fs *FileSystem) Finalize(options FinalizeOptions) error {
137
139
// write file fragments
138
140
//
139
141
fragmentBlockStart := location
140
- fragmentBlocks , fragsWritten , err := writeFragmentBlocks (fileList , f , fs .workspace , blocksize , options , fragmentBlockStart )
142
+ fragmentBlocks , _ , err := writeFragmentBlocks (fileList , f , fs .workspace , blocksize , options , fragmentBlockStart )
141
143
if err != nil {
142
144
return fmt .Errorf ("error writing file fragment blocks: %v" , err )
143
145
}
144
- location += fragsWritten
146
+ location += int64 ( len ( fragmentBlocks ) * blocksize )
145
147
146
148
// extract extended attributes, and save them for later; these are written at the very end
147
149
// this must be done *before* creating inodes, as inodes reference these
@@ -538,6 +540,7 @@ func writeFileDataBlocks(e *finalizeFileInfo, to backend.WritableFile, ws string
538
540
e .dataLocation = location
539
541
e .blocks = blocks
540
542
e .startBlock = startBlock
543
+ e .startFromBegin = location
541
544
542
545
// how many blocks did we write?
543
546
blockCount = raw / blocksize
@@ -588,7 +591,9 @@ func writeDataBlocks(fileList []*finalizeFileInfo, f backend.WritableFile, ws st
588
591
}
589
592
allBlocks += blocks
590
593
allWritten += written
594
+ location += int64 (written )
591
595
}
596
+
592
597
return allWritten , nil
593
598
}
594
599
@@ -637,9 +642,10 @@ func writeFragmentBlocks(fileList []*finalizeFileInfo, f backend.WritableFile, w
637
642
compressed : compressed ,
638
643
location : location ,
639
644
})
645
+ location += int64 ((written + blocksize - 1 ) / blocksize * blocksize )
640
646
// increment as all writes will be to next block block
641
647
fragmentBlockIndex ++
642
- fragmentData = fragmentData [: blocksize ]
648
+ fragmentData = make ([] byte , 0 )
643
649
}
644
650
645
651
e .fragment = & fragmentRef {
@@ -1119,13 +1125,15 @@ func createInodes(fileList []*finalizeFileInfo, idtable map[uint32]uint16, optio
1119
1125
} else {
1120
1126
// use basicFile
1121
1127
bf := & basicFile {
1122
- startBlock : uint32 (e .startBlock ),
1128
+ startBlock : uint32 (e .startFromBegin ),
1123
1129
fileSize : uint32 (e .Size ()),
1124
1130
blockSizes : e .blocks ,
1125
1131
}
1126
1132
if e .fragment != nil {
1127
1133
bf .fragmentBlockIndex = e .fragment .block
1128
1134
bf .fragmentOffset = e .fragment .offset
1135
+ } else {
1136
+ bf .fragmentBlockIndex = 0xffffffff
1129
1137
}
1130
1138
in = bf
1131
1139
inodeT = inodeBasicFile
0 commit comments