From ae3243ad21ec591212fe3dca4ac35c5385ccecef Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 8 May 2019 07:06:58 +0100 Subject: [PATCH] [sync] Convert to a class --- src/main/scala/net/kemitix/s3thorp/Main.scala | 4 ++- src/main/scala/net/kemitix/s3thorp/Sync.scala | 33 +++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/scala/net/kemitix/s3thorp/Main.scala b/src/main/scala/net/kemitix/s3thorp/Main.scala index c2b9df7..757db0b 100644 --- a/src/main/scala/net/kemitix/s3thorp/Main.scala +++ b/src/main/scala/net/kemitix/s3thorp/Main.scala @@ -12,11 +12,13 @@ object Main extends IOApp { val defaultConfig: Config = Config("(none)", "", Paths.get(".").toFile) + val sync = new Sync() + def program(args: List[String]): IO[ExitCode] = for { _ <- putStrLn("S3Thorp - hashed sync for s3") a <- ParseArgs(args, defaultConfig) - _ <- Sync(a) + _ <- sync.run(a) } yield ExitCode.Success override def run(args: List[String]): IO[ExitCode] = diff --git a/src/main/scala/net/kemitix/s3thorp/Sync.scala b/src/main/scala/net/kemitix/s3thorp/Sync.scala index a3c8aae..7732aaa 100644 --- a/src/main/scala/net/kemitix/s3thorp/Sync.scala +++ b/src/main/scala/net/kemitix/s3thorp/Sync.scala @@ -7,11 +7,15 @@ import java.time.Instant import cats.effect._ import fs2.Stream import net.kemitix.s3thorp.Main.putStrLn +import net.kemitix.s3thorp.Sync.{Hash, LastModified} import scala.concurrent.Promise -object Sync extends LocalFileStream with S3MetaDataEnricher { - def apply(c: Config): IO[Unit] = for { +class Sync extends LocalFileStream with S3MetaDataEnricher { + + override def objectHead(bucket: String, key: String): (Hash, LastModified) = ??? + + def run(c: Config): IO[Unit] = for { _ <- putStrLn(s"Bucket: ${c.bucket}, Prefix: ${c.prefix}, Source: ${c.source}") _ <- { streamDirectoryPaths(c.source).flatMap( @@ -21,17 +25,11 @@ object Sync extends LocalFileStream with S3MetaDataEnricher { } } yield () - type Bucket = String // the S3 bucket name - type LocalFile = File // the file or directory - type RemotePath = String // path within an S3 bucket - type Hash = String // an MD5 hash - type LastModified = Instant // or scala equivalent - private def uploadRequiredFilter: S3MetaData => Stream[IO, File] = s3Metadata => Stream.eval(for { - _ <- putStrLn(s"upload required: ${s3Metadata.localFile}") - //md5File(localFile) - //filter(localHash => options.force || localHash != metadataHash) - } yield s3Metadata.localFile) + _ <- 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 { @@ -40,5 +38,14 @@ object Sync extends LocalFileStream with S3MetaDataEnricher { p = Promise[Unit]() } yield p) - override def objectHead(bucket: String, key: String): (Hash, LastModified) = ??? +} + +object Sync { + + type Bucket = String // the S3 bucket name + type LocalFile = File // the file or directory + type RemotePath = String // path within an S3 bucket + type Hash = String // an MD5 hash + type LastModified = Instant // or scala equivalent + }