diff --git a/storagedriver/filesystem/filesystem.go b/storagedriver/filesystem/filesystem.go index 0bdf60177..2cca78906 100644 --- a/storagedriver/filesystem/filesystem.go +++ b/storagedriver/filesystem/filesystem.go @@ -98,7 +98,7 @@ func (d *FilesystemDriver) ReadStream(path string, offset uint64) (io.ReadCloser func (d *FilesystemDriver) WriteStream(subPath string, offset, size uint64, reader io.ReadCloser) error { defer reader.Close() - resumableOffset, err := d.ResumeWritePosition(subPath) + resumableOffset, err := d.CurrentSize(subPath) if _, pathNotFound := err.(storagedriver.PathNotFoundError); err != nil && !pathNotFound { return err } @@ -154,7 +154,7 @@ func (d *FilesystemDriver) WriteStream(subPath string, offset, size uint64, read return err } -func (d *FilesystemDriver) ResumeWritePosition(subPath string) (uint64, error) { +func (d *FilesystemDriver) CurrentSize(subPath string) (uint64, error) { fullPath := d.subPath(subPath) fileInfo, err := os.Stat(fullPath) diff --git a/storagedriver/inmemory/inmemory.go b/storagedriver/inmemory/inmemory.go index 9b9fd9473..fee39bc97 100644 --- a/storagedriver/inmemory/inmemory.go +++ b/storagedriver/inmemory/inmemory.go @@ -78,7 +78,7 @@ func (d *InMemoryDriver) WriteStream(path string, offset, size uint64, reader io d.mutex.RLock() defer d.mutex.RUnlock() - resumableOffset, err := d.ResumeWritePosition(path) + resumableOffset, err := d.CurrentSize(path) if err != nil { return err } @@ -100,7 +100,7 @@ func (d *InMemoryDriver) WriteStream(path string, offset, size uint64, reader io return nil } -func (d *InMemoryDriver) ResumeWritePosition(path string) (uint64, error) { +func (d *InMemoryDriver) CurrentSize(path string) (uint64, error) { d.mutex.RLock() defer d.mutex.RUnlock() contents, ok := d.storage[path] diff --git a/storagedriver/ipc/client.go b/storagedriver/ipc/client.go index 929eda611..8c74e0843 100644 --- a/storagedriver/ipc/client.go +++ b/storagedriver/ipc/client.go @@ -216,16 +216,16 @@ func (driver *StorageDriverClient) WriteStream(path string, offset, size uint64, return nil } -func (driver *StorageDriverClient) ResumeWritePosition(path string) (uint64, error) { +func (driver *StorageDriverClient) CurrentSize(path string) (uint64, error) { receiver, remoteSender := libchan.Pipe() params := map[string]interface{}{"Path": path} - err := driver.sender.Send(&Request{Type: "ResumeWritePosition", Parameters: params, ResponseChannel: remoteSender}) + err := driver.sender.Send(&Request{Type: "CurrentSize", Parameters: params, ResponseChannel: remoteSender}) if err != nil { return 0, err } - var response ResumeWritePositionResponse + var response CurrentSizeResponse err = receiver.Receive(&response) if err != nil { return 0, err diff --git a/storagedriver/ipc/ipc.go b/storagedriver/ipc/ipc.go index 9c6b1dc01..233e38916 100644 --- a/storagedriver/ipc/ipc.go +++ b/storagedriver/ipc/ipc.go @@ -49,8 +49,8 @@ type WriteStreamResponse struct { Error *responseError } -// ResumeWritePositionResponse is a response for a ResumeWritePosition request -type ResumeWritePositionResponse struct { +// CurrentSizeResponse is a response for a CurrentSize request +type CurrentSizeResponse struct { Position uint64 Error *responseError } diff --git a/storagedriver/ipc/server.go b/storagedriver/ipc/server.go index d73be2f6d..ccd0e3df1 100644 --- a/storagedriver/ipc/server.go +++ b/storagedriver/ipc/server.go @@ -119,10 +119,10 @@ func handleRequest(driver storagedriver.StorageDriver, request Request) { if err != nil { panic(err) } - case "ResumeWritePosition": + case "CurrentSize": path, _ := request.Parameters["Path"].(string) - position, err := driver.ResumeWritePosition(path) - response := ResumeWritePositionResponse{ + position, err := driver.CurrentSize(path) + response := CurrentSizeResponse{ Position: position, Error: ResponseError(err), } diff --git a/storagedriver/s3/s3.go b/storagedriver/s3/s3.go index ea13b87cb..c932a1e17 100644 --- a/storagedriver/s3/s3.go +++ b/storagedriver/s3/s3.go @@ -177,7 +177,7 @@ func (d *S3Driver) WriteStream(path string, offset, size uint64, reader io.ReadC return nil } -func (d *S3Driver) ResumeWritePosition(path string) (uint64, error) { +func (d *S3Driver) CurrentSize(path string) (uint64, error) { _, parts, err := d.getAllParts(path) if err != nil { return 0, err @@ -190,11 +190,11 @@ func (d *S3Driver) ResumeWritePosition(path string) (uint64, error) { return (((uint64(len(parts)) - 1) * uint64(parts[0].Size)) + uint64(parts[len(parts)-1].Size)), nil } -func (d *S3Driver) List(prefix string) ([]string, error) { - if prefix[len(prefix)-1] != '/' { - prefix = prefix + "/" +func (d *S3Driver) List(path string) ([]string, error) { + if path[len(path)-1] != '/' { + path = path + "/" } - listResponse, err := d.Bucket.List(prefix, "/", "", listPartsMax) + listResponse, err := d.Bucket.List(path, "/", "", listPartsMax) if err != nil { return nil, err } @@ -212,7 +212,7 @@ func (d *S3Driver) List(prefix string) ([]string, error) { } if listResponse.IsTruncated { - listResponse, err = d.Bucket.List(prefix, "/", listResponse.NextMarker, listPartsMax) + listResponse, err = d.Bucket.List(path, "/", listResponse.NextMarker, listPartsMax) if err != nil { return nil, err } diff --git a/storagedriver/storagedriver.go b/storagedriver/storagedriver.go index a66dba0c2..01ebd5ff8 100644 --- a/storagedriver/storagedriver.go +++ b/storagedriver/storagedriver.go @@ -25,12 +25,12 @@ type StorageDriver interface { // the given path // The driver will know it has received the full contents when it has read "size" bytes // May be used to resume writing a stream by providing a nonzero offset - // The offset must be no larger than the ResumeWritePosition for this path + // The offset must be no larger than the CurrentSize for this path WriteStream(path string, offset, size uint64, readCloser io.ReadCloser) error - // ResumeWritePosition retrieves the byte offset at which it is safe to continue writing at the - // given path - ResumeWritePosition(path string) (uint64, error) + // CurrentSize retrieves the curernt size in bytes of the object at the given path + // It should be safe to read or write anywhere up to this point + CurrentSize(path string) (uint64, error) // List returns a list of the objects that are direct descendants of the given path List(path string) ([]string, error) diff --git a/storagedriver/testsuites/testsuites.go b/storagedriver/testsuites/testsuites.go index 94d85461a..d2859913d 100644 --- a/storagedriver/testsuites/testsuites.go +++ b/storagedriver/testsuites/testsuites.go @@ -160,7 +160,7 @@ func (suite *DriverSuite) TestContinueStreamAppend(c *C) { err := suite.StorageDriver.WriteStream(filename, 0, 3*chunkSize, ioutil.NopCloser(bytes.NewReader(contentsChunk1))) c.Assert(err, IsNil) - offset, err := suite.StorageDriver.ResumeWritePosition(filename) + offset, err := suite.StorageDriver.CurrentSize(filename) c.Assert(err, IsNil) if offset > chunkSize { c.Fatalf("Offset too large, %d > %d", offset, chunkSize) @@ -168,7 +168,7 @@ func (suite *DriverSuite) TestContinueStreamAppend(c *C) { err = suite.StorageDriver.WriteStream(filename, offset, 3*chunkSize, ioutil.NopCloser(bytes.NewReader(fullContents[offset:2*chunkSize]))) c.Assert(err, IsNil) - offset, err = suite.StorageDriver.ResumeWritePosition(filename) + offset, err = suite.StorageDriver.CurrentSize(filename) c.Assert(err, IsNil) if offset > 2*chunkSize { c.Fatalf("Offset too large, %d > %d", offset, 2*chunkSize)