From a749b1f5b0971d4de8515375bc7abc21077865bc Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 30 Jul 2019 15:30:12 +0100 Subject: [PATCH] [filesystem] Merge FS object into FileSystem object (#139) --- .../thorp/config/ParseConfigFile.scala | 7 ++++--- .../kemitix/thorp/core/MD5HashGenerator.scala | 5 +++-- .../scala/net/kemitix/thorp/core/Remote.scala | 4 ++-- .../net/kemitix/thorp/filesystem/FS.scala | 19 ------------------- .../kemitix/thorp/filesystem/FileSystem.scala | 10 ++++++++++ 5 files changed, 19 insertions(+), 26 deletions(-) delete mode 100644 filesystem/src/main/scala/net/kemitix/thorp/filesystem/FS.scala diff --git a/config/src/main/scala/net/kemitix/thorp/config/ParseConfigFile.scala b/config/src/main/scala/net/kemitix/thorp/config/ParseConfigFile.scala index 38fd13d..f5bf968 100644 --- a/config/src/main/scala/net/kemitix/thorp/config/ParseConfigFile.scala +++ b/config/src/main/scala/net/kemitix/thorp/config/ParseConfigFile.scala @@ -2,7 +2,7 @@ package net.kemitix.thorp.config import java.nio.file.Path -import net.kemitix.thorp.filesystem.{FS, FileSystem} +import net.kemitix.thorp.filesystem.FileSystem import zio.{IO, ZIO} trait ParseConfigFile { @@ -16,9 +16,10 @@ trait ParseConfigFile { List(ConfigValidation.ErrorReadingFile(filename, h.getMessage)))) private def readFile(filename: Path) = - FS.exists(filename.toFile) + FileSystem + .exists(filename.toFile) .flatMap( - if (_) FS.lines(filename.toFile) + if (_) FileSystem.lines(filename.toFile) else ZIO.succeed(List.empty)) } diff --git a/core/src/main/scala/net/kemitix/thorp/core/MD5HashGenerator.scala b/core/src/main/scala/net/kemitix/thorp/core/MD5HashGenerator.scala index 3539d3b..822d10c 100644 --- a/core/src/main/scala/net/kemitix/thorp/core/MD5HashGenerator.scala +++ b/core/src/main/scala/net/kemitix/thorp/core/MD5HashGenerator.scala @@ -5,7 +5,7 @@ import java.nio.file.Path import java.security.MessageDigest import net.kemitix.thorp.domain.MD5Hash -import net.kemitix.thorp.filesystem.{FS, FileSystem} +import net.kemitix.thorp.filesystem.FileSystem import zio.{Task, TaskR} import scala.collection.immutable.NumericRange @@ -48,7 +48,8 @@ object MD5HashGenerator { offset: Long, endOffset: Long ) = - FS.open(file, offset) + FileSystem + .open(file, offset) .flatMap { managedFileInputStream => managedFileInputStream.use { fileInputStream => digestFile(fileInputStream, offset, endOffset) diff --git a/core/src/main/scala/net/kemitix/thorp/core/Remote.scala b/core/src/main/scala/net/kemitix/thorp/core/Remote.scala index b6244bf..e9902d6 100644 --- a/core/src/main/scala/net/kemitix/thorp/core/Remote.scala +++ b/core/src/main/scala/net/kemitix/thorp/core/Remote.scala @@ -3,7 +3,7 @@ package net.kemitix.thorp.core import java.nio.file.Path import net.kemitix.thorp.domain.{RemoteKey, Sources} -import net.kemitix.thorp.filesystem.{FS, FileSystem} +import net.kemitix.thorp.filesystem.FileSystem import zio.{TaskR, ZIO} object Remote { @@ -19,7 +19,7 @@ object Remote { ): TaskR[FileSystem, Boolean] = { def existsInSource(source: Path) = remoteKey.asFile(source, prefix) match { - case Some(file) => FS.exists(file) + case Some(file) => FileSystem.exists(file) case None => ZIO.succeed(false) } ZIO diff --git a/filesystem/src/main/scala/net/kemitix/thorp/filesystem/FS.scala b/filesystem/src/main/scala/net/kemitix/thorp/filesystem/FS.scala deleted file mode 100644 index 06a8087..0000000 --- a/filesystem/src/main/scala/net/kemitix/thorp/filesystem/FS.scala +++ /dev/null @@ -1,19 +0,0 @@ -package net.kemitix.thorp.filesystem - -import java.io.{File, FileInputStream} - -import zio.{TaskR, ZIO, ZManaged} - -object FS { - - final def exists(file: File): ZIO[FileSystem, Throwable, Boolean] = - ZIO.accessM(_.filesystem fileExists file) - - final def open(file: File, offset: Long = 0) - : TaskR[FileSystem, ZManaged[FileSystem, Throwable, FileInputStream]] = - ZIO.accessM(_.filesystem openManagedFileInputStream (file, offset)) - - final def lines(file: File): TaskR[FileSystem, List[String]] = - ZIO.accessM(_.filesystem fileLines (file)) - -} diff --git a/filesystem/src/main/scala/net/kemitix/thorp/filesystem/FileSystem.scala b/filesystem/src/main/scala/net/kemitix/thorp/filesystem/FileSystem.scala index df13978..552e677 100644 --- a/filesystem/src/main/scala/net/kemitix/thorp/filesystem/FileSystem.scala +++ b/filesystem/src/main/scala/net/kemitix/thorp/filesystem/FileSystem.scala @@ -76,4 +76,14 @@ object FileSystem { fileLinesResult } } + + final def exists(file: File): ZIO[FileSystem, Throwable, Boolean] = + ZIO.accessM(_.filesystem fileExists file) + + final def open(file: File, offset: Long = 0) + : TaskR[FileSystem, ZManaged[FileSystem, Throwable, FileInputStream]] = + ZIO.accessM(_.filesystem openManagedFileInputStream (file, offset)) + + final def lines(file: File): TaskR[FileSystem, List[String]] = + ZIO.accessM(_.filesystem fileLines (file)) }