Support symlinks in configtree property paths
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
This commit is contained in:
		
							parent
							
								
									615a8ae56e
								
							
						
					
					
						commit
						505340909a
					
				|  | @ -19,6 +19,7 @@ package org.springframework.boot.env; | |||
| 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; | ||||
|  | @ -203,7 +204,8 @@ public class ConfigTreePropertySource extends EnumerablePropertySource<Path> imp | |||
| 		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) -> { | ||||
| 				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)) { | ||||
|  |  | |||
|  | @ -88,6 +88,15 @@ class ConfigTreePropertySourceTests { | |||
| 		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(); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue