Skip to content

Commit

Permalink
Merge pull request #2660 from eikek/fix/2650-addon-extract
Browse files Browse the repository at this point in the history
FIx extracting addons with only a single file
  • Loading branch information
mergify[bot] authored May 27, 2024
2 parents 870bfd9 + 2ca492d commit 2bbeec6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ final case class AddonArchive(url: LenientUri, name: String, version: String) {
Files[F].createDirectories(target) *>
reader(url)
.through(Zip[F](logger.some).unzip(glob = glob, targetDir = target.some))
.evalTap(_ => Directory.unwrapSingle[F](logger, target))
.compile
.drain
.flatTap(_ => Directory.unwrapSingle[F](logger, target))
.as(target)
}
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package docspell.addons
import cats.effect._
import cats.syntax.option._

import docspell.common.UrlReader
import docspell.common._
import docspell.logging.TestLoggingConfig

import munit._
Expand Down Expand Up @@ -42,10 +42,20 @@ class AddonArchiveTest extends CatsEffectSuite with TestLoggingConfig with Fixtu
} yield ()
}

tempDir.test("read archive from zip with yaml only") { dir =>
for {
aa <- AddonArchive.read[IO](singleFileAddonUrl, UrlReader.defaultReader[IO], None)
_ = assertEquals(aa.version, "0.7.0")
path <- aa.extractTo(UrlReader.defaultReader[IO], dir)
read <- AddonArchive.read[IO](aa.url, UrlReader.defaultReader[IO], path.some)
_ = assertEquals(aa, read)
} yield ()
}

tempDir.test("Read generated addon from path") { dir =>
AddonGenerator.successAddon("mini-addon").use { addon =>
for {
archive <- IO(AddonArchive(addon.url, "", ""))
archive <- IO(AddonArchive(addon.url, "test-addon", "0.1.0"))
path <- archive.extractTo[IO](UrlReader.defaultReader[IO], dir)

read <- AddonArchive.read[IO](addon.url, UrlReader.defaultReader[IO], path.some)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ trait Fixtures extends TestLoggingConfig { self: CatsEffectSuite =>
val miniAddonUrl =
LenientUri.fromJava(getClass.getResource("/minimal-addon.zip"))

val singleFileAddonUrl =
LenientUri.fromJava(getClass.getResource("/docspell-addon-single-file.zip"))

val dummyAddonMeta =
AddonMeta(
meta =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package docspell.common.util

import cats.data.OptionT
import cats.effect._
import cats.syntax.all._
import cats.{Applicative, Monad}
Expand All @@ -26,10 +27,10 @@ object Directory {
(dir :: dirs.toList).traverse_(Files[F].createDirectories(_))

def nonEmpty[F[_]: Files: Sync](dir: Path): F[Boolean] =
List(
Files[F].isDirectory(dir),
Files[F].list(dir).take(1).compile.last.map(_.isDefined)
).sequence.map(_.forall(identity))
OptionT
.whenM(Files[F].isDirectory(dir))(Files[F].list(dir).take(1).compile.toList)
.map(_.nonEmpty)
.isDefined

def isEmpty[F[_]: Files: Sync](dir: Path): F[Boolean] =
nonEmpty(dir).map(b => !b)
Expand Down

0 comments on commit 2bbeec6

Please sign in to comment.