Skip to content
Snippets Groups Projects
Commit d80592fc authored by felmer's avatar felmer
Browse files

LMS-1389 canonicalize file path

SVN: 14746
parent 7d9e7485
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package ch.systemsx.cisd.common.highwatermark; package ch.systemsx.cisd.common.highwatermark;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
...@@ -113,7 +114,7 @@ public final class HostAwareFileWithHighwaterMark extends HostAwareFile ...@@ -113,7 +114,7 @@ public final class HostAwareFileWithHighwaterMark extends HostAwareFile
assert properties != null : "Unspecified properties"; assert properties != null : "Unspecified properties";
assert StringUtils.isNotBlank(hostFilePropertyKey) : "Host-file property key is blank"; assert StringUtils.isNotBlank(hostFilePropertyKey) : "Host-file property key is blank";
final String hostFile = PropertyUtils.getMandatoryProperty(properties, hostFilePropertyKey); final String hostFile = PropertyUtils.getMandatoryProperty(properties, hostFilePropertyKey);
final String filePath; File file;
String hostNameOrNull = null; String hostNameOrNull = null;
final int index = hostFile.indexOf(HOST_FILE_SEP); final int index = hostFile.indexOf(HOST_FILE_SEP);
final String rsyncModuleOrNull; final String rsyncModuleOrNull;
...@@ -124,24 +125,36 @@ public final class HostAwareFileWithHighwaterMark extends HostAwareFile ...@@ -124,24 +125,36 @@ public final class HostAwareFileWithHighwaterMark extends HostAwareFile
if (index2 > -1) if (index2 > -1)
{ {
rsyncModuleOrNull = hostFile.substring(index + 1, index2); rsyncModuleOrNull = hostFile.substring(index + 1, index2);
filePath = hostFile.substring(index2 + 1); file = new File(hostFile.substring(index2 + 1));
} else } else
{ {
rsyncModuleOrNull = null; rsyncModuleOrNull = null;
filePath = hostFile.substring(index + 1); file = getCanonicalFile(hostFile.substring(index + 1));
} }
} else } else
{ {
rsyncModuleOrNull = null; rsyncModuleOrNull = null;
filePath = hostFile; file = getCanonicalFile(hostFile);
} }
final long highwaterMarkInKb = final long highwaterMarkInKb =
PropertyUtils.getLong(properties, hostFilePropertyKey.concat(SEP).concat( PropertyUtils.getLong(properties, hostFilePropertyKey.concat(SEP).concat(
HIGHWATER_MARK_PROPERTY_KEY), -1L); HIGHWATER_MARK_PROPERTY_KEY), -1L);
return new HostAwareFileWithHighwaterMark(hostNameOrNull, new File(filePath), return new HostAwareFileWithHighwaterMark(hostNameOrNull, file,
rsyncModuleOrNull, highwaterMarkInKb); rsyncModuleOrNull, highwaterMarkInKb);
} }
private static File getCanonicalFile(final String hostFile)
{
File file = new File(hostFile);
try
{
return file.getCanonicalFile();
} catch (IOException ex)
{
throw new ConfigurationFailureException("Unknown file " + file.getAbsolutePath());
}
}
/** /**
* Returns the high water mark for this file. * Returns the high water mark for this file.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment