[sync] Convert to a class

This commit is contained in:
Paul Campbell 2019-05-08 07:06:58 +01:00
parent c5044e2ff7
commit ae3243ad21
2 changed files with 23 additions and 14 deletions

View file

@ -12,11 +12,13 @@ object Main extends IOApp {
val defaultConfig: Config = val defaultConfig: Config =
Config("(none)", "", Paths.get(".").toFile) Config("(none)", "", Paths.get(".").toFile)
val sync = new Sync()
def program(args: List[String]): IO[ExitCode] = def program(args: List[String]): IO[ExitCode] =
for { for {
_ <- putStrLn("S3Thorp - hashed sync for s3") _ <- putStrLn("S3Thorp - hashed sync for s3")
a <- ParseArgs(args, defaultConfig) a <- ParseArgs(args, defaultConfig)
_ <- Sync(a) _ <- sync.run(a)
} yield ExitCode.Success } yield ExitCode.Success
override def run(args: List[String]): IO[ExitCode] = override def run(args: List[String]): IO[ExitCode] =

View file

@ -7,11 +7,15 @@ import java.time.Instant
import cats.effect._ import cats.effect._
import fs2.Stream import fs2.Stream
import net.kemitix.s3thorp.Main.putStrLn import net.kemitix.s3thorp.Main.putStrLn
import net.kemitix.s3thorp.Sync.{Hash, LastModified}
import scala.concurrent.Promise import scala.concurrent.Promise
object Sync extends LocalFileStream with S3MetaDataEnricher { class Sync extends LocalFileStream with S3MetaDataEnricher {
def apply(c: Config): IO[Unit] = for {
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}") _ <- putStrLn(s"Bucket: ${c.bucket}, Prefix: ${c.prefix}, Source: ${c.source}")
_ <- { _ <- {
streamDirectoryPaths(c.source).flatMap( streamDirectoryPaths(c.source).flatMap(
@ -21,17 +25,11 @@ object Sync extends LocalFileStream with S3MetaDataEnricher {
} }
} yield () } 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 { private def uploadRequiredFilter: S3MetaData => Stream[IO, File] = s3Metadata => Stream.eval(for {
_ <- putStrLn(s"upload required: ${s3Metadata.localFile}") _ <- putStrLn(s"upload required: ${s3Metadata.localFile}")
//md5File(localFile) //md5File(localFile)
//filter(localHash => options.force || localHash != metadataHash) //filter(localHash => options.force || localHash != metadataHash)
} yield s3Metadata.localFile) } yield s3Metadata.localFile)
private def performUpload: File => Stream[IO, Promise[Unit]] = private def performUpload: File => Stream[IO, Promise[Unit]] =
file => Stream.eval(for { file => Stream.eval(for {
@ -40,5 +38,14 @@ object Sync extends LocalFileStream with S3MetaDataEnricher {
p = Promise[Unit]() p = Promise[Unit]()
} yield p) } 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
} }