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)
|
return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ct.ContainerCreate(params.Container + "_segments", nil); err != nil {
|
if err := ct.ContainerCreate(params.Container+"_segments", nil); err != nil {
|
||||||
return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container + "_segments", err)
|
return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container+"_segments", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
d := &driver{
|
d := &driver{
|
||||||
|
@ -197,7 +197,7 @@ func (d *driver) PutContent(ctx context.Context, path string, contents []byte) e
|
||||||
return parseError(dir, err)
|
return parseError(dir, err)
|
||||||
}
|
}
|
||||||
err := d.Conn.ObjectPutBytes(d.Container, d.swiftPath(path),
|
err := d.Conn.ObjectPutBytes(d.Container, d.swiftPath(path),
|
||||||
contents, d.getContentType())
|
contents, d.getContentType())
|
||||||
return parseError(path, err)
|
return parseError(path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
||||||
headers := make(swift.Headers)
|
headers := make(swift.Headers)
|
||||||
headers["X-Object-Manifest"] = segmentsContainer + "/" + d.swiftPath(path)
|
headers["X-Object-Manifest"] = segmentsContainer + "/" + d.swiftPath(path)
|
||||||
manifest, err := d.Conn.ObjectCreate(d.Container, d.swiftPath(path), false, "",
|
manifest, err := d.Conn.ObjectCreate(d.Container, d.swiftPath(path), false, "",
|
||||||
d.getContentType(), headers)
|
d.getContentType(), headers)
|
||||||
manifest.Close()
|
manifest.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bytesRead, parseError(path, err)
|
return bytesRead, parseError(path, err)
|
||||||
|
@ -279,7 +279,7 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
||||||
headers := make(swift.Headers)
|
headers := make(swift.Headers)
|
||||||
headers["Content-Type"] = "application/json"
|
headers["Content-Type"] = "application/json"
|
||||||
opts := &swift.ObjectsOpts{Prefix: d.swiftPath(path), Headers: headers}
|
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 {
|
if err != nil {
|
||||||
return bytesRead, parseError(path, err)
|
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
|
// First, we skip the existing segments that are not modified by this call
|
||||||
for i := range segments {
|
for i := range segments {
|
||||||
if offset < cursor + segments[i].Bytes {
|
if offset < cursor+segments[i].Bytes {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
cursor += segments[i].Bytes
|
cursor += segments[i].Bytes
|
||||||
|
@ -297,11 +297,11 @@ 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
|
// We reached the end of the file but we haven't reached 'offset' yet
|
||||||
// Therefore we add blocks of zeros
|
// Therefore we add blocks of zeros
|
||||||
if offset >= currentLength {
|
if offset >= currentLength {
|
||||||
for offset - currentLength >= d.ChunkSize {
|
for offset-currentLength >= d.ChunkSize {
|
||||||
// Insert a block a zero
|
// Insert a block a zero
|
||||||
d.Conn.ObjectPut(segmentsContainer, getSegment(),
|
d.Conn.ObjectPut(segmentsContainer, getSegment(),
|
||||||
bytes.NewReader(zeroBuf), false, "",
|
bytes.NewReader(zeroBuf), false, "",
|
||||||
d.getContentType(), nil)
|
d.getContentType(), nil)
|
||||||
currentLength += d.ChunkSize
|
currentLength += d.ChunkSize
|
||||||
partNumber++
|
partNumber++
|
||||||
}
|
}
|
||||||
|
@ -318,8 +318,8 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
||||||
}
|
}
|
||||||
|
|
||||||
multi := io.MultiReader(
|
multi := io.MultiReader(
|
||||||
io.LimitReader(paddingReader, offset - cursor),
|
io.LimitReader(paddingReader, offset-cursor),
|
||||||
io.LimitReader(reader, d.ChunkSize - (offset - cursor)),
|
io.LimitReader(reader, d.ChunkSize-(offset-cursor)),
|
||||||
)
|
)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -335,10 +335,10 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
||||||
|
|
||||||
if n < d.ChunkSize {
|
if n < d.ChunkSize {
|
||||||
// We wrote all the data
|
// We wrote all the data
|
||||||
if cursor + n < currentLength {
|
if cursor+n < currentLength {
|
||||||
// Copy the end of the chunk
|
// Copy the end of the chunk
|
||||||
headers := make(swift.Headers)
|
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)
|
file, _, err := d.Conn.ObjectOpen(d.Container, d.swiftPath(path), false, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bytesRead, parseError(path, err)
|
return bytesRead, parseError(path, err)
|
||||||
|
@ -348,13 +348,13 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
|
||||||
}
|
}
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
currentSegment.Close()
|
currentSegment.Close()
|
||||||
bytesRead += n - max(0, offset - cursor)
|
bytesRead += n - max(0, offset-cursor)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSegment.Close()
|
currentSegment.Close()
|
||||||
bytesRead += n - max(0, offset - cursor)
|
bytesRead += n - max(0, offset-cursor)
|
||||||
multi = io.MultiReader(io.LimitReader(reader, d.ChunkSize))
|
multi = io.MultiReader(io.LimitReader(reader, d.ChunkSize))
|
||||||
cursor += d.ChunkSize
|
cursor += d.ChunkSize
|
||||||
partNumber++
|
partNumber++
|
||||||
|
@ -405,7 +405,7 @@ func (d *driver) List(ctx context.Context, path string) ([]string, error) {
|
||||||
// object.
|
// object.
|
||||||
func (d *driver) Move(ctx context.Context, sourcePath string, destPath string) error {
|
func (d *driver) Move(ctx context.Context, sourcePath string, destPath string) error {
|
||||||
err := d.Conn.ObjectMove(d.Container, d.swiftPath(sourcePath),
|
err := d.Conn.ObjectMove(d.Container, d.swiftPath(sourcePath),
|
||||||
d.Container, d.swiftPath(destPath))
|
d.Container, d.swiftPath(destPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return parseError(sourcePath, err)
|
return parseError(sourcePath, err)
|
||||||
}
|
}
|
||||||
|
@ -443,7 +443,7 @@ 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.Conn.ObjectNamesAll(segContainer, &swift.ObjectsOpts{Prefix: components[1]})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return parseError(name, err)
|
return parseError(name, err)
|
||||||
}
|
}
|
||||||
|
@ -483,7 +483,7 @@ func (d *driver) createParentFolder(path string) (string, error) {
|
||||||
_, _, err := d.Conn.Object(d.Container, d.swiftPath(dir))
|
_, _, err := d.Conn.Object(d.Container, d.swiftPath(dir))
|
||||||
if swiftErr, ok := err.(*swift.Error); ok && swiftErr.StatusCode == 404 {
|
if swiftErr, ok := err.(*swift.Error); ok && swiftErr.StatusCode == 404 {
|
||||||
_, err := d.Conn.ObjectPut(d.Container, d.swiftPath(dir), bytes.NewReader(make([]byte, 0)),
|
_, err := d.Conn.ObjectPut(d.Container, d.swiftPath(dir), bytes.NewReader(make([]byte, 0)),
|
||||||
false, "", "application/directory", nil)
|
false, "", "application/directory", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dir, err
|
return dir, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,15 @@ type SwiftDriverConstructor func(rootDirectory string) (*Driver, error)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var (
|
var (
|
||||||
username string
|
username string
|
||||||
password string
|
password string
|
||||||
authURL string
|
authURL string
|
||||||
tenant string
|
tenant string
|
||||||
container string
|
container string
|
||||||
region string
|
region string
|
||||||
prefix string
|
prefix string
|
||||||
swiftServer *swifttest.SwiftServer
|
swiftServer *swifttest.SwiftServer
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
if username = os.Getenv("OS_USERNAME"); username == "" {
|
if username = os.Getenv("OS_USERNAME"); username == "" {
|
||||||
username = os.Getenv("ST_USER")
|
username = os.Getenv("ST_USER")
|
||||||
|
|
Loading…
Reference in a new issue