mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
use default sparrow home location in user dir for instance lock file pointer
This commit is contained in:
parent
5d674b7e91
commit
c1fc8712d5
3 changed files with 30 additions and 14 deletions
|
@ -130,7 +130,7 @@ public class SparrowWallet {
|
||||||
private final List<String> fileUriArguments;
|
private final List<String> fileUriArguments;
|
||||||
|
|
||||||
public Instance(List<String> fileUriArguments) {
|
public Instance(List<String> fileUriArguments) {
|
||||||
super(SparrowWallet.APP_ID + "." + Network.get(), true);
|
super(SparrowWallet.APP_ID, true);
|
||||||
this.fileUriArguments = fileUriArguments;
|
this.fileUriArguments = fileUriArguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,17 +134,20 @@ public abstract class Instance {
|
||||||
|
|
||||||
private Path getLockFile(boolean findExisting) {
|
private Path getLockFile(boolean findExisting) {
|
||||||
if(findExisting) {
|
if(findExisting) {
|
||||||
Path pointer = getSystemLockFilePointer();
|
Path pointer = getUserLockFilePointer();
|
||||||
try {
|
try {
|
||||||
if(Files.exists(pointer)) {
|
if(pointer != null && Files.exists(pointer)) {
|
||||||
if(Files.isSymbolicLink(pointer)) {
|
if(Files.isSymbolicLink(pointer)) {
|
||||||
return Files.readSymbolicLink(pointer);
|
return Files.readSymbolicLink(pointer);
|
||||||
} else {
|
} else {
|
||||||
return Path.of(Files.readString(pointer, StandardCharsets.UTF_8));
|
Path lockFile = Path.of(Files.readString(pointer, StandardCharsets.UTF_8));
|
||||||
|
if(Files.exists(lockFile)) {
|
||||||
|
return lockFile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
log.warn("Could not follow symbolic link at " + pointer.toAbsolutePath());
|
log.warn("Could not find lock file at " + pointer.toAbsolutePath());
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
//ignore
|
//ignore
|
||||||
}
|
}
|
||||||
|
@ -154,9 +157,9 @@ public abstract class Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSymlink(Path lockFile) {
|
private void createSymlink(Path lockFile) {
|
||||||
Path pointer = getSystemLockFilePointer();
|
Path pointer = getUserLockFilePointer();
|
||||||
try {
|
try {
|
||||||
if(!Files.exists(pointer, LinkOption.NOFOLLOW_LINKS)) {
|
if(pointer != null && !Files.exists(pointer, LinkOption.NOFOLLOW_LINKS)) {
|
||||||
Files.createSymbolicLink(pointer, lockFile);
|
Files.createSymbolicLink(pointer, lockFile);
|
||||||
pointer.toFile().deleteOnExit();
|
pointer.toFile().deleteOnExit();
|
||||||
}
|
}
|
||||||
|
@ -174,8 +177,12 @@ public abstract class Instance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path getSystemLockFilePointer() {
|
private Path getUserLockFilePointer() {
|
||||||
return Path.of(System.getProperty("java.io.tmpdir")).resolve(applicationId + ".link");
|
try {
|
||||||
|
return Storage.getSparrowDir(true).toPath().resolve(applicationId + ".default");
|
||||||
|
} catch(Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,8 +195,9 @@ public abstract class Instance {
|
||||||
if(serverChannel != null && serverChannel.isOpen()) {
|
if(serverChannel != null && serverChannel.isOpen()) {
|
||||||
serverChannel.close();
|
serverChannel.close();
|
||||||
}
|
}
|
||||||
|
if(getUserLockFilePointer() != null) {
|
||||||
Files.deleteIfExists(getSystemLockFilePointer());
|
Files.deleteIfExists(getUserLockFilePointer());
|
||||||
|
}
|
||||||
Files.deleteIfExists(getLockFile(false));
|
Files.deleteIfExists(getLockFile(false));
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new InstanceException(e);
|
throw new InstanceException(e);
|
||||||
|
|
|
@ -536,11 +536,15 @@ 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(), Network.get().getName());
|
sparrowDir = new File(getSparrowHome(useDefault), Network.get().getName());
|
||||||
} else {
|
} else {
|
||||||
sparrowDir = getSparrowHome();
|
sparrowDir = getSparrowHome(useDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!sparrowDir.exists()) {
|
if(!sparrowDir.exists()) {
|
||||||
|
@ -551,7 +555,11 @@ public class Storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getSparrowHome() {
|
public static File getSparrowHome() {
|
||||||
if(System.getProperty(SparrowWallet.APP_HOME_PROPERTY) != null) {
|
return getSparrowHome(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getSparrowHome(boolean useDefault) {
|
||||||
|
if(!useDefault && System.getProperty(SparrowWallet.APP_HOME_PROPERTY) != null) {
|
||||||
return new File(System.getProperty(SparrowWallet.APP_HOME_PROPERTY));
|
return new File(System.getProperty(SparrowWallet.APP_HOME_PROPERTY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue