handle package update
This commit is contained in:
@@ -74,7 +74,6 @@ proc newDownloadPanel(parent : Element) : DownloadPanel =
|
|||||||
let tf= document.createElement("input")
|
let tf= document.createElement("input")
|
||||||
tf.setAttribute("name", "pkgs")
|
tf.setAttribute("name", "pkgs")
|
||||||
let txt = sequtils.foldl(pkglist, a & " " & b)
|
let txt = sequtils.foldl(pkglist, a & " " & b)
|
||||||
echo txt
|
|
||||||
tf.value(txt)
|
tf.value(txt)
|
||||||
form.appendChild(tf)
|
form.appendChild(tf)
|
||||||
document.body.appendChild(form)
|
document.body.appendChild(form)
|
||||||
@@ -237,6 +236,7 @@ proc newPkgTable(parent: Element, searchString : string) : PkgTable =
|
|||||||
var arches : JsonNode
|
var arches : JsonNode
|
||||||
for v, a in versions:
|
for v, a in versions:
|
||||||
arches = a
|
arches = a
|
||||||
|
break
|
||||||
for arch, pkgname in arches:
|
for arch, pkgname in arches:
|
||||||
data.add(arch)
|
data.add(arch)
|
||||||
createDropdown(elem, data, size_change_callback)
|
createDropdown(elem, data, size_change_callback)
|
||||||
|
@@ -8,13 +8,12 @@ import java.util.zip.GZIPInputStream
|
|||||||
import net.woggioni.jpacrepo.exception.ParseException
|
import net.woggioni.jpacrepo.exception.ParseException
|
||||||
import net.woggioni.jpacrepo.pacbase.{CompressionFormat, PkgData, PkgId}
|
import net.woggioni.jpacrepo.pacbase.{CompressionFormat, PkgData, PkgId}
|
||||||
import net.woggioni.jpacrepo.utils.Utils._
|
import net.woggioni.jpacrepo.utils.Utils._
|
||||||
import net.woggioni.jwo.JWO
|
|
||||||
import net.woggioni.jzstd.ZstdInputStream
|
import net.woggioni.jzstd.ZstdInputStream
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
|
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
|
||||||
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream
|
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream
|
||||||
|
|
||||||
import scala.jdk.CollectionConverters._
|
|
||||||
import scala.io.Source
|
import scala.io.Source
|
||||||
|
import scala.jdk.CollectionConverters._
|
||||||
|
|
||||||
object Parser {
|
object Parser {
|
||||||
|
|
||||||
@@ -100,14 +99,14 @@ object Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.md5sum = Files.newInputStream(file).use(hasher.getHashString)
|
data.md5sum = Files.newInputStream(file).use(hasher.getHashString)
|
||||||
data.fileName = file.getFileName().toString
|
data.fileName = file.getFileName.toString
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
else {
|
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 {
|
} finally {
|
||||||
is.close()
|
is.close()
|
||||||
}
|
}
|
||||||
|
@@ -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 {
|
} catch {
|
||||||
case _: NoResultException =>
|
case _: NoResultException =>
|
||||||
throw new NotFoundException
|
throw new NotFoundException
|
||||||
@@ -344,31 +344,35 @@ class PacmanWebService {
|
|||||||
val savedFiles: util.List[PkgData] = fquery.getResultList
|
val savedFiles: util.List[PkgData] = fquery.getResultList
|
||||||
if (savedFiles.size > 0) Response.notModified.build
|
if (savedFiles.size > 0) Response.notModified.build
|
||||||
else {
|
else {
|
||||||
val fos: OutputStream = Files.newOutputStream(file)
|
Files.newOutputStream(file).useCatch { os =>
|
||||||
try {
|
|
||||||
val buffer: Array[Byte] = new Array[Byte](0x1000)
|
val buffer: Array[Byte] = new Array[Byte](0x1000)
|
||||||
var read = 0
|
var read = 0
|
||||||
while ( {
|
while ( {
|
||||||
read = input.read(buffer)
|
read = input.read(buffer)
|
||||||
read >= 0
|
read >= 0
|
||||||
}) {
|
}) {
|
||||||
fos.write(buffer, 0, read)
|
os.write(buffer, 0, read)
|
||||||
}
|
}
|
||||||
val pkg = Parser.parseFile(file, CompressionFormat.guess(Paths.get(filename)))
|
val pkg = Parser.parseFile(file, CompressionFormat.guess(Paths.get(filename)))
|
||||||
pkg.fileName = 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}")
|
log.info(s"Persisting package ${pkg.fileName}")
|
||||||
|
em.persist(pkg)
|
||||||
val pkgUri: URI = uriInfo.getAbsolutePathBuilder.path(pkg.fileName).build()
|
val pkgUri: URI = uriInfo.getAbsolutePathBuilder.path(pkg.fileName).build()
|
||||||
Files.move(file, ctx.repoFolder.resolve(filename), ATOMIC_MOVE)
|
Files.move(file, ctx.repoFolder.resolve(filename), ATOMIC_MOVE)
|
||||||
ctx.invalidateCache.set(true)
|
ctx.invalidateCache.set(true)
|
||||||
cachedMap = null
|
cachedMap = null
|
||||||
Response.created(pkgUri).build
|
Response.created(pkgUri).build
|
||||||
} catch {
|
} { t: Throwable =>
|
||||||
case e: Exception =>
|
|
||||||
Files.delete(file)
|
Files.delete(file)
|
||||||
throw e
|
throw t
|
||||||
} finally {
|
|
||||||
fos.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,16 @@ package net.woggioni.jpacrepo.utils
|
|||||||
object Utils {
|
object Utils {
|
||||||
|
|
||||||
implicit class Use[CLOSEABLE <: AutoCloseable, RESULT](closeable: CLOSEABLE) {
|
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 = {
|
def use(cb: CLOSEABLE => RESULT): RESULT = {
|
||||||
try {
|
try {
|
||||||
cb(closeable)
|
cb(closeable)
|
||||||
|
@@ -4,6 +4,7 @@ import lombok.SneakyThrows;
|
|||||||
import net.woggioni.jpacrepo.model.Hasher;
|
import net.woggioni.jpacrepo.model.Hasher;
|
||||||
import net.woggioni.jpacrepo.model.MD5InputStream;
|
import net.woggioni.jpacrepo.model.MD5InputStream;
|
||||||
import net.woggioni.jpacrepo.model.Parser;
|
import net.woggioni.jpacrepo.model.Parser;
|
||||||
|
import net.woggioni.jpacrepo.pacbase.CompressionFormat;
|
||||||
import net.woggioni.jpacrepo.pacbase.PkgData;
|
import net.woggioni.jpacrepo.pacbase.PkgData;
|
||||||
import net.woggioni.jpacrepo.service.PacmanServiceRemote;
|
import net.woggioni.jpacrepo.service.PacmanServiceRemote;
|
||||||
import net.woggioni.jwo.JWO;
|
import net.woggioni.jwo.JWO;
|
||||||
@@ -19,6 +20,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.security.DigestInputStream;
|
import java.security.DigestInputStream;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@@ -102,7 +104,8 @@ public class ClientTest {
|
|||||||
h.read(out, 0, (int) a);
|
h.read(out, 0, (int) a);
|
||||||
System.out.println(h.digest());
|
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());
|
System.out.println(p.md5sum());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ class MarshalTest extends AnyFlatSpec {
|
|||||||
.filter(Files.isRegularFile(_))
|
.filter(Files.isRegularFile(_))
|
||||||
.filter((p: Path) => pattern.matcher(p.getFileName.toString).matches)
|
.filter((p: Path) => pattern.matcher(p.getFileName.toString).matches)
|
||||||
.limit(10)
|
.limit(10)
|
||||||
.map(Parser.parseFile)
|
.map(Parser.parseFile(_, CompressionFormat.Z_STANDARD))
|
||||||
.collect(Collectors.toList[PkgData])
|
.collect(Collectors.toList[PkgData])
|
||||||
val list = new PkgDataList(pkgDatas)
|
val list = new PkgDataList(pkgDatas)
|
||||||
mar.marshal(list, System.out)
|
mar.marshal(list, System.out)
|
||||||
|
@@ -9,6 +9,14 @@ import scala.collection.mutable
|
|||||||
|
|
||||||
class ExampleSpec extends AnyFlatSpec with Matchers {
|
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 {
|
// "A Stack" should "pop values in last-in-first-out order" in {
|
||||||
// val stack = new mutable.Stack[Int]
|
// val stack = new mutable.Stack[Int]
|
||||||
// stack.push(1)
|
// stack.push(1)
|
||||||
@@ -25,7 +33,6 @@ class ExampleSpec extends AnyFlatSpec with Matchers {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
"sdfgf" should "dfgfd" in {
|
"sdfgf" should "dfgfd" in {
|
||||||
val initial = InitialSchemaAction("none")
|
foo(a=5)()
|
||||||
println(initial)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user