Move Dynamic Large Object handling to dedicated methods

Signed-off-by: Sylvain Baubeau <sbaubeau@redhat.com>
This commit is contained in:
Sylvain Baubeau 2015-05-29 16:09:05 +02:00
parent 8a22c0f4e1
commit ea81e208a4

View file

@ -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 {