[filesystem] Merge FS object into FileSystem object (#139)
This commit is contained in:
parent
e5de73e705
commit
a749b1f5b0
5 changed files with 19 additions and 26 deletions
|
@ -2,7 +2,7 @@ package net.kemitix.thorp.config
|
||||||
|
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
import net.kemitix.thorp.filesystem.{FS, FileSystem}
|
import net.kemitix.thorp.filesystem.FileSystem
|
||||||
import zio.{IO, ZIO}
|
import zio.{IO, ZIO}
|
||||||
|
|
||||||
trait ParseConfigFile {
|
trait ParseConfigFile {
|
||||||
|
@ -16,9 +16,10 @@ trait ParseConfigFile {
|
||||||
List(ConfigValidation.ErrorReadingFile(filename, h.getMessage))))
|
List(ConfigValidation.ErrorReadingFile(filename, h.getMessage))))
|
||||||
|
|
||||||
private def readFile(filename: Path) =
|
private def readFile(filename: Path) =
|
||||||
FS.exists(filename.toFile)
|
FileSystem
|
||||||
|
.exists(filename.toFile)
|
||||||
.flatMap(
|
.flatMap(
|
||||||
if (_) FS.lines(filename.toFile)
|
if (_) FileSystem.lines(filename.toFile)
|
||||||
else ZIO.succeed(List.empty))
|
else ZIO.succeed(List.empty))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import java.nio.file.Path
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
|
|
||||||
import net.kemitix.thorp.domain.MD5Hash
|
import net.kemitix.thorp.domain.MD5Hash
|
||||||
import net.kemitix.thorp.filesystem.{FS, FileSystem}
|
import net.kemitix.thorp.filesystem.FileSystem
|
||||||
import zio.{Task, TaskR}
|
import zio.{Task, TaskR}
|
||||||
|
|
||||||
import scala.collection.immutable.NumericRange
|
import scala.collection.immutable.NumericRange
|
||||||
|
@ -48,7 +48,8 @@ object MD5HashGenerator {
|
||||||
offset: Long,
|
offset: Long,
|
||||||
endOffset: Long
|
endOffset: Long
|
||||||
) =
|
) =
|
||||||
FS.open(file, offset)
|
FileSystem
|
||||||
|
.open(file, offset)
|
||||||
.flatMap { managedFileInputStream =>
|
.flatMap { managedFileInputStream =>
|
||||||
managedFileInputStream.use { fileInputStream =>
|
managedFileInputStream.use { fileInputStream =>
|
||||||
digestFile(fileInputStream, offset, endOffset)
|
digestFile(fileInputStream, offset, endOffset)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package net.kemitix.thorp.core
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
import net.kemitix.thorp.domain.{RemoteKey, Sources}
|
import net.kemitix.thorp.domain.{RemoteKey, Sources}
|
||||||
import net.kemitix.thorp.filesystem.{FS, FileSystem}
|
import net.kemitix.thorp.filesystem.FileSystem
|
||||||
import zio.{TaskR, ZIO}
|
import zio.{TaskR, ZIO}
|
||||||
|
|
||||||
object Remote {
|
object Remote {
|
||||||
|
@ -19,7 +19,7 @@ object Remote {
|
||||||
): TaskR[FileSystem, Boolean] = {
|
): TaskR[FileSystem, Boolean] = {
|
||||||
def existsInSource(source: Path) =
|
def existsInSource(source: Path) =
|
||||||
remoteKey.asFile(source, prefix) match {
|
remoteKey.asFile(source, prefix) match {
|
||||||
case Some(file) => FS.exists(file)
|
case Some(file) => FileSystem.exists(file)
|
||||||
case None => ZIO.succeed(false)
|
case None => ZIO.succeed(false)
|
||||||
}
|
}
|
||||||
ZIO
|
ZIO
|
||||||
|
|
|
@ -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))
|
|
||||||
|
|
||||||
}
|
|
|
@ -76,4 +76,14 @@ object FileSystem {
|
||||||
fileLinesResult
|
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))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue