From 0d4670fb36f1b50c273e89cbc2e3424a7edb86e9 Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Fri, 13 Jul 2012 12:18:54 +0000 Subject: [PATCH] Support buffer directories which are absolute Windows paths (replace one more call). SVN: 26106 --- .../cisd/common/filesystem/HostAwareFile.java | 20 +++++++++++++++++++ .../HostAwareFileWithHighwaterMark.java | 10 ++-------- .../systemsx/cisd/datamover/Parameters.java | 15 +------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/common/source/java/ch/systemsx/cisd/common/filesystem/HostAwareFile.java b/common/source/java/ch/systemsx/cisd/common/filesystem/HostAwareFile.java index 54603520138..9247e643bac 100644 --- a/common/source/java/ch/systemsx/cisd/common/filesystem/HostAwareFile.java +++ b/common/source/java/ch/systemsx/cisd/common/filesystem/HostAwareFile.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.common.filesystem; import java.io.File; import java.io.Serializable; +import java.util.regex.Pattern; import ch.systemsx.cisd.common.utilities.AbstractHashable; @@ -30,6 +31,8 @@ public class HostAwareFile extends AbstractHashable implements Serializable { private static final long serialVersionUID = 1L; + private final static Pattern WINDOWS_DRIVE_PATTERN = Pattern.compile("^[a-zA-Z]:\\\\"); + public static final char HOST_FILE_SEP = ':'; private final String hostOrNull; @@ -93,4 +96,21 @@ public class HostAwareFile extends AbstractHashable implements Serializable } } } + + /** + * Returns the index between host and file, or -1, if the <var>hostFileString</var> does not + * contain a host. + */ + public static int getHostFileIndex(final String hostFileString) + { + // Windows absolute path. + if (WINDOWS_DRIVE_PATTERN.matcher(hostFileString).find()) + { + return -1; + } else + { + return hostFileString.indexOf(HostAwareFile.HOST_FILE_SEP); + } + } + } diff --git a/common/source/java/ch/systemsx/cisd/common/highwatermark/HostAwareFileWithHighwaterMark.java b/common/source/java/ch/systemsx/cisd/common/highwatermark/HostAwareFileWithHighwaterMark.java index be4b5c53cc9..5e12de40676 100644 --- a/common/source/java/ch/systemsx/cisd/common/highwatermark/HostAwareFileWithHighwaterMark.java +++ b/common/source/java/ch/systemsx/cisd/common/highwatermark/HostAwareFileWithHighwaterMark.java @@ -133,9 +133,9 @@ public final class HostAwareFileWithHighwaterMark extends HostAwareFile { File file; String hostNameOrNull = null; - final int index = hostFile.indexOf(HOST_FILE_SEP); + final int index = getHostFileIndex(hostFile); final String rsyncModuleOrNull; - if (index > -1 && isWindowsDriveLetter(hostFile, index) == false) + if (index > -1) { hostNameOrNull = hostFile.substring(0, index); final int index2 = hostFile.indexOf(HOST_FILE_SEP, index + 1); @@ -157,12 +157,6 @@ public final class HostAwareFileWithHighwaterMark extends HostAwareFile highwaterMarkInKb); } - private static boolean isWindowsDriveLetter(String hostFile, int colonIndex) - { - // e.g. c:\ - return colonIndex == 1 && hostFile.length() >= 3 && hostFile.charAt(2) == '\\'; - } - private static File getCanonicalFile(final String hostFile) { File file = new File(hostFile); diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/Parameters.java b/datamover/source/java/ch/systemsx/cisd/datamover/Parameters.java index 6549036390e..28b075a84b5 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/Parameters.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/Parameters.java @@ -989,8 +989,6 @@ public final class Parameters implements ITimingParameters, IFileSysParameters public final static class HostAwareFileWithHighwaterMarkHandler extends OptionHandler { - private final static Pattern WINDOWS_DRIVE_PATTERN = Pattern.compile("^[a-zA-Z]:\\\\"); - static final char DIRECTORY_HIGHWATERMARK_SEP = '>'; private final Setter<? super HostAwareFileWithHighwaterMark> setter; @@ -1030,7 +1028,7 @@ public final class Parameters implements ITimingParameters, IFileSysParameters String host = null; String strHighwaterMark = null; final File file; - final int hostFileIndex = getHostFileIndex(value); + final int hostFileIndex = HostAwareFileWithHighwaterMark.getHostFileIndex(value); final int fileHWMIndex = value.indexOf(DIRECTORY_HIGHWATERMARK_SEP); String rsyncModuleOrNull = null; if (hostFileIndex > -1 && fileHWMIndex > -1) @@ -1076,17 +1074,6 @@ public final class Parameters implements ITimingParameters, IFileSysParameters highwaterMark)); } - private int getHostFileIndex(final String value) - { - // Windows absolute path. - if (WINDOWS_DRIVE_PATTERN.matcher(value).find()) - { - return -1; - } else - { - return value.indexOf(HostAwareFile.HOST_FILE_SEP); - } - } } } -- GitLab