Adopt deprecated APIs from fs2; use fs2.Path

This commit is contained in:
eikek
2021-08-07 12:20:38 +02:00
parent f92aeb6a0f
commit 1901fe1a8c
41 changed files with 124 additions and 109 deletions

View File

@ -29,7 +29,7 @@ object Binary {
Binary[F](
name,
MimeType.octetStream,
Stream.emit(content).through(fs2.text.utf8Encode)
Stream.emit(content).through(fs2.text.utf8.encode)
)
def text[F[_]](name: String, content: String): Binary[F] =
@ -46,7 +46,7 @@ object Binary {
def decode[F[_]](cs: Charset): Pipe[F, Byte, String] =
if (cs == StandardCharsets.UTF_8)
fs2.text.utf8Decode
fs2.text.utf8.decode
else
util.decode[F](cs)

View File

@ -6,14 +6,14 @@
package docspell.common
import java.nio.file.Path
import java.nio.file.{Path => JPath}
import cats.FlatMap
import cats.Monad
import cats.effect._
import cats.implicits._
import fs2.Stream
import fs2.io.file.Files
import fs2.io.file.{Files, Flags, Path}
import docspell.common.syntax.all._
@ -21,7 +21,9 @@ import io.circe.Decoder
object File {
def mkDir[F[_]: Files](dir: Path): F[Path] =
def path(jp: JPath): Path = Path.fromNioPath(jp)
def mkDir[F[_]: Files](dir: Path): F[Unit] =
Files[F].createDirectories(dir)
def exists[F[_]: Files](file: Path): F[Boolean] =
@ -37,31 +39,36 @@ object File {
for {
isDir <- Files[F].isDirectory(path)
_ <-
if (isDir) Files[F].deleteDirectoryRecursively(path)
if (isDir) Files[F].deleteRecursively(path)
else Files[F].deleteIfExists(path)
} yield ()
def withTempDir[F[_]: Files](parent: Path, prefix: String): Resource[F, Path] =
Resource
.eval(mkDir[F](parent))
.flatMap(_ => Files[F].tempDirectory(parent.some, prefix))
.flatMap(_ => Files[F].tempDirectory(parent.some, prefix, None))
def listFiles[F[_]: Files](pred: Path => Boolean, dir: Path): Stream[F, Path] =
Files[F].directoryStream(dir, pred)
Files[F].list(dir).filter(pred)
def readAll[F[_]: Files](
file: Path,
chunkSize: Int
): Stream[F, Byte] =
Files[F].readAll(file, chunkSize)
Files[F].readAll(file, chunkSize, Flags.Read)
def readAll[F[_]: Files](
file: Path
): Stream[F, Byte] =
Files[F].readAll(file)
def readText[F[_]: Files: Concurrent](file: Path): F[String] =
readAll[F](file, 8192).through(fs2.text.utf8Decode).compile.foldMonoid
readAll[F](file, 8192).through(fs2.text.utf8.decode).compile.foldMonoid
def writeString[F[_]: Files: Concurrent](file: Path, content: String): F[Path] =
Stream
.emit(content)
.through(fs2.text.utf8Encode)
.through(fs2.text.utf8.encode)
.through(Files[F].writeAll(file))
.compile
.drain

View File

@ -82,7 +82,7 @@ case class LenientUri(
)
def readText[F[_]: Sync](chunkSize: Int): F[String] =
readURL[F](chunkSize).through(fs2.text.utf8Decode).compile.foldMonoid
readURL[F](chunkSize).through(fs2.text.utf8.decode).compile.foldMonoid
def host: Option[String] =
authority.map(a =>

View File

@ -8,13 +8,13 @@ package docspell.common
import java.io.InputStream
import java.lang.ProcessBuilder.Redirect
import java.nio.file.Path
import java.util.concurrent.TimeUnit
import scala.jdk.CollectionConverters._
import cats.effect._
import cats.implicits._
import fs2.io.file.Path
import fs2.{Stream, io, text}
object SystemCommand {
@ -102,7 +102,7 @@ object SystemCommand {
.redirectError(Redirect.PIPE)
.redirectOutput(Redirect.PIPE)
wd.map(_.toFile).foreach(pb.directory)
wd.map(_.toNioPath.toFile).foreach(pb.directory)
pb.start()
}
)
@ -115,7 +115,7 @@ object SystemCommand {
private def inputStreamToString[F[_]: Sync](in: InputStream): F[String] =
io.readInputStream(Sync[F].pure(in), 16 * 1024, closeAfterUse = false)
.through(text.utf8Decode)
.through(text.utf8.decode)
.chunks
.map(_.toVector.mkString)
.fold1(_ + _)

View File

@ -6,8 +6,12 @@
package docspell.common.config
import java.nio.file.{Path => JPath}
import scala.reflect.ClassTag
import fs2.io.file.Path
import docspell.common._
import com.github.eikek.calev.CalEvent
@ -16,6 +20,10 @@ import pureconfig.error.{CannotConvert, FailureReason}
import scodec.bits.ByteVector
object Implicits {
implicit val pathReader: ConfigReader[Path] =
ConfigReader[JPath].map(Path.fromNioPath)
implicit val lenientUriReader: ConfigReader[LenientUri] =
ConfigReader[String].emap(reason(LenientUri.parse))

View File

@ -6,20 +6,17 @@
package docspell.common.syntax
import java.nio.file.Path
import fs2.io.file.Path
trait FileSyntax {
implicit final class PathOps(p: Path) {
def absolutePath: Path =
p.normalize().toAbsolutePath
p.absolute
def absolutePathAsString: String =
absolutePath.toString
def /(next: String): Path =
p.resolve(next)
}
}