aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2017-06-19 11:40:34 -0700
committerJakob Odersky <jakob@odersky.com>2017-06-19 13:47:42 -0700
commitf6a67a8400e12de6e0ae83d0b4c744e07fc4901c (patch)
tree7cfeab5d13327a3e319a893d54cd0bb30a00ad92
parent38b7278027e81c97afde27fb48eefde3c6e254bd (diff)
downloaddriver-core-f6a67a8400e12de6e0ae83d0b4c744e07fc4901c.tar.gz
driver-core-f6a67a8400e12de6e0ae83d0b4c744e07fc4901c.tar.bz2
driver-core-f6a67a8400e12de6e0ae83d0b4c744e07fc4901c.zip
Check for null values in gcs directory listingv0.13.12
GCS: when listing, always assume the path is a directory GCS: fix unit test
-rw-r--r--src/main/scala/xyz/driver/core/file/GcsStorage.scala22
-rw-r--r--src/main/scala/xyz/driver/core/file/package.scala3
-rw-r--r--src/test/scala/xyz/driver/core/FileTest.scala3
3 files changed, 17 insertions, 11 deletions
diff --git a/src/main/scala/xyz/driver/core/file/GcsStorage.scala b/src/main/scala/xyz/driver/core/file/GcsStorage.scala
index 6c2746e..0d8b918 100644
--- a/src/main/scala/xyz/driver/core/file/GcsStorage.scala
+++ b/src/main/scala/xyz/driver/core/file/GcsStorage.scala
@@ -52,24 +52,30 @@ class GcsStorage(storageClient: Storage, bucketName: Name[Bucket], executionCont
storageClient.delete(BlobId.of(bucketName.value, filePath.toString))
}
- override def list(path: Path): ListT[Future, FileLink] =
+ override def list(directoryPath: Path): ListT[Future, FileLink] =
ListT.listT(Future {
val page = storageClient.list(
bucketName.value,
BlobListOption.currentDirectory(),
- BlobListOption.prefix(path.toString)
+ BlobListOption.prefix(s"$directoryPath/")
)
- page.iterateAll().asScala.map(blobToFileLink(path, _)).toList
+ page.iterateAll().asScala.map(blobToFileLink(directoryPath, _)).toList
})
protected def blobToFileLink(path: Path, blob: Blob): FileLink = {
+ def nullError(property: String) = throw new IllegalStateException(s"Blob $blob at $path does not have $property")
+ val name = Option(blob.getName).getOrElse(nullError("a name"))
+ val generation = Option(blob.getGeneration).getOrElse(nullError("a generation"))
+ val updateTime = Option(blob.getUpdateTime).getOrElse(nullError("an update time"))
+ val size = Option(blob.getSize).getOrElse(nullError("a size"))
+
FileLink(
- Name(blob.getName),
- Paths.get(path.toString, blob.getName),
- Revision(blob.getGeneration.toString),
- Time(blob.getUpdateTime),
- blob.getSize
+ Name(name),
+ Paths.get(path.toString, name),
+ Revision(generation.toString),
+ Time(updateTime),
+ size
)
}
diff --git a/src/main/scala/xyz/driver/core/file/package.scala b/src/main/scala/xyz/driver/core/file/package.scala
index 9000894..7203207 100644
--- a/src/main/scala/xyz/driver/core/file/package.scala
+++ b/src/main/scala/xyz/driver/core/file/package.scala
@@ -37,7 +37,8 @@ package file {
def delete(filePath: Path): Future[Unit]
- def list(path: Path): ListT[Future, FileLink]
+ /** List contents of a directory */
+ def list(directoryPath: Path): ListT[Future, FileLink]
/** List of characters to avoid in S3 (I would say file names in general)
*
diff --git a/src/test/scala/xyz/driver/core/FileTest.scala b/src/test/scala/xyz/driver/core/FileTest.scala
index a1b0329..c35eb5b 100644
--- a/src/test/scala/xyz/driver/core/FileTest.scala
+++ b/src/test/scala/xyz/driver/core/FileTest.scala
@@ -150,8 +150,7 @@ class FileTest extends FlatSpec with Matchers with MockitoSugar {
Iterator[Blob](blobMock).asJava,
Iterator[Blob]().asJava
)
- when(
- gcsMock.list(testBucket.value, BlobListOption.currentDirectory(), BlobListOption.prefix(testDirPath.toString)))
+ when(gcsMock.list(testBucket.value, BlobListOption.currentDirectory(), BlobListOption.prefix(s"$testDirPath/")))
.thenReturn(pageMock)
val filesBefore = Await.result(gcsStorage.list(testDirPath).run, 10 seconds)