mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-02 20:36:44 +00:00
avoid saving lock file link for default instance if environment variable is set
This commit is contained in:
parent
0fad93524e
commit
f0bfc44e72
2 changed files with 16 additions and 9 deletions
|
@ -4,6 +4,7 @@ import com.sparrowwallet.sparrow.io.Storage;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
@ -23,6 +24,7 @@ import java.util.Set;
|
||||||
|
|
||||||
public abstract class Instance {
|
public abstract class Instance {
|
||||||
private static final Logger log = LoggerFactory.getLogger(Instance.class);
|
private static final Logger log = LoggerFactory.getLogger(Instance.class);
|
||||||
|
private static final String LINK_ENV_PROPERTY = "SPARROW_NO_LOCK_FILE_LINK";
|
||||||
|
|
||||||
public final String applicationId;
|
public final String applicationId;
|
||||||
private final boolean autoExit;
|
private final boolean autoExit;
|
||||||
|
@ -64,7 +66,7 @@ public abstract class Instance {
|
||||||
serverChannel.register(selector, SelectionKey.OP_ACCEPT);
|
serverChannel.register(selector, SelectionKey.OP_ACCEPT);
|
||||||
lockFile.toFile().deleteOnExit();
|
lockFile.toFile().deleteOnExit();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new InstanceException("Could not open UNIX socket at " + lockFile.toAbsolutePath(), e);
|
throw new InstanceException("Could not open UNIX socket lock file for instance at " + lockFile.toAbsolutePath(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread thread = new Thread(() -> {
|
Thread thread = new Thread(() -> {
|
||||||
|
@ -121,7 +123,7 @@ public abstract class Instance {
|
||||||
try {
|
try {
|
||||||
Files.deleteIfExists(lockFile);
|
Files.deleteIfExists(lockFile);
|
||||||
startServer(lockFile);
|
startServer(lockFile);
|
||||||
} catch(IOException ex) {
|
} catch(Exception ex) {
|
||||||
throw new InstanceException("Could not delete lock file from previous instance", e);
|
throw new InstanceException("Could not delete lock file from previous instance", e);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
@ -187,8 +189,17 @@ public abstract class Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path getUserLockFilePointer() {
|
private Path getUserLockFilePointer() {
|
||||||
|
if(Boolean.parseBoolean(System.getenv(LINK_ENV_PROPERTY))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Storage.getSparrowDir(true).toPath().resolve(applicationId + ".default");
|
File sparrowHome = Storage.getSparrowHome(true);
|
||||||
|
if(!sparrowHome.exists()) {
|
||||||
|
Storage.createOwnerOnlyDirectory(sparrowHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sparrowHome.toPath().resolve(applicationId + ".default");
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -536,15 +536,11 @@ public class Storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getSparrowDir() {
|
public static File getSparrowDir() {
|
||||||
return getSparrowDir(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getSparrowDir(boolean useDefault) {
|
|
||||||
File sparrowDir;
|
File sparrowDir;
|
||||||
if(Network.get() != Network.MAINNET) {
|
if(Network.get() != Network.MAINNET) {
|
||||||
sparrowDir = new File(getSparrowHome(useDefault), Network.get().getName());
|
sparrowDir = new File(getSparrowHome(), Network.get().getName());
|
||||||
} else {
|
} else {
|
||||||
sparrowDir = getSparrowHome(useDefault);
|
sparrowDir = getSparrowHome();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!sparrowDir.exists()) {
|
if(!sparrowDir.exists()) {
|
||||||
|
|
Loading…
Reference in a new issue