[sync] sketch out rest of sync process

This commit is contained in:
Paul Campbell 2019-05-06 22:07:23 +01:00
parent 294966759c
commit 2153f109aa

View file

@ -2,21 +2,21 @@ package net.kemitix.s3thorp
import java.nio.file.{DirectoryStream, Files, Path, Paths}
import scala.collection.JavaConverters._
import fs2.Stream
import cats.effect._
import Main.putStrLn
import fs2.Stream
import net.kemitix.s3thorp.Main.putStrLn
import scala.collection.JavaConverters._
import scala.concurrent.Promise
object Sync {
def apply(c: Config): IO[Unit] = for {
_ <- putStrLn(s"Bucket: ${c.bucket}, Prefix: ${c.prefix}, Source: ${c.source}")
_ <- {
// a stream of files in the source directory
val pathStream: Stream[IO, Path] = streamDirectoryPaths(Paths.get(c.source))
IO.unit
streamDirectoryPaths(Paths.get(c.source)).flatMap(
enrichWithS3MetaData).flatMap(
uploadRequiredFilter).flatMap(
performUpload).compile.drain
}
} yield ()
@ -43,4 +43,23 @@ object Sync {
flatMap(openDirectory).
flatMap(recurseIntoSubDirectories)
}
case class S3MetaData()
private def enrichWithS3MetaData: Path => Stream[IO, S3MetaData] = path => {
// HEAD(bucket, prefix, relative(path))
// create blank S3MetaData records (sealed trait?)
}
private def uploadRequiredFilter: S3MetaData => Stream[IO, Path] =
s3Metadata => {
//md5File(localFile)
//filter(localHash => options.force || localHash != metadataHash)
}
private def performUpload: Path => Stream[IO, Promise[Unit]] =
path => {
// upload
IO.unit
}
}