aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/file/GcsStorage.scala
diff options
context:
space:
mode:
authorvlad <vlad@driver.xyz>2017-06-29 20:19:30 -0700
committervlad <vlad@driver.xyz>2017-06-29 20:19:30 -0700
commit5013a7fde52e4459c12ff5e92793cad9fc2f23db (patch)
tree00be653526aac5b20ec528204b5dda4153becbfb /src/main/scala/xyz/driver/core/file/GcsStorage.scala
parent0e6a5d1dbaf02192cc5ad5ff6edbb793dc6a1287 (diff)
parente41050b75308aab2736eea11b67bf9387a90dfe5 (diff)
downloaddriver-core-5013a7fde52e4459c12ff5e92793cad9fc2f23db.tar.gz
driver-core-5013a7fde52e4459c12ff5e92793cad9fc2f23db.tar.bz2
driver-core-5013a7fde52e4459c12ff5e92793cad9fc2f23db.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/main/scala/xyz/driver/core/file/GcsStorage.scala')
-rw-r--r--src/main/scala/xyz/driver/core/file/GcsStorage.scala31
1 files changed, 23 insertions, 8 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..deb8a0e 100644
--- a/src/main/scala/xyz/driver/core/file/GcsStorage.scala
+++ b/src/main/scala/xyz/driver/core/file/GcsStorage.scala
@@ -52,27 +52,42 @@ 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
)
}
+ override def exists(path: Path): Future[Boolean] = Future {
+ val blob = Option(
+ storageClient.get(
+ bucketName.value,
+ path.toString
+ ))
+ blob.isDefined
+ }
+
override def signedFileUrl(filePath: Path, duration: Duration): OptionT[Future, URL] =
OptionT.optionT(Future {
Option(storageClient.get(bucketName.value, filePath.toString)).filterNot(_.getSize == 0).map { blob =>