php-opencloud / openstack

PHP SDK for OpenStack clouds
Apache License 2.0
222 stars 152 forks source link

The createLargeObject() does not work correctly for segment count 10 and more #365

Closed vpecinka closed 9 months ago

vpecinka commented 9 months ago

In the method createLargeObject() there is on this line the following construct

'name'          => sprintf('%s/%d', $segmentPrefix, ++$count),

however, when there is more than 9 parts (segments) the resulting large file will not be restored correctly, as the Swift object storage orders the segments by filename...

As stated here in Swift docs: All the object segments need to be in the same container, have a common object name prefix, and sort in the order in which they should be concatenated. Object names are sorted lexicographically as UTF-8 byte strings.

The current code produces something like this

segmentPrefix/1
segmentPrefix/10
segmentPrefix/11
segmentPrefix/2
segmentPrefix/3

and should produce

segmentPrefix/0001
segmentPrefix/0002
segmentPrefix/0003
:
:
segmentPrefix/0010
segmentPrefix/0011

therefore I suggest to change the code to this:

'name'          => sprintf('%s/%05d', $segmentPrefix, ++$count),