@@ -530,10 +530,10 @@ type listFn func(remote string, object *swift.Object, isDirectory bool) error
530
530
//
531
531
// Set recurse to read sub directories
532
532
func (f * Fs ) listContainerRoot (container , directory , prefix string , addContainer bool , recurse bool , fn listFn ) error {
533
- if prefix != "" {
533
+ if prefix != "" && ! strings . HasSuffix ( prefix , "/" ) {
534
534
prefix += "/"
535
535
}
536
- if directory != "" {
536
+ if directory != "" && ! strings . HasSuffix ( directory , "/" ) {
537
537
directory += "/"
538
538
}
539
539
// Options for ObjectsWalk
@@ -952,6 +952,18 @@ func (o *Object) isStaticLargeObject() (bool, error) {
952
952
return o .hasHeader ("X-Static-Large-Object" )
953
953
}
954
954
955
+ func (o * Object ) isInContainerVersioning () (bool , error ) {
956
+ _ , headers , err := o .fs .c .Container (o .fs .root )
957
+ if err != nil {
958
+ return false , err
959
+ }
960
+ xHistoryLocation := headers ["X-History-Location" ]
961
+ if len (xHistoryLocation ) > 0 {
962
+ return true , nil
963
+ }
964
+ return false , nil
965
+ }
966
+
955
967
// Size returns the size of an object in bytes
956
968
func (o * Object ) Size () int64 {
957
969
return o .size
@@ -1083,9 +1095,8 @@ func min(x, y int64) int64 {
1083
1095
//
1084
1096
// if except is passed in then segments with that prefix won't be deleted
1085
1097
func (o * Object ) removeSegments (except string ) error {
1086
- container , containerPath := o .split ()
1087
- segmentsContainer := container + "_segments"
1088
- err := o .fs .listContainerRoot (segmentsContainer , containerPath , "" , false , true , func (remote string , object * swift.Object , isDirectory bool ) error {
1098
+ segmentsContainer , prefix , err := o .getSegmentsDlo ()
1099
+ err = o .fs .listContainerRoot (segmentsContainer , prefix , "" , false , true , func (remote string , object * swift.Object , isDirectory bool ) error {
1089
1100
if isDirectory {
1090
1101
return nil
1091
1102
}
@@ -1114,6 +1125,19 @@ func (o *Object) removeSegments(except string) error {
1114
1125
return nil
1115
1126
}
1116
1127
1128
+ func (o * Object ) getSegmentsDlo () (segmentsContainer string , prefix string , err error ) {
1129
+ if err = o .readMetaData (); err != nil {
1130
+ return
1131
+ }
1132
+ dirManifest := o .headers ["X-Object-Manifest" ]
1133
+ delimiter := strings .Index (dirManifest , "/" )
1134
+ if len (dirManifest ) == 0 || delimiter < 0 {
1135
+ err = errors .New ("Missing or wrong structure of manifest of Dynamic large object" )
1136
+ return
1137
+ }
1138
+ return dirManifest [:delimiter ], dirManifest [delimiter + 1 :], nil
1139
+ }
1140
+
1117
1141
// urlEncode encodes a string so that it is a valid URL
1118
1142
//
1119
1143
// We don't use any of Go's standard methods as we need `/` not
@@ -1300,12 +1324,9 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
1300
1324
}
1301
1325
1302
1326
// Remove an object
1303
- func (o * Object ) Remove (ctx context.Context ) error {
1327
+ func (o * Object ) Remove (ctx context.Context ) ( err error ) {
1304
1328
container , containerPath := o .split ()
1305
- isDynamicLargeObject , err := o .isDynamicLargeObject ()
1306
- if err != nil {
1307
- return err
1308
- }
1329
+
1309
1330
// Remove file/manifest first
1310
1331
err = o .fs .pacer .Call (func () (bool , error ) {
1311
1332
err = o .fs .c .ObjectDelete (container , containerPath )
@@ -1314,12 +1335,22 @@ func (o *Object) Remove(ctx context.Context) error {
1314
1335
if err != nil {
1315
1336
return err
1316
1337
}
1338
+ isDynamicLargeObject , err := o .isDynamicLargeObject ()
1339
+ if err != nil {
1340
+ return err
1341
+ }
1317
1342
// ...then segments if required
1318
1343
if isDynamicLargeObject {
1319
- err = o .removeSegments ( "" )
1344
+ isInContainerVersioning , err : = o .isInContainerVersioning ( )
1320
1345
if err != nil {
1321
1346
return err
1322
1347
}
1348
+ if ! isInContainerVersioning {
1349
+ err = o .removeSegments ("" )
1350
+ if err != nil {
1351
+ return err
1352
+ }
1353
+ }
1323
1354
}
1324
1355
return nil
1325
1356
}
0 commit comments