Skip to content

Commit b53857c

Browse files
committed
[bugfix] Make sure filesystem paths are normalised
1 parent b55849d commit b53857c

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
@@ -2190,7 +2190,7 @@ public boolean run(final String args[]) throws Exception {
21902190
configFile = Optional.ofNullable(ConfigurationHelper.lookup((String) CONF_XML.get("")));
21912191
}
21922192
}
2193-
configFile.ifPresent(value -> properties.setProperty(CONFIGURATION, value.toAbsolutePath().toString()));
2193+
configFile.ifPresent(value -> properties.setProperty(CONFIGURATION, value.toString()));
21942194

21952195
properties.putAll(loadClientProperties());
21962196

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()) {
@@ -863,15 +864,15 @@ private void configureBackend( final Optional<Path> dbHome, Element con ) throws
863864
final String dataFiles = getConfigAttributeValue( con, BrokerPool.DATA_DIR_ATTRIBUTE );
864865

865866
if (dataFiles != null) {
866-
final Path df = ConfigurationHelper.lookup( dataFiles, dbHome );
867+
final Path df = ConfigurationHelper.lookup(dataFiles, dbHome);
867868
if (!Files.isReadable(df)) {
868869
try {
869870
Files.createDirectories(df);
870871
} catch (final IOException ioe) {
871-
throw new DatabaseConfigurationException("cannot read data directory: " + df.toAbsolutePath().toString(), ioe);
872+
throw new DatabaseConfigurationException("cannot read data directory: " + df, ioe);
872873
}
873874
}
874-
config.put(BrokerPool.PROPERTY_DATA_DIR, df.toAbsolutePath());
875+
config.put(BrokerPool.PROPERTY_DATA_DIR, df);
875876
LOG.debug(BrokerPool.PROPERTY_DATA_DIR + ": {}", config.get(BrokerPool.PROPERTY_DATA_DIR));
876877
}
877878

@@ -1090,9 +1091,9 @@ private void configureRecovery( final Optional<Path> dbHome, Element recovery )
10901091
final Path rf = ConfigurationHelper.lookup( option, dbHome );
10911092

10921093
if(!Files.isReadable(rf)) {
1093-
throw new DatabaseConfigurationException( "cannot read data directory: " + rf.toAbsolutePath());
1094+
throw new DatabaseConfigurationException( "cannot read data directory: " + rf);
10941095
}
1095-
setProperty(Journal.PROPERTY_RECOVERY_JOURNAL_DIR, rf.toAbsolutePath());
1096+
setProperty(Journal.PROPERTY_RECOVERY_JOURNAL_DIR, rf);
10961097
LOG.debug(Journal.PROPERTY_RECOVERY_JOURNAL_DIR + ": {}", config.get(Journal.PROPERTY_RECOVERY_JOURNAL_DIR));
10971098
}
10981099

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)