forked from TrueCloudLab/distribution
Move Dynamic Large Object handling to dedicated methods
Signed-off-by: Sylvain Baubeau <sbaubeau@redhat.com>
This commit is contained in:
parent
d8d50fb0e0
commit
2632fd9dc8
1 changed files with 20 additions and 8 deletions
|
@ -237,8 +237,8 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
||||||
bytesRead := int64(0)
|
bytesRead := int64(0)
|
||||||
currentLength := int64(0)
|
currentLength := int64(0)
|
||||||
zeroBuf := make([]byte, d.ChunkSize)
|
zeroBuf := make([]byte, d.ChunkSize)
|
||||||
segmentsContainer := d.Container + "_segments"
|
|
||||||
cursor := int64(0)
|
cursor := int64(0)
|
||||||
|
segmentsContainer := d.getSegmentsContainer()
|
||||||
|
|
||||||
getSegment := func() string {
|
getSegment := func() string {
|
||||||
return d.swiftPath(path) + "/" + fmt.Sprintf("%016d", partNumber)
|
return d.swiftPath(path) + "/" + fmt.Sprintf("%016d", partNumber)
|
||||||
|
@ -269,10 +269,7 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
||||||
} else {
|
} else {
|
||||||
// The manifest already exists. Get all the segments
|
// The manifest already exists. Get all the segments
|
||||||
currentLength = info.Bytes
|
currentLength = info.Bytes
|
||||||
headers := make(swift.Headers)
|
segments, err = d.getAllSegments(segmentsContainer, path)
|
||||||
headers["Content-Type"] = "application/json"
|
|
||||||
opts := &swift.ObjectsOpts{Prefix: d.swiftPath(path), Headers: headers}
|
|
||||||
segments, err = d.Conn.Objects(d.Container+"_segments", opts)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bytesRead, parseError(path, err)
|
return bytesRead, parseError(path, err)
|
||||||
}
|
}
|
||||||
|
@ -438,14 +435,14 @@ func (d *driver) Delete(ctx context.Context, path string) error {
|
||||||
if ok {
|
if ok {
|
||||||
components := strings.SplitN(manifest, "/", 2)
|
components := strings.SplitN(manifest, "/", 2)
|
||||||
segContainer := components[0]
|
segContainer := components[0]
|
||||||
segments, err := d.Conn.ObjectNamesAll(segContainer, &swift.ObjectsOpts{Prefix: components[1]})
|
segments, err := d.getAllSegments(segContainer, components[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return parseError(name, err)
|
return parseError(name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range segments {
|
for _, s := range segments {
|
||||||
if err := d.Conn.ObjectDelete(segContainer, s); err != nil {
|
if err := d.Conn.ObjectDelete(segContainer, s.Name); err != nil {
|
||||||
return parseError(s, err)
|
return parseError(s.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,6 +489,21 @@ func (d *driver) getContentType() string {
|
||||||
return "application/octet-stream"
|
return "application/octet-stream"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *driver) getSegmentsContainer() string {
|
||||||
|
return d.Container + "_segments"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *driver) getAllSegments(container string, path string) ([]swift.Object, error) {
|
||||||
|
return d.Conn.Objects(container, &swift.ObjectsOpts{Prefix: d.swiftPath(path)})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *driver) createManifest(path string) (*swift.ObjectCreateFile, error) {
|
||||||
|
headers := make(swift.Headers)
|
||||||
|
headers["X-Object-Manifest"] = d.getSegmentsContainer() + "/" + d.swiftPath(path)
|
||||||
|
return d.Conn.ObjectCreate(d.Container, d.swiftPath(path), false, "",
|
||||||
|
d.getContentType(), headers)
|
||||||
|
}
|
||||||
|
|
||||||
func detectBulkDelete(authURL string) (bulkDelete bool) {
|
func detectBulkDelete(authURL string) (bulkDelete bool) {
|
||||||
resp, err := http.Get(filepath.Join(authURL, "..", "..") + "/info")
|
resp, err := http.Get(filepath.Join(authURL, "..", "..") + "/info")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
Loading…
Reference in a new issue