Skip to content

Commit 0cd3dd2

Browse files
committed
[bugfix] Make sure filesystem paths are normalised
1 parent a4a3824 commit 0cd3dd2

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

exist-core/src/main/java/org/exist/client/InteractiveClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,7 @@ private void applyDefaultConfig(Optional<Path> home) throws ClassNotFoundExcepti
21732173
configFile = Optional.ofNullable(ConfigurationHelper.lookup((String) CONF_XML.get("")));
21742174
}
21752175
}
2176-
configFile.ifPresent(value -> properties.setProperty(CONFIGURATION, value.toAbsolutePath().toString()));
2176+
configFile.ifPresent(value -> properties.setProperty(CONFIGURATION, value.toString()));
21772177
}
21782178

21792179
final boolean isInteractive() {

exist-core/src/main/java/org/exist/util/Configuration.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public Configuration(String configFilename, Optional<Path> existHomeDirname) thr
127127
InputStream is = null;
128128
try {
129129

130+
existHomeDirname = existHomeDirname.map(Path::normalize);
131+
130132
if(configFilename == null) {
131133
// Default file name
132134
configFilename = DatabaseImpl.CONF_XML;
@@ -164,7 +166,6 @@ public Configuration(String configFilename, Optional<Path> existHomeDirname) thr
164166
}
165167
}
166168

167-
168169
Path configFile = Paths.get(configFilename);
169170

170171
if(!configFile.isAbsolute() && existHome.isPresent()) {
@@ -889,15 +890,15 @@ private void configureBackend( final Optional<Path> dbHome, Element con ) throws
889890
final String dataFiles = getConfigAttributeValue( con, BrokerPool.DATA_DIR_ATTRIBUTE );
890891

891892
if (dataFiles != null) {
892-
final Path df = ConfigurationHelper.lookup( dataFiles, dbHome );
893+
final Path df = ConfigurationHelper.lookup(dataFiles, dbHome);
893894
if (!Files.isReadable(df)) {
894895
try {
895896
Files.createDirectories(df);
896897
} catch (final IOException ioe) {
897-
throw new DatabaseConfigurationException("cannot read data directory: " + df.toAbsolutePath().toString(), ioe);
898+
throw new DatabaseConfigurationException("cannot read data directory: " + df, ioe);
898899
}
899900
}
900-
config.put(BrokerPool.PROPERTY_DATA_DIR, df.toAbsolutePath());
901+
config.put(BrokerPool.PROPERTY_DATA_DIR, df);
901902
LOG.debug(BrokerPool.PROPERTY_DATA_DIR + ": {}", config.get(BrokerPool.PROPERTY_DATA_DIR));
902903
}
903904

@@ -1116,9 +1117,9 @@ private void configureRecovery( final Optional<Path> dbHome, Element recovery )
11161117
final Path rf = ConfigurationHelper.lookup( option, dbHome );
11171118

11181119
if(!Files.isReadable(rf)) {
1119-
throw new DatabaseConfigurationException( "cannot read data directory: " + rf.toAbsolutePath());
1120+
throw new DatabaseConfigurationException( "cannot read data directory: " + rf);
11201121
}
1121-
setProperty(Journal.PROPERTY_RECOVERY_JOURNAL_DIR, rf.toAbsolutePath());
1122+
setProperty(Journal.PROPERTY_RECOVERY_JOURNAL_DIR, rf);
11221123
LOG.debug(Journal.PROPERTY_RECOVERY_JOURNAL_DIR + ": {}", config.get(Journal.PROPERTY_RECOVERY_JOURNAL_DIR));
11231124
}
11241125

exist-core/src/main/java/org/exist/util/ConfigurationHelper.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static Optional<Path> getExistHome(final String config) {
109109
final Path userHomeRelativeConfig = userHome.resolve(config);
110110
if (Files.isDirectory(userHome) && Files.isRegularFile(userHomeRelativeConfig)) {
111111
final Path existHome = userHomeRelativeConfig.getParent().normalize();
112-
LOG.debug("Got eXist home: {} from system property 'user.home': {}", existHome.toAbsolutePath().toString(), userHome.toAbsolutePath().toString());
112+
LOG.debug("Got eXist home: {} from system property 'user.home': {}", existHome.toAbsolutePath(), userHome.toAbsolutePath());
113113
return Optional.of(existHome);
114114
}
115115

@@ -119,7 +119,7 @@ public static Optional<Path> getExistHome(final String config) {
119119
final Path userDirRelativeConfig = userDir.resolve(config);
120120
if (Files.isDirectory(userDir) && Files.isRegularFile(userDirRelativeConfig)) {
121121
final Path existHome = userDirRelativeConfig.getParent().normalize();
122-
LOG.debug("Got eXist home: {} from system property 'user.dir': {}", existHome.toAbsolutePath().toString(), userDir.toAbsolutePath().toString());
122+
LOG.debug("Got eXist home: {} from system property 'user.dir': {}", existHome.toAbsolutePath(), userDir.toAbsolutePath());
123123
return Optional.of(existHome);
124124
}
125125

@@ -132,7 +132,7 @@ public static Optional<Path> getExistHome(final String config) {
132132
existHome = Paths.get(new URI(configUrl.getPath())).getParent().getParent().normalize();
133133
LOG.warn("{} file was found on the classpath, but inside a Jar file! Derived EXIST_HOME from Jar's parent folder: {}", config, existHome);
134134
} else {
135-
existHome = Paths.get(configUrl.toURI()).getParent();
135+
existHome = Paths.get(configUrl.toURI()).getParent().normalize();
136136
if (FileUtils.fileName(existHome).equals("etc")) {
137137
existHome = existHome.getParent().normalize();
138138
}
@@ -179,15 +179,14 @@ public static Path lookup(final String path) {
179179
* @return the file handle
180180
*/
181181
public static Path lookup(final String path, final Optional<Path> parent) {
182-
// resolvePath is used for things like ~user/folder
183-
final Path p = decodeUserHome(path);
184-
if (p.isAbsolute()) {
185-
return p;
182+
// attempt to first resolve the path that is used for things like ~user/folder
183+
Path p = decodeUserHome(path);
184+
if (!p.isAbsolute()) {
185+
p = parent
186+
.orElse(getExistHome().orElse(Paths.get(System.getProperty("user.dir"))))
187+
.resolve(path);
186188
}
187-
188-
return parent
189-
.orElse(getExistHome().orElse(Paths.get(System.getProperty("user.dir"))))
190-
.resolve(path);
189+
return p.normalize().toAbsolutePath();
191190
}
192191

193192

exist-core/src/main/java/org/exist/util/SingleInstanceConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public SingleInstanceConfiguration(String configFilename, Optional<Path> existHo
6666
public static Optional<Path> getPath() {
6767
if (!_configFile.isPresent()) {
6868
final Path f = ConfigurationHelper.lookup("conf.xml");
69-
return Optional.of(f.toAbsolutePath());
69+
return Optional.of(f);
7070
}
7171
return _configFile;
7272
}

0 commit comments

Comments
 (0)