TransferManager.downloadDirectory crashes on windows if a key contains colon ':'
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 51
Description
### Describe the bug
If the target directory contains an object with a key which contains a colon character, then it throws java.nio.file.InvalidPathException: Illegal char <:>
### Expected Behavior
All files are downloaded, illegal characters are changed to underscore
(Like in the AWS console. If that is an accepted solution there, I believe it should work the same way here too.)
If it unacceptable for some reason, then catch the exception and either skip the file or use the downloadFileRequestTransformer.destination as fileName if provided.
### Current Behavior
Download stops and
java.nio.file.InvalidPathException: Illegal char <:>
is thrown
### Reproduction Steps
download any directory with an object with a colon in it's key
### Possible Solution
In DownloadDirectoryHelper.determineDestinationPath method the java.nio.file.Path.resolve method is used to construct the destination path. If the current fileSystem is windows then it checks for reserved characters before creates the new path.
before calling resolve(relativePath), all reserved characters (<>:\"|?*) should be replaced with underscore.
There is a normalizeKey method there, probably a String.replaceAll there would do the trick.
(probably the same is true on other FileSystems, although I didn't test it on Linux)
### Additional Information/Context
using downloadFileRequestTransformer does NOT help, because the original destination path is always calculated (even if it is replaced later by the transformer). The Exception is thrown when the default destination path is **calculated**, not when the file is **written** to the fileSystem
### AWS Java SDK version used
2.20.8
### JDK version used
17
### Operating System and version
Windows 11
Contributor guide
Assessment
This issue has not been assessed yet.