handle package update

This commit is contained in:
2020-05-10 10:43:11 +01:00
parent ab082860c9
commit 5362e83118
7 changed files with 47 additions and 24 deletions

View File

@@ -74,7 +74,6 @@ proc newDownloadPanel(parent : Element) : DownloadPanel =
let tf= document.createElement("input")
tf.setAttribute("name", "pkgs")
let txt = sequtils.foldl(pkglist, a & " " & b)
echo txt
tf.value(txt)
form.appendChild(tf)
document.body.appendChild(form)
@@ -237,6 +236,7 @@ proc newPkgTable(parent: Element, searchString : string) : PkgTable =
var arches : JsonNode
for v, a in versions:
arches = a
break
for arch, pkgname in arches:
data.add(arch)
createDropdown(elem, data, size_change_callback)

View File

@@ -8,13 +8,12 @@ import java.util.zip.GZIPInputStream
import net.woggioni.jpacrepo.exception.ParseException
import net.woggioni.jpacrepo.pacbase.{CompressionFormat, PkgData, PkgId}
import net.woggioni.jpacrepo.utils.Utils._
import net.woggioni.jwo.JWO
import net.woggioni.jzstd.ZstdInputStream
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream
import scala.jdk.CollectionConverters._
import scala.io.Source
import scala.jdk.CollectionConverters._
object Parser {
@@ -100,14 +99,14 @@ object Parser {
}
}
data.md5sum = Files.newInputStream(file).use(hasher.getHashString)
data.fileName = file.getFileName().toString
data.fileName = file.getFileName.toString
return data
}
else {
archiveEntry = is.getNextEntry()
archiveEntry = is.getNextEntry
}
}
throw new ParseException(s".PKGINFO file not found in '${file}'")
throw new ParseException(s".PKGINFO file not found in '$file'")
} finally {
is.close()
}

View File

@@ -47,7 +47,7 @@ class PkgDataList extends util.ArrayList[PkgData] {
l.forEach(el => add(el))
}
def this(elements : PkgData*) {
def this(elements: PkgData*) {
this()
elements.foreach(el => add(el))
}
@@ -69,12 +69,12 @@ class StringList extends util.ArrayList[String] {
l.forEach(el => add(el))
}
def this(elements : String*) {
def this(elements: String*) {
this()
elements.foreach(el => add(el))
}
def this(elements : Iterable[String]) {
def this(elements: Iterable[String]) {
this()
elements.foreach(el => add(el))
}
@@ -305,7 +305,7 @@ class PacmanWebService {
}
()
}
return Response.ok(stream).header("Content-Length", Files.size(ctx.getFile(pkg))).build
Response.ok(stream).header("Content-Length", Files.size(ctx.getFile(pkg))).build
} catch {
case _: NoResultException =>
throw new NotFoundException
@@ -344,31 +344,35 @@ class PacmanWebService {
val savedFiles: util.List[PkgData] = fquery.getResultList
if (savedFiles.size > 0) Response.notModified.build
else {
val fos: OutputStream = Files.newOutputStream(file)
try {
Files.newOutputStream(file).useCatch { os =>
val buffer: Array[Byte] = new Array[Byte](0x1000)
var read = 0
while ( {
read = input.read(buffer)
read >= 0
}) {
fos.write(buffer, 0, read)
os.write(buffer, 0, read)
}
val pkg = Parser.parseFile(file, CompressionFormat.guess(Paths.get(filename)))
pkg.fileName = filename
em.persist(pkg)
Option(em.find(classOf[PkgData], pkg.id)) match {
case Some(pkgData) => {
em.remove(pkgData)
Files.delete(ctx.repoFolder.resolve(pkgData.fileName))
}
case None =>
}
log.info(s"Persisting package ${pkg.fileName}")
em.persist(pkg)
val pkgUri: URI = uriInfo.getAbsolutePathBuilder.path(pkg.fileName).build()
Files.move(file, ctx.repoFolder.resolve(filename), ATOMIC_MOVE)
ctx.invalidateCache.set(true)
cachedMap = null
Response.created(pkgUri).build
} catch {
case e: Exception =>
Files.delete(file)
throw e
} finally {
fos.close()
} { t: Throwable =>
Files.delete(file)
throw t
}
}
}

View File

@@ -3,6 +3,16 @@ package net.woggioni.jpacrepo.utils
object Utils {
implicit class Use[CLOSEABLE <: AutoCloseable, RESULT](closeable: CLOSEABLE) {
def useCatch(cb: CLOSEABLE => RESULT) (exceptionally : Throwable => RESULT): RESULT = {
try {
cb(closeable)
} catch {
case t : Throwable => exceptionally(t)
} finally {
closeable.close()
}
}
def use(cb: CLOSEABLE => RESULT): RESULT = {
try {
cb(closeable)

View File

@@ -4,6 +4,7 @@ import lombok.SneakyThrows;
import net.woggioni.jpacrepo.model.Hasher;
import net.woggioni.jpacrepo.model.MD5InputStream;
import net.woggioni.jpacrepo.model.Parser;
import net.woggioni.jpacrepo.pacbase.CompressionFormat;
import net.woggioni.jpacrepo.pacbase.PkgData;
import net.woggioni.jpacrepo.service.PacmanServiceRemote;
import net.woggioni.jwo.JWO;
@@ -19,6 +20,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.DigestInputStream;
import java.security.MessageDigest;
@@ -102,7 +104,8 @@ public class ClientTest {
h.read(out, 0, (int) a);
System.out.println(h.digest());
PkgData p = Parser.parseFile(Paths.get(file));
Path path = Paths.get(file);
PkgData p = Parser.parseFile(path, CompressionFormat.guess(path));
System.out.println(p.md5sum());
}

View File

@@ -40,7 +40,7 @@ class MarshalTest extends AnyFlatSpec {
.filter(Files.isRegularFile(_))
.filter((p: Path) => pattern.matcher(p.getFileName.toString).matches)
.limit(10)
.map(Parser.parseFile)
.map(Parser.parseFile(_, CompressionFormat.Z_STANDARD))
.collect(Collectors.toList[PkgData])
val list = new PkgDataList(pkgDatas)
mar.marshal(list, System.out)

View File

@@ -9,6 +9,14 @@ import scala.collection.mutable
class ExampleSpec extends AnyFlatSpec with Matchers {
def foo(a : Int)(b : String = "walter"): Unit = {
println(s"a: $a, b: $b")
}
def foo(c : Int): Unit = {
foo(a=c)("adfsda")
}
// "A Stack" should "pop values in last-in-first-out order" in {
// val stack = new mutable.Stack[Int]
// stack.push(1)
@@ -25,7 +33,6 @@ class ExampleSpec extends AnyFlatSpec with Matchers {
// }
"sdfgf" should "dfgfd" in {
val initial = InitialSchemaAction("none")
println(initial)
foo(a=5)()
}
}