mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 19:55:48 +01:00
Fix "Unable to watch transformation directory" warnings (#1650)
Fixes #1636 Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
parent
81e82e7d44
commit
f201b83c09
@ -247,10 +247,10 @@ public abstract class AbstractFileTransformationService<T> implements Transforma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable String getFileExtension(String fileName) {
|
private String getFileExtension(String fileName) {
|
||||||
int extensionPos = fileName.lastIndexOf(EXTENSION_SEPARATOR);
|
int extensionPos = fileName.lastIndexOf(EXTENSION_SEPARATOR);
|
||||||
int lastSeparatorPos = Math.max(fileName.lastIndexOf(UNIX_SEPARATOR), fileName.lastIndexOf(WINDOWS_SEPARATOR));
|
int lastSeparatorPos = Math.max(fileName.lastIndexOf(UNIX_SEPARATOR), fileName.lastIndexOf(WINDOWS_SEPARATOR));
|
||||||
return lastSeparatorPos > extensionPos ? null : fileName.substring(extensionPos + 1);
|
return lastSeparatorPos > extensionPos ? "" : fileName.substring(extensionPos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,31 +262,21 @@ public abstract class AbstractFileTransformationService<T> implements Transforma
|
|||||||
*/
|
*/
|
||||||
protected String getLocalizedProposedFilename(String filename, final WatchService watchService) {
|
protected String getLocalizedProposedFilename(String filename, final WatchService watchService) {
|
||||||
final File file = new File(filename);
|
final File file = new File(filename);
|
||||||
|
if (file.getParent() != null) {
|
||||||
|
watchSubDirectory(file.getParent(), watchService);
|
||||||
|
}
|
||||||
|
|
||||||
String extension = getFileExtension(filename);
|
String extension = getFileExtension(filename);
|
||||||
String prefix = file.getPath();
|
|
||||||
String result = filename;
|
|
||||||
|
|
||||||
if (extension == null) {
|
|
||||||
extension = "";
|
|
||||||
}
|
|
||||||
if (!prefix.isEmpty()) {
|
|
||||||
watchSubDirectory(prefix, watchService);
|
|
||||||
}
|
|
||||||
|
|
||||||
// the filename may already contain locale information
|
// the filename may already contain locale information
|
||||||
if (!filename.matches(".*_[a-z]{2}." + extension + "$")) {
|
if (!filename.matches(".*_[a-z]{2}." + extension + "$")) {
|
||||||
String basename = file.getName();
|
String alternateName = filename + "_" + getLocale().getLanguage() + "." + extension;
|
||||||
String alternateName = prefix + basename + "_" + getLocale().getLanguage() + "." + extension;
|
|
||||||
String alternatePath = getSourcePath() + alternateName;
|
String alternatePath = getSourcePath() + alternateName;
|
||||||
|
if (new File(alternatePath).exists()) {
|
||||||
File f = new File(alternatePath);
|
return alternatePath;
|
||||||
if (f.exists()) {
|
|
||||||
result = alternateName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = getSourcePath() + result;
|
return getSourcePath() + filename;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user