From 4c1cf89d51f09bf33119556d504b8b115aa227fb Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 10 May 2019 08:52:39 +0100 Subject: [PATCH] Consistent logging format --- src/main/scala/net/kemitix/s3thorp/Config.scala | 5 +++++ .../net/kemitix/s3thorp/S3MetaDataEnricher.scala | 1 + .../scala/net/kemitix/s3thorp/S3Uploader.scala | 5 +++-- src/main/scala/net/kemitix/s3thorp/Sync.scala | 2 +- .../kemitix/s3thorp/UploadSelectionFilter.scala | 14 +++++++++++--- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/scala/net/kemitix/s3thorp/Config.scala b/src/main/scala/net/kemitix/s3thorp/Config.scala index 64610c5..91a2fc2 100644 --- a/src/main/scala/net/kemitix/s3thorp/Config.scala +++ b/src/main/scala/net/kemitix/s3thorp/Config.scala @@ -1,5 +1,8 @@ package net.kemitix.s3thorp +import java.io.File +import java.nio.file.Path + import net.kemitix.s3thorp.Sync.{Bucket, LocalFile} case class Config(bucket: Bucket = "", @@ -7,4 +10,6 @@ case class Config(bucket: Bucket = "", source: LocalFile ) { + def relativePath(file: File): Path = source.toPath.relativize(file.toPath) + } diff --git a/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala b/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala index 3737979..f92fdad 100644 --- a/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala +++ b/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala @@ -12,6 +12,7 @@ trait S3MetaDataEnricher extends S3Client with KeyGenerator { val remoteKey = generateKey(c)_ file => Stream.eval({ + println(s"- Consider: ${c.relativePath(file)}") val key = remoteKey(file) for { head <- objectHead(c.bucket, key) diff --git a/src/main/scala/net/kemitix/s3thorp/S3Uploader.scala b/src/main/scala/net/kemitix/s3thorp/S3Uploader.scala index fa18db4..d7d817b 100644 --- a/src/main/scala/net/kemitix/s3thorp/S3Uploader.scala +++ b/src/main/scala/net/kemitix/s3thorp/S3Uploader.scala @@ -15,10 +15,11 @@ trait S3Uploader val remoteKey = generateKey(c) _ file => { val key = remoteKey(file) - val shortFile = c.source.toPath.relativize(file.toPath) + val shortFile = c.relativePath(file) Stream.eval(for { - _ <- putStrLn(s"Uploading: $shortFile") + _ <- putStrLn(s" Upload: $shortFile") _ <- upload(file, c.bucket, key) + _ <- putStrLn(s" Done: $shortFile") } yield ()) } } diff --git a/src/main/scala/net/kemitix/s3thorp/Sync.scala b/src/main/scala/net/kemitix/s3thorp/Sync.scala index 528ad83..919c554 100644 --- a/src/main/scala/net/kemitix/s3thorp/Sync.scala +++ b/src/main/scala/net/kemitix/s3thorp/Sync.scala @@ -25,7 +25,7 @@ class Sync(s3Client: S3Client) _ <- { streamDirectoryPaths(c.source).flatMap( enrichWithS3MetaData(c)).flatMap( - uploadRequiredFilter).flatMap( + uploadRequiredFilter(c)).flatMap( performUpload(c)).compile.drain } } yield () diff --git a/src/main/scala/net/kemitix/s3thorp/UploadSelectionFilter.scala b/src/main/scala/net/kemitix/s3thorp/UploadSelectionFilter.scala index 4318d04..67c3d7b 100644 --- a/src/main/scala/net/kemitix/s3thorp/UploadSelectionFilter.scala +++ b/src/main/scala/net/kemitix/s3thorp/UploadSelectionFilter.scala @@ -18,14 +18,22 @@ trait UploadSelectionFilter { md5.digest.map("%02x".format(_)).mkString } - def uploadRequiredFilter: Either[File, S3MetaData] => Stream[IO, File] = { - case Left(file) => Stream(file) + def uploadRequiredFilter(c: Config): Either[File, S3MetaData] => Stream[IO, File] = { + case Left(file) => { + println(s" Created: ${c.relativePath(file)}") + Stream(file) + } case Right(s3Metadata) => Stream.eval(for { localHash <- IO(md5File(s3Metadata.localFile)) } yield (s3Metadata.localFile, localHash)). filter { case (_, localHash) => localHash != s3Metadata.remoteHash }. - map {case (localFile,_) => localFile} + map { + case (localFile,_) => { + println(s" Updated: ${c.relativePath(localFile)}") + localFile + } + } } }