Simplify pack building and remove obsolete address fallback

This commit is contained in:
2026-09-13 23:17:48 +03:00
parent b439007f7f
commit bcd1a75a19
5 changed files with 43 additions and 17 deletions
@@ -16,6 +16,7 @@ import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HexFormat;
import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -75,12 +76,8 @@ public final class PackBuilder {
throws IOException {
// Shared with server-side exporters (AstraPlus). A build must see one complete asset
// generation.
String lock =
"AstraPacks:contents:"
+ contents.toAbsolutePath()
.normalize()
.toString()
.toLowerCase(java.util.Locale.ROOT);
Path directory = contents.toAbsolutePath().normalize();
String lock = "AstraPacks:contents:" + directory.toString().toLowerCase(Locale.ROOT);
synchronized (lock.intern()) {
return writeLockedArchive(contents, target, resourceVersion);
}
@@ -90,6 +87,8 @@ public final class PackBuilder {
throws IOException {
int files = 0;
long totalBytes = 0;
long maxFileBytes = config.build.maxFileMiB * 1024L * 1024L;
long maxTotalBytes = config.build.maxTotalMiB * 1024L * 1024L;
try (var paths = Files.walk(contents);
var zip =
new ZipOutputStream(
@@ -115,10 +114,8 @@ public final class PackBuilder {
ZipEntry entry = new ZipEntry(name);
entry.setTime(0);
zip.putNextEntry(entry);
long limit =
Math.min(
config.build.maxFileMiB * 1024L * 1024L,
config.build.maxTotalMiB * 1024L * 1024L - totalBytes);
long availableBytes = maxTotalBytes - totalBytes;
long limit = Math.min(maxFileBytes, availableBytes);
totalBytes += copyResource(file, zip, limit);
zip.closeEntry();
}
@@ -91,10 +91,6 @@ public final class PackConfig {
if (config == null) {
throw new IllegalArgumentException("Empty config");
}
// Old automatic addressing is no longer supported; leave it for the owner to set.
if (config.hosting != null && "auto".equals(config.hosting.publicAddress)) {
config.hosting.publicAddress = "";
}
config.validate();
return config;
} catch (RuntimeException e) {
@@ -221,11 +221,11 @@ class PackCoreTest {
}
@Test
void legacyAutomaticAddressIsUnsetWithoutRewritingUserConfig() throws Exception {
void automaticAddressIsRejectedWithoutRewritingUserConfig() throws Exception {
Path path = root.resolve("astrapacks.json");
String legacy = "{\"hosting\":{\"mode\":\"simple_self_host\",\"publicAddress\":\"auto\"}}";
Files.writeString(path, legacy);
assertEquals("", PackConfig.load(path).hosting.publicAddress);
assertThrows(IOException.class, () -> PackConfig.load(path));
assertEquals(legacy, Files.readString(path));
}