diff options
author | Jakob Odersky <jakob@driver.xyz> | 2017-06-21 15:06:20 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@driver.xyz> | 2017-06-21 16:40:27 -0700 |
commit | e41050b75308aab2736eea11b67bf9387a90dfe5 (patch) | |
tree | 4138f96ec7381b54c1339cb6577198ae067486e3 /src/main/scala/xyz/driver/core/file/S3Storage.scala | |
parent | c5bc3df97dd7670d6271efe440068b44f6521562 (diff) | |
download | driver-core-e41050b75308aab2736eea11b67bf9387a90dfe5.tar.gz driver-core-e41050b75308aab2736eea11b67bf9387a90dfe5.tar.bz2 driver-core-e41050b75308aab2736eea11b67bf9387a90dfe5.zip |
Add file existence checking to file storagev0.13.15
Diffstat (limited to 'src/main/scala/xyz/driver/core/file/S3Storage.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/file/S3Storage.scala | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/main/scala/xyz/driver/core/file/S3Storage.scala b/src/main/scala/xyz/driver/core/file/S3Storage.scala index 933b01a..7df3db2 100644 --- a/src/main/scala/xyz/driver/core/file/S3Storage.scala +++ b/src/main/scala/xyz/driver/core/file/S3Storage.scala @@ -15,13 +15,13 @@ import scalaz.{ListT, OptionT} class S3Storage(s3: AmazonS3, bucket: Name[Bucket], executionContext: ExecutionContext) extends FileStorage { implicit private val execution = executionContext - def upload(localSource: File, destination: Path): Future[Unit] = Future { + override def upload(localSource: File, destination: Path): Future[Unit] = Future { checkSafeFileName(destination) { val _ = s3.putObject(bucket.value, destination.toString, localSource).getETag } } - def download(filePath: Path): OptionT[Future, File] = + override def download(filePath: Path): OptionT[Future, File] = OptionT.optionT(Future { val tempDir = System.getProperty("java.io.tmpdir") val randomFolderName = randomUUID().toString @@ -36,11 +36,11 @@ class S3Storage(s3: AmazonS3, bucket: Name[Bucket], executionContext: ExecutionC } }) - def delete(filePath: Path): Future[Unit] = Future { + override def delete(filePath: Path): Future[Unit] = Future { s3.deleteObject(bucket.value, filePath.toString) } - def list(path: Path): ListT[Future, FileLink] = + override def list(path: Path): ListT[Future, FileLink] = ListT.listT(Future { import scala.collection.JavaConverters._ val req = new ListObjectsV2Request().withBucketName(bucket.value).withPrefix(path.toString).withMaxKeys(2) @@ -63,4 +63,9 @@ class S3Storage(s3: AmazonS3, bucket: Name[Bucket], executionContext: ExecutionC } filterNot isInSubFolder(path) } toList }) + + override def exists(path: Path): Future[Boolean] = Future { + s3.doesObjectExist(bucket.value, path.toString) + } + } |