Skip to content

Commit

Permalink
Support symlinks in configtree property paths
Browse files Browse the repository at this point in the history
Prior to this commit, the configtree property source would not traverse
into a sub-directory in a property path if the sub-directory was a
symbolic link. This commit allows symlinked sub-directories to be
traversed like any other sub-directory in the property path.

Fixes gh-24530
  • Loading branch information
scottfrederick committed Jan 5, 2021
1 parent 615a8ae commit 5053409
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Expand Up @@ -19,6 +19,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
Expand Down Expand Up @@ -203,15 +204,16 @@ Origin getOrigin() {
static Map<String, PropertyFile> findAll(Path sourceDirectory, Set<Option> options) {
try {
Map<String, PropertyFile> propertyFiles = new TreeMap<>();
Files.find(sourceDirectory, MAX_DEPTH, PropertyFile::isPropertyFile).forEach((path) -> {
String name = getName(sourceDirectory.relativize(path));
if (StringUtils.hasText(name)) {
if (options.contains(Option.USE_LOWERCASE_NAMES)) {
name = name.toLowerCase();
}
propertyFiles.put(name, new PropertyFile(path, options));
}
});
Files.find(sourceDirectory, MAX_DEPTH, PropertyFile::isPropertyFile, FileVisitOption.FOLLOW_LINKS)
.forEach((path) -> {
String name = getName(sourceDirectory.relativize(path));
if (StringUtils.hasText(name)) {
if (options.contains(Option.USE_LOWERCASE_NAMES)) {
name = name.toLowerCase();
}
propertyFiles.put(name, new PropertyFile(path, options));
}
});
return Collections.unmodifiableMap(propertyFiles);
}
catch (IOException ex) {
Expand Down
Expand Up @@ -88,6 +88,15 @@ void getPropertyNamesFromNestedReturnsPropertyNames() throws Exception {
assertThat(propertySource.getPropertyNames()).containsExactly("c", "fa.a", "fa.b", "fb.a", "fb.fa.a");
}

@Test
void getPropertyNamesFromNestedWithSymlinkInPathReturnsPropertyNames() throws Exception {
addNested();
Path symlinkTempDir = Files.createSymbolicLink(this.directory.resolveSibling("symlinkTempDir"), this.directory);
ConfigTreePropertySource propertySource = new ConfigTreePropertySource("test", symlinkTempDir);
Files.delete(symlinkTempDir);
assertThat(propertySource.getPropertyNames()).containsExactly("c", "fa.a", "fa.b", "fb.a", "fb.fa.a");
}

@Test
void getPropertyNamesFromFlatWithSymlinksIgnoresHiddenFiles() throws Exception {
ConfigTreePropertySource propertySource = getSymlinkedFlatPropertySource();
Expand Down

0 comments on commit 5053409

Please sign in to comment.