Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

#158 Permission Issue: Default Bootstrap Location #159

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/main/java/org/update4j/service/DefaultBootstrap.java
Expand Up @@ -42,10 +42,11 @@
import org.update4j.UpdateOptions;
import org.update4j.inject.InjectSource;
import org.update4j.util.ArgUtils;
import org.update4j.util.FileUtils;

public class DefaultBootstrap implements Delegate {

private static final String ZIP_LOCATION = "update.zip";
private static final Path ZIP_FILE_PATH = FileUtils.getTempPath().resolve("update4j.zip");
private static final String OLD_CONFIG = "config.old";

private String remote;
Expand Down Expand Up @@ -201,14 +202,13 @@ protected void updateFirst() throws Throwable {
}

Configuration config = remoteConfig != null ? remoteConfig : localConfig;
Path zip = Paths.get(ZIP_LOCATION);

boolean success = config.update(UpdateOptions.archive(zip).publicKey(pk)).getException() == null;
boolean success = config.update(UpdateOptions.archive(ZIP_FILE_PATH).publicKey(pk)).getException() == null;
if (!success && stopOnUpdateError)
return;

if (Files.exists(zip)) {
Archive.read(zip).install();
if (Files.exists(ZIP_FILE_PATH)) {
Archive.read(ZIP_FILE_PATH).install();
}

if (success && syncLocal && config == remoteConfig) {
Expand All @@ -223,11 +223,10 @@ protected void updateFirst() throws Throwable {
}

protected void launchFirst() throws Throwable {
Path zip = Paths.get(ZIP_LOCATION);

if (Files.exists(zip)) {
if (Files.exists(ZIP_FILE_PATH)) {
try {
Archive archive = Archive.read(zip);
Archive archive = Archive.read(ZIP_FILE_PATH);
Configuration oldConfig = null;
Configuration newConfig = archive.getConfiguration();

Expand Down Expand Up @@ -265,11 +264,11 @@ protected void launchFirst() throws Throwable {
if (remoteConfig.equals(localConfig))
return;

boolean success = remoteConfig.update(UpdateOptions.archive(zip).publicKey(pk)).getException() == null;
boolean success = remoteConfig.update(UpdateOptions.archive(ZIP_FILE_PATH).publicKey(pk)).getException() == null;

if (Files.exists(zip)) {
if (Files.exists(ZIP_FILE_PATH)) {
// persist old config to delete old files on next restart
Archive archive = Archive.read(zip);
Archive archive = Archive.read(ZIP_FILE_PATH);
try (FileSystem fs = archive.openConnection();
BufferedWriter out = Files.newBufferedWriter(fs.getPath(OLD_CONFIG))) {
localConfig.write(out);
Expand Down Expand Up @@ -342,8 +341,8 @@ protected void syncLocal(Configuration remoteConfig) {
} catch (IOException e) {
e.printStackTrace();
}
}

}
// @formatter:off
private static void welcome() {

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/update4j/util/FileUtils.java
Expand Up @@ -50,7 +50,8 @@
public class FileUtils {

public static final Pattern OS_PATTERN = Pattern.compile(".+-(linux|win|mac)\\.[^.]+");

private static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir";

private FileUtils() {
}

Expand Down Expand Up @@ -279,5 +280,9 @@ public static void delayedDelete(Collection<Path> files, int secondsDelay) {
}
}));
}

public static Path getTempPath() {
return Paths.get(System.getProperty(JAVA_IO_TMPDIR_KEY));
}

}