aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlad <vlad@drivergrp.com>2016-08-25 12:32:30 -0700
committervlad <vlad@drivergrp.com>2016-08-25 12:32:30 -0700
commita39ab2cb0e19f84176513d7b1e145351c3ceef8b (patch)
tree9c69c2952b4c5569f09af3395036bdc86c9ace8a
parent9f1b85ce3e8798d59da8bb4805ec39a0f1dffe2d (diff)
downloaddriver-core-a39ab2cb0e19f84176513d7b1e145351c3ceef8b.tar.gz
driver-core-a39ab2cb0e19f84176513d7b1e145351c3ceef8b.tar.bz2
driver-core-a39ab2cb0e19f84176513d7b1e145351c3ceef8b.zip
Id generation within limits + File error logging fix
-rw-r--r--src/main/scala/com/drivergrp/core/file.scala53
-rw-r--r--src/main/scala/com/drivergrp/core/generators.scala2
2 files changed, 28 insertions, 27 deletions
diff --git a/src/main/scala/com/drivergrp/core/file.scala b/src/main/scala/com/drivergrp/core/file.scala
index da46107..2c6a990 100644
--- a/src/main/scala/com/drivergrp/core/file.scala
+++ b/src/main/scala/com/drivergrp/core/file.scala
@@ -62,19 +62,20 @@ object file {
}
}
- def download(filePath: Path): OptionT[Future, File] = OptionT.optionT(Future {
- val tempDir = System.getProperty("java.io.tmpdir")
- val randomFolderName = randomUUID().toString
- val tempDestinationFile = new File(Paths.get(tempDir, randomFolderName, filePath.toString).toString)
-
- if (!tempDestinationFile.getParentFile.mkdirs()) {
- throw new Exception(s"Failed to create temp directory to download file `$file`")
- } else {
- Option(s3.getObject(new GetObjectRequest(bucket, filePath.toString), tempDestinationFile)).map { _ =>
- tempDestinationFile
+ def download(filePath: Path): OptionT[Future, File] =
+ OptionT.optionT(Future {
+ val tempDir = System.getProperty("java.io.tmpdir")
+ val randomFolderName = randomUUID().toString
+ val tempDestinationFile = new File(Paths.get(tempDir, randomFolderName, filePath.toString).toString)
+
+ if (!tempDestinationFile.getParentFile.mkdirs()) {
+ throw new Exception(s"Failed to create temp directory to download file `$tempDestinationFile`")
+ } else {
+ Option(s3.getObject(new GetObjectRequest(bucket, filePath.toString), tempDestinationFile)).map { _ =>
+ tempDestinationFile
+ }
}
- }
- })
+ })
def delete(filePath: Path): Future[Unit] = Future {
s3.deleteObject(bucket, filePath.toString)
@@ -94,11 +95,10 @@ object file {
} flatMap { result =>
result.getObjectSummaries.asScala.toList.map { summary =>
val file = new File(summary.getKey)
- FileLink(
- Name[File](file.getName),
- Paths.get(file.getPath),
- Revision[File](summary.getETag),
- Time(summary.getLastModified.getTime))
+ FileLink(Name[File](file.getName),
+ Paths.get(file.getPath),
+ Revision[File](summary.getETag),
+ Time(summary.getLastModified.getTime))
} filterNot isInSubFolder(path)
} toList
})
@@ -123,9 +123,10 @@ object file {
}
}
- def download(filePath: Path): OptionT[Future, File] = OptionT.optionT(Future {
- Option(new File(filePath.toString)).filter(file => file.exists() && file.isFile)
- })
+ def download(filePath: Path): OptionT[Future, File] =
+ OptionT.optionT(Future {
+ Option(new File(filePath.toString)).filter(file => file.exists() && file.isFile)
+ })
def delete(filePath: Path): Future[Unit] = Future {
val file = new File(filePath.toString)
@@ -140,14 +141,12 @@ object file {
val file = new File(path.toString)
if (file.isDirectory) {
file.listFiles().toList.filter(_.isFile).map { file =>
- FileLink(
- Name[File](file.getName),
- Paths.get(file.getPath),
- Revision[File](file.hashCode.toString),
- Time(file.lastModified()))
+ FileLink(Name[File](file.getName),
+ Paths.get(file.getPath),
+ Revision[File](file.hashCode.toString),
+ Time(file.lastModified()))
}
- }
- else List.empty[FileLink]
+ } else List.empty[FileLink]
})
}
}
diff --git a/src/main/scala/com/drivergrp/core/generators.scala b/src/main/scala/com/drivergrp/core/generators.scala
index 86183a1..10df7db 100644
--- a/src/main/scala/com/drivergrp/core/generators.scala
+++ b/src/main/scala/com/drivergrp/core/generators.scala
@@ -18,6 +18,8 @@ object generators {
def nextId[T](): Id[T] = Id[T](scala.math.abs(nextLong()))
+ def nextId[T](maxValue: Int): Id[T] = Id[T](scala.math.abs(nextInt(maxValue).toLong))
+
def nextName[T](maxLength: Int = DefaultMaxLength): Name[T] = Name[T](nextString(maxLength))
def nextUuid() = java.util.UUID.randomUUID