Skip to content

Commit

Permalink
Add NFC and NFD file name normalization for uploading files
Browse files Browse the repository at this point in the history
This is needed in case the path encoding on the filesystem differs from the path encoding in the meta data.
  • Loading branch information
claussni committed Sep 3, 2015
1 parent 3c7e8db commit 22a4111
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.Normalizer;

/**
* This encapsulates datastreams which are on the local file system
Expand Down Expand Up @@ -195,7 +196,11 @@ private File getFileInstance() throws IOException {
File file;
if (_path.startsWith("file:")) {
try {
file = new File(new URI(_path));
file = tryNormalizedFilename(_path, Normalizer.Form.NFC);
if (!file.exists()) {
LOG.warn("Could'nt find file by NFC normalized file name. Fallback to NFD normalization...");
file = tryNormalizedFilename(_path, Normalizer.Form.NFD);
}
} catch (URISyntaxException e) {
throw new IOException("File URI is not valid: " + _path);
}
Expand All @@ -204,4 +209,8 @@ private File getFileInstance() throws IOException {
}
return file;
}

private File tryNormalizedFilename(String path, Normalizer.Form form) throws URISyntaxException {
return new File(new URI(Normalizer.normalize(path, form)));
}
}

0 comments on commit 22a4111

Please sign in to comment.