mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Adopt deprecated APIs from fs2; use fs2.Path
This commit is contained in:
@ -6,11 +6,9 @@
|
||||
|
||||
package docspell.convert.extern
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import fs2.io.file.Files
|
||||
import fs2.io.file.{Files, Path}
|
||||
import fs2.{Pipe, Stream}
|
||||
|
||||
import docspell.common._
|
||||
@ -30,8 +28,8 @@ private[extern] object ExternConv {
|
||||
Stream
|
||||
.resource(File.withTempDir[F](wd, s"docspell-$name"))
|
||||
.flatMap { dir =>
|
||||
val inFile = dir.resolve("infile").toAbsolutePath.normalize
|
||||
val out = dir.resolve("out.pdf").toAbsolutePath.normalize
|
||||
val inFile = dir.resolve("infile").absolute.normalize
|
||||
val out = dir.resolve("out.pdf").absolute.normalize
|
||||
val sysCfg =
|
||||
cmdCfg.replace(
|
||||
Map(
|
||||
@ -77,7 +75,7 @@ private[extern] object ExternConv {
|
||||
)(out: Path, result: SystemCommand.Result): F[ConversionResult[F]] =
|
||||
File.existsNonEmpty[F](out).flatMap {
|
||||
case true if result.rc == 0 =>
|
||||
val outTxt = out.resolveSibling(out.getFileName.toString + ".txt")
|
||||
val outTxt = out.resolveSibling(out.fileName.toString + ".txt")
|
||||
File.existsNonEmpty[F](outTxt).flatMap {
|
||||
case true =>
|
||||
successPdfTxt(
|
||||
|
@ -6,10 +6,9 @@
|
||||
|
||||
package docspell.convert.extern
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
import cats.effect._
|
||||
import fs2.Stream
|
||||
import fs2.io.file.Path
|
||||
|
||||
import docspell.common._
|
||||
import docspell.convert.ConversionResult
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
package docspell.convert.extern
|
||||
|
||||
import java.nio.file.Path
|
||||
import fs2.io.file.Path
|
||||
|
||||
import docspell.common.SystemCommand
|
||||
|
||||
|
@ -6,10 +6,9 @@
|
||||
|
||||
package docspell.convert.extern
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
import cats.effect._
|
||||
import fs2.Stream
|
||||
import fs2.io.file.Path
|
||||
|
||||
import docspell.common._
|
||||
import docspell.convert.ConversionResult
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
package docspell.convert.extern
|
||||
|
||||
import java.nio.file.Path
|
||||
import fs2.io.file.Path
|
||||
|
||||
import docspell.common.SystemCommand
|
||||
|
||||
|
@ -6,10 +6,9 @@
|
||||
|
||||
package docspell.convert.extern
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
import cats.effect._
|
||||
import fs2.Stream
|
||||
import fs2.io.file.Path
|
||||
|
||||
import docspell.common._
|
||||
import docspell.convert.ConversionResult
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
package docspell.convert.extern
|
||||
|
||||
import java.nio.file.Path
|
||||
import fs2.io.file.Path
|
||||
|
||||
import docspell.common.SystemCommand
|
||||
|
||||
|
@ -7,10 +7,10 @@
|
||||
package docspell.convert.extern
|
||||
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.file.Path
|
||||
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import fs2.io.file.Path
|
||||
import fs2.{Chunk, Stream}
|
||||
|
||||
import docspell.common._
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
package docspell.convert.extern
|
||||
|
||||
import java.nio.file.Path
|
||||
import fs2.io.file.Path
|
||||
|
||||
import docspell.common.SystemCommand
|
||||
|
||||
|
@ -26,7 +26,7 @@ import munit._
|
||||
class ConversionTest extends FunSuite with FileChecks {
|
||||
|
||||
val logger = Logger.log4s[IO](org.log4s.getLogger)
|
||||
val target = Paths.get("target")
|
||||
val target = File.path(Paths.get("target"))
|
||||
|
||||
val convertConfig = ConvertConfig(
|
||||
8192,
|
||||
|
@ -7,14 +7,15 @@
|
||||
package docspell.convert
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.{Files, Path}
|
||||
import java.nio.file.Files
|
||||
|
||||
import cats.data.Kleisli
|
||||
import cats.effect.IO
|
||||
import cats.effect.unsafe.implicits.global
|
||||
import fs2.io.file.Path
|
||||
import fs2.{Pipe, Stream}
|
||||
|
||||
import docspell.common.MimeType
|
||||
import docspell.common._
|
||||
import docspell.convert.ConversionResult.Handler
|
||||
import docspell.files.TikaMimetype
|
||||
|
||||
@ -23,7 +24,7 @@ trait FileChecks {
|
||||
implicit class FileCheckOps(p: Path) {
|
||||
|
||||
def isNonEmpty: Boolean =
|
||||
Files.exists(p) && Files.size(p) > 0
|
||||
Files.exists(p.toNioPath) && Files.size(p.toNioPath) > 0
|
||||
|
||||
def isType(mime: MimeType): Boolean =
|
||||
TikaMimetype.detect[IO](p).map(_ == mime).unsafeRunSync()
|
||||
@ -36,7 +37,12 @@ trait FileChecks {
|
||||
}
|
||||
|
||||
def storeFile(file: Path): Pipe[IO, Byte, Path] =
|
||||
in => Stream.eval(in.compile.to(Array).flatMap(bytes => IO(Files.write(file, bytes))))
|
||||
in =>
|
||||
Stream
|
||||
.eval(
|
||||
in.compile.to(Array).flatMap(bytes => IO(Files.write(file.toNioPath, bytes)))
|
||||
)
|
||||
.map(p => File.path(p))
|
||||
|
||||
def storePdfHandler(file: Path): Handler[IO, Path] =
|
||||
storePdfTxtHandler(file, file.resolveSibling("unexpected.txt")).map(_._1)
|
||||
@ -47,8 +53,8 @@ trait FileChecks {
|
||||
for {
|
||||
pout <- pdf.through(storeFile(filePdf)).compile.lastOrError
|
||||
str <- txt
|
||||
tout <- IO(Files.write(fileTxt, str.getBytes(StandardCharsets.UTF_8)))
|
||||
} yield (pout, tout)
|
||||
tout <- IO(Files.write(fileTxt.toNioPath, str.getBytes(StandardCharsets.UTF_8)))
|
||||
} yield (pout, File.path(tout))
|
||||
|
||||
case ConversionResult.SuccessPdf(pdf) =>
|
||||
pdf.through(storeFile(filePdf)).compile.lastOrError.map(p => (p, fileTxt))
|
||||
|
@ -7,10 +7,11 @@
|
||||
package docspell.convert.extern
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.{Path, Paths}
|
||||
import java.nio.file.Paths
|
||||
|
||||
import cats.effect._
|
||||
import cats.effect.unsafe.implicits.global
|
||||
import fs2.io.file.Path
|
||||
|
||||
import docspell.common._
|
||||
import docspell.convert._
|
||||
@ -21,7 +22,7 @@ import munit._
|
||||
class ExternConvTest extends FunSuite with FileChecks {
|
||||
val utf8 = StandardCharsets.UTF_8
|
||||
val logger = Logger.log4s[IO](org.log4s.getLogger)
|
||||
val target = Paths.get("target")
|
||||
val target = File.path(Paths.get("target"))
|
||||
|
||||
test("convert html to pdf") {
|
||||
val cfg = SystemCommand.Config(
|
||||
|
Reference in New Issue
Block a user