[uploadselectionfilter] Extracted as trait

This commit is contained in:
Paul Campbell 2019-05-09 16:55:57 +01:00
parent 86a53bf712
commit 5090a78baa
2 changed files with 25 additions and 10 deletions

View file

@ -10,7 +10,10 @@ import net.kemitix.s3thorp.awssdk.S3Client
import scala.concurrent.Promise
class Sync(s3Client: S3Client) extends LocalFileStream with S3MetaDataEnricher {
class Sync(s3Client: S3Client)
extends LocalFileStream
with S3MetaDataEnricher
with UploadSelectionFilter {
override def objectHead(bucket: String, key: String)=
s3Client.objectHead(bucket, key)
@ -25,15 +28,6 @@ class Sync(s3Client: S3Client) extends LocalFileStream with S3MetaDataEnricher {
}
} yield ()
private def uploadRequiredFilter: Either[File, S3MetaData] => Stream[IO, File] = {
case Left(file) => Stream(file)
case Right(s3Metadata) =>
Stream.eval(for {
_ <- putStrLn(s"upload required: ${s3Metadata.localFile}")
//md5File(localFile)
//filter(localHash => options.force || localHash != metadataHash)
} yield s3Metadata.localFile)
}
private def performUpload: File => Stream[IO, Promise[Unit]] =
file => Stream.eval(for {
_ <- putStrLn(s"upload: $file")

View file

@ -0,0 +1,21 @@
package net.kemitix.s3thorp
import java.io.File
import fs2.Stream
import cats.effect.IO
import net.kemitix.s3thorp.Main.putStrLn
trait UploadSelectionFilter {
def uploadRequiredFilter: Either[File, S3MetaData] => Stream[IO, File] = {
case Left(file) => Stream(file)
case Right(s3Metadata) =>
Stream.eval(for {
_ <- putStrLn(s"upload required: ${s3Metadata.localFile}")
//md5File(localFile)
//filter(localHash => options.force || localHash != metadataHash)
} yield s3Metadata.localFile)
}
}