forked from TrueCloudLab/distribution
Use gofmt to format the code of swift driver.
Signed-off-by: Li Wenquan <wenquan.li@hp.com>
This commit is contained in:
parent
cce4956131
commit
1f4eb7b735
2 changed files with 26 additions and 26 deletions
|
@ -155,8 +155,8 @@ func New(params DriverParameters) (*Driver, error) {
|
|||
return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container, err)
|
||||
}
|
||||
|
||||
if err := ct.ContainerCreate(params.Container + "_segments", nil); err != nil {
|
||||
return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container + "_segments", err)
|
||||
if err := ct.ContainerCreate(params.Container+"_segments", nil); err != nil {
|
||||
return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container+"_segments", err)
|
||||
}
|
||||
|
||||
d := &driver{
|
||||
|
@ -279,7 +279,7 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
|||
headers := make(swift.Headers)
|
||||
headers["Content-Type"] = "application/json"
|
||||
opts := &swift.ObjectsOpts{Prefix: d.swiftPath(path), Headers: headers}
|
||||
segments, err = d.Conn.Objects(d.Container + "_segments", opts)
|
||||
segments, err = d.Conn.Objects(d.Container+"_segments", opts)
|
||||
if err != nil {
|
||||
return bytesRead, parseError(path, err)
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
|||
|
||||
// First, we skip the existing segments that are not modified by this call
|
||||
for i := range segments {
|
||||
if offset < cursor + segments[i].Bytes {
|
||||
if offset < cursor+segments[i].Bytes {
|
||||
break
|
||||
}
|
||||
cursor += segments[i].Bytes
|
||||
|
@ -297,7 +297,7 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
|||
// We reached the end of the file but we haven't reached 'offset' yet
|
||||
// Therefore we add blocks of zeros
|
||||
if offset >= currentLength {
|
||||
for offset - currentLength >= d.ChunkSize {
|
||||
for offset-currentLength >= d.ChunkSize {
|
||||
// Insert a block a zero
|
||||
d.Conn.ObjectPut(segmentsContainer, getSegment(),
|
||||
bytes.NewReader(zeroBuf), false, "",
|
||||
|
@ -318,8 +318,8 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
|||
}
|
||||
|
||||
multi := io.MultiReader(
|
||||
io.LimitReader(paddingReader, offset - cursor),
|
||||
io.LimitReader(reader, d.ChunkSize - (offset - cursor)),
|
||||
io.LimitReader(paddingReader, offset-cursor),
|
||||
io.LimitReader(reader, d.ChunkSize-(offset-cursor)),
|
||||
)
|
||||
|
||||
for {
|
||||
|
@ -335,10 +335,10 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
|||
|
||||
if n < d.ChunkSize {
|
||||
// We wrote all the data
|
||||
if cursor + n < currentLength {
|
||||
if cursor+n < currentLength {
|
||||
// Copy the end of the chunk
|
||||
headers := make(swift.Headers)
|
||||
headers["Range"] = "bytes=" + strconv.FormatInt(cursor + n, 10) + "-" + strconv.FormatInt(cursor + d.ChunkSize, 10)
|
||||
headers["Range"] = "bytes=" + strconv.FormatInt(cursor+n, 10) + "-" + strconv.FormatInt(cursor+d.ChunkSize, 10)
|
||||
file, _, err := d.Conn.ObjectOpen(d.Container, d.swiftPath(path), false, headers)
|
||||
if err != nil {
|
||||
return bytesRead, parseError(path, err)
|
||||
|
@ -348,13 +348,13 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
|||
}
|
||||
if n > 0 {
|
||||
currentSegment.Close()
|
||||
bytesRead += n - max(0, offset - cursor)
|
||||
bytesRead += n - max(0, offset-cursor)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
currentSegment.Close()
|
||||
bytesRead += n - max(0, offset - cursor)
|
||||
bytesRead += n - max(0, offset-cursor)
|
||||
multi = io.MultiReader(io.LimitReader(reader, d.ChunkSize))
|
||||
cursor += d.ChunkSize
|
||||
partNumber++
|
||||
|
@ -443,7 +443,7 @@ func (d *driver) Delete(ctx context.Context, path string) error {
|
|||
if ok {
|
||||
components := strings.SplitN(manifest, "/", 2)
|
||||
segContainer := components[0]
|
||||
segments, err := d.Conn.ObjectNamesAll(segContainer, &swift.ObjectsOpts{ Prefix: components[1] })
|
||||
segments, err := d.Conn.ObjectNamesAll(segContainer, &swift.ObjectsOpts{Prefix: components[1]})
|
||||
if err != nil {
|
||||
return parseError(name, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue