mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-30 00:56:56 +13:00
Session fixes
This commit is contained in:
parent
b54066bf89
commit
16f165a92c
4 changed files with 67 additions and 18 deletions
|
@ -27,6 +27,10 @@ public abstract class LocalProcessControlProvider {
|
|||
}
|
||||
|
||||
public static ShellProcessControl create() {
|
||||
if (INSTANCE == null) {
|
||||
throw new IllegalStateException("Not initialized");
|
||||
}
|
||||
|
||||
return INSTANCE.createProcessControl();
|
||||
}
|
||||
|
||||
|
|
26
core/src/main/java/io/xpipe/core/util/UuidHelper.java
Normal file
26
core/src/main/java/io/xpipe/core/util/UuidHelper.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package io.xpipe.core.util;
|
||||
|
||||
import io.xpipe.core.dialog.Dialog;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UuidHelper {
|
||||
|
||||
public static Optional<UUID> parse(String s) {
|
||||
try {
|
||||
return Optional.of(UUID.fromString(s));
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<UUID> parse(Dialog.FailableSupplier<String> supplier) {
|
||||
try {
|
||||
var s = supplier.get();
|
||||
return Optional.of(UUID.fromString(s));
|
||||
} catch (Exception ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,21 +30,37 @@ public class XPipeSession {
|
|||
|
||||
private static XPipeSession INSTANCE;
|
||||
|
||||
public static void init(UUID buildSessionId) throws Exception {
|
||||
var sessionFile = XPipeTempDirectory.getLocal().resolve("xpipe_session");
|
||||
var isNew = !Files.exists(sessionFile);
|
||||
var systemSessionId = isNew ? UUID.randomUUID() : UUID.fromString(Files.readString(sessionFile));
|
||||
|
||||
if (OsType.getLocal().equals(OsType.WINDOWS)) {
|
||||
var pf = Path.of("C:\\pagefile.sys");
|
||||
BasicFileAttributes attr = Files.readAttributes(pf, BasicFileAttributes.class);
|
||||
var timeUuid = UUID.nameUUIDFromBytes(attr.creationTime().toInstant().toString().getBytes());
|
||||
isNew = isNew && timeUuid.equals(systemSessionId);
|
||||
systemSessionId = timeUuid;
|
||||
public static void init(UUID buildSessionId) {
|
||||
if (INSTANCE != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Files.writeString(sessionFile, systemSessionId.toString());
|
||||
INSTANCE = new XPipeSession(isNew, UUID.randomUUID(), buildSessionId, systemSessionId);
|
||||
var sessionFile = XPipeTempDirectory.getLocal().resolve("xpipe_session");
|
||||
var isNewSystemSession = !Files.exists(sessionFile);
|
||||
var systemSessionId = isNewSystemSession
|
||||
? UUID.randomUUID()
|
||||
: UuidHelper.parse(() -> Files.readString(sessionFile)).orElse(UUID.randomUUID());
|
||||
|
||||
try {
|
||||
if (OsType.getLocal().equals(OsType.WINDOWS)) {
|
||||
var pf = Path.of("C:\\pagefile.sys");
|
||||
BasicFileAttributes attr = Files.readAttributes(pf, BasicFileAttributes.class);
|
||||
var timeUuid = UUID.nameUUIDFromBytes(
|
||||
attr.creationTime().toInstant().toString().getBytes());
|
||||
isNewSystemSession = isNewSystemSession && timeUuid.equals(systemSessionId);
|
||||
systemSessionId = timeUuid;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
isNewSystemSession = true;
|
||||
systemSessionId = UUID.randomUUID();
|
||||
}
|
||||
|
||||
try {
|
||||
Files.writeString(sessionFile, systemSessionId.toString());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
INSTANCE = new XPipeSession(isNewSystemSession, UUID.randomUUID(), buildSessionId, systemSessionId);
|
||||
}
|
||||
|
||||
public static XPipeSession get() {
|
||||
|
|
|
@ -3,16 +3,19 @@ package io.xpipe.core.util;
|
|||
import io.xpipe.core.impl.FileNames;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.process.ShellProcessControl;
|
||||
import io.xpipe.core.store.ShellStore;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class XPipeTempDirectory {
|
||||
|
||||
public static Path getLocal() throws Exception {
|
||||
try (var pc = ShellStore.local().create().start()) {
|
||||
return Path.of(get(pc));
|
||||
public static Path getLocal() {
|
||||
if (OsType.getLocal().equals(OsType.WINDOWS)) {
|
||||
return Path.of(System.getenv("TEMP")).resolve("xpipe");
|
||||
} else if (OsType.getLocal().equals(OsType.LINUX)) {
|
||||
return Path.of("/tmp/xpipe");
|
||||
} else {
|
||||
return Path.of(System.getenv("TMPDIR"), "xpipe");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +27,7 @@ public class XPipeTempDirectory {
|
|||
proc.executeSimpleCommand(proc.getShellType().flatten(proc.getShellType().getMkdirsCommand(dir)), "Unable to access or create temporary directory " + dir);
|
||||
|
||||
if (proc.getOsType().equals(OsType.LINUX) || proc.getOsType().equals(OsType.MAC)) {
|
||||
proc.executeSimpleCommand("(chmod -f 777 \"" + dir + "\"");
|
||||
proc.executeSimpleCommand("chmod -f 777 \"" + dir + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue