diff --git a/common/source/java/ch/systemsx/cisd/common/filesystem/FastHardLinkMaker.java b/common/source/java/ch/systemsx/cisd/common/filesystem/FastHardLinkMaker.java index a0c5fd6d5c767bb755eb4596567c615b0b5a8253..92af00b7e99d82b1c44932db60edbd37f52466bd 100644 --- a/common/source/java/ch/systemsx/cisd/common/filesystem/FastHardLinkMaker.java +++ b/common/source/java/ch/systemsx/cisd/common/filesystem/FastHardLinkMaker.java @@ -99,7 +99,7 @@ public class FastHardLinkMaker implements IFileImmutableCopier } /** - * Creates an {@link IFileImmutableCopier} with default timing pameters (uses + * Creates an {@link IFileImmutableCopier} with default timing parameters (uses * {@link TimingParameters#getDefaultParameters()}. * * @return The copier, if the native library could be initialized successfully, or @@ -107,12 +107,7 @@ public class FastHardLinkMaker implements IFileImmutableCopier */ public final static IFileImmutableCopier tryCreate() { - if (Unix.isOperational() == false) - { - return null; - } - return new FastHardLinkMaker(TimingParameters.getDefaultParameters()); - + return tryCreate(TimingParameters.getDefaultParameters()); } private final IFileImmutableCopier monitoringProxy; diff --git a/common/source/java/ch/systemsx/cisd/common/filesystem/FastRecursiveHardLinkMaker.java b/common/source/java/ch/systemsx/cisd/common/filesystem/FastRecursiveHardLinkMaker.java index c817d1d5f381c295ce3b13c51e7ec09d89d39903..79c683b25f436de71cf697215248d46d891ad8db 100644 --- a/common/source/java/ch/systemsx/cisd/common/filesystem/FastRecursiveHardLinkMaker.java +++ b/common/source/java/ch/systemsx/cisd/common/filesystem/FastRecursiveHardLinkMaker.java @@ -61,16 +61,14 @@ public class FastRecursiveHardLinkMaker implements IImmutableCopier public final static IImmutableCopier tryCreate(final TimingParameters timingParameters) { final File rsyncExecOrNull = OSUtilities.findExecutable(RSYNC_EXEC); - if (rsyncExecOrNull == null) - { - return null; - } final File lnExecOrNull = OSUtilities.findExecutable(LN_EXEC); - if (lnExecOrNull == null) + try + { + return create(rsyncExecOrNull, lnExecOrNull, timingParameters, false); + } catch (ConfigurationFailureException ex) { return null; } - return create(rsyncExecOrNull, lnExecOrNull, timingParameters, false); } public final static IImmutableCopier create(final File rsyncExecutable, final File lnExecutable) @@ -97,7 +95,7 @@ public class FastRecursiveHardLinkMaker implements IImmutableCopier { this.internFileCopierOrNull = neverUseNative ? null : FastHardLinkMaker.tryCreate(timingParameters); - this.rsyncBasedDirectoryCopierOrNull = + this.rsyncBasedDirectoryCopierOrNull = (rsyncExcutable == null) ? null : new RsyncBasedRecursiveHardLinkMaker(rsyncExcutable, timingParameters, DEFAULT_MAX_ERRORS_TO_IGNORE); if (internFileCopierOrNull == null) diff --git a/common/source/java/ch/systemsx/cisd/common/filesystem/rsync/RsyncBasedRecursiveHardLinkMaker.java b/common/source/java/ch/systemsx/cisd/common/filesystem/rsync/RsyncBasedRecursiveHardLinkMaker.java index 82dba348daace274cf26f294c081299469fdbbd6..263ea8b4731d4789071693787c9320deee17c181 100644 --- a/common/source/java/ch/systemsx/cisd/common/filesystem/rsync/RsyncBasedRecursiveHardLinkMaker.java +++ b/common/source/java/ch/systemsx/cisd/common/filesystem/rsync/RsyncBasedRecursiveHardLinkMaker.java @@ -25,6 +25,7 @@ import ch.systemsx.cisd.common.TimingParameters; import ch.systemsx.cisd.common.concurrent.ConcurrencyUtilities; import ch.systemsx.cisd.common.concurrent.InactivityMonitor; import ch.systemsx.cisd.common.concurrent.InactivityMonitor.IInactivityObserver; +import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException; import ch.systemsx.cisd.common.exceptions.Status; import ch.systemsx.cisd.common.filesystem.CopyModeExisting; import ch.systemsx.cisd.common.filesystem.IDirectoryImmutableCopier; @@ -72,13 +73,19 @@ public class RsyncBasedRecursiveHardLinkMaker implements IDirectoryImmutableCopi public RsyncBasedRecursiveHardLinkMaker(File rsyncExecutableOrNull, TimingParameters timingParameters, int maxErrorsToIgnore) { - if (rsyncExecutableOrNull == null) + final File rsyncExecutable = + (rsyncExecutableOrNull == null) ? OSUtilities.findExecutable(RSYNC_EXEC) + : rsyncExecutableOrNull; + if (rsyncExecutable == null) { - rsyncCopier = new RsyncCopier(OSUtilities.findExecutable(RSYNC_EXEC)); - } else + throw new ConfigurationFailureException("No rsync executable available."); + } + if (rsyncExecutable.exists() == false) { - rsyncCopier = new RsyncCopier(rsyncExecutableOrNull); + throw new ConfigurationFailureException("rsync executable '" + rsyncExecutable + + "' does not exist."); } + this.rsyncCopier = new RsyncCopier(rsyncExecutable); this.timingParameters = timingParameters; this.maxErrorsToIgnore = maxErrorsToIgnore; } diff --git a/common/source/java/ch/systemsx/cisd/common/filesystem/rsync/RsyncCopier.java b/common/source/java/ch/systemsx/cisd/common/filesystem/rsync/RsyncCopier.java index a4cc18cbd13124dd793482eab1266af61d99ffad..a61c518dbf813dbc17bd4fb51fa60002438bde2d 100644 --- a/common/source/java/ch/systemsx/cisd/common/filesystem/rsync/RsyncCopier.java +++ b/common/source/java/ch/systemsx/cisd/common/filesystem/rsync/RsyncCopier.java @@ -103,7 +103,7 @@ public final class RsyncCopier implements IPathCopier, IDirectoryImmutableCopier private final RsyncVersion rsyncVersion; - private final String sshExecutable; + private final String sshExecutablePathOrNull; private final List<String> additionalCmdLineFlagsOrNull; @@ -143,12 +143,19 @@ public final class RsyncCopier implements IPathCopier, IDirectoryImmutableCopier public RsyncCopier(final File rsyncExecutable, final File sshExecutableOrNull, String... cmdLineFlags) { - assert rsyncExecutable != null && rsyncExecutable.exists(); - assert sshExecutableOrNull == null || rsyncExecutable.exists(); - + if (rsyncExecutable == null) + { + throw new ConfigurationFailureException("No rsync executable available."); + } + if (rsyncExecutable.exists() == false) + { + throw new ConfigurationFailureException("rsync executable '" + rsyncExecutable + + "' does not exist."); + } this.rsyncExecutable = rsyncExecutable.getAbsolutePath(); this.rsyncVersion = RsyncVersionChecker.getVersion(rsyncExecutable.getAbsolutePath()); - this.sshExecutable = (sshExecutableOrNull != null) ? sshExecutableOrNull.getPath() : null; + this.sshExecutablePathOrNull = + (sshExecutableOrNull != null) ? sshExecutableOrNull.getPath() : null; this.rsyncTerminator = new AtomicReference<ITerminable>(null); this.overwriteMode = false; this.destinationDirectoryRequiresDeletionBeforeCreation = false; @@ -170,12 +177,19 @@ public final class RsyncCopier implements IPathCopier, IDirectoryImmutableCopier final boolean destinationDirectoryRequiresDeletionBeforeCreation, final boolean overwrite, final String... cmdLineFlags) { - assert rsyncExecutable != null && rsyncExecutable.exists(); - assert sshExecutableOrNull == null || rsyncExecutable.exists(); - + if (rsyncExecutable == null) + { + throw new ConfigurationFailureException("No rsync executable available."); + } + if (rsyncExecutable.exists() == false) + { + throw new ConfigurationFailureException("rsync executable '" + rsyncExecutable + + "' does not exist."); + } this.rsyncExecutable = rsyncExecutable.getAbsolutePath(); this.rsyncVersion = RsyncVersionChecker.getVersion(rsyncExecutable.getAbsolutePath()); - this.sshExecutable = (sshExecutableOrNull != null) ? sshExecutableOrNull.getPath() : null; + this.sshExecutablePathOrNull = + (sshExecutableOrNull != null) ? sshExecutableOrNull.getPath() : null; this.destinationDirectoryRequiresDeletionBeforeCreation = destinationDirectoryRequiresDeletionBeforeCreation; this.overwriteMode = overwrite; @@ -417,6 +431,10 @@ public final class RsyncCopier implements IPathCopier, IDirectoryImmutableCopier public boolean checkRsyncConnectionViaSsh(String host, String rsyncExecutableOnHostOrNull, long millisToWaitForCompletion) { + if (sshExecutablePathOrNull == null) + { + return false; + } if (remoteHostRsyncMap.containsKey(host)) { return true; @@ -434,7 +452,7 @@ public final class RsyncCopier implements IPathCopier, IDirectoryImmutableCopier return false; } final List<String> commandLineList = - createSshCommand(host, sshExecutable, rsyncExec + " --version"); + createSshCommand(host, sshExecutablePathOrNull, rsyncExec + " --version"); final ProcessResult verResult = runCommand(commandLineList, millisToWaitForCompletion); verResult.log(); if (verResult.isOK() == false || verResult.getOutput().size() == 0) @@ -464,7 +482,8 @@ public final class RsyncCopier implements IPathCopier, IDirectoryImmutableCopier private String tryFindRemoteRsyncExecutable(String host, long millisToWaitForCompletion) { - List<String> commandLineList = createSshCommand(host, sshExecutable, "type -p rsync"); + List<String> commandLineList = + createSshCommand(host, sshExecutablePathOrNull, "type -p rsync"); final ProcessResult result = runCommand(commandLineList, millisToWaitForCompletion); result.log(); if (result.isOK() && result.getOutput().size() != 1) @@ -527,9 +546,10 @@ public final class RsyncCopier implements IPathCopier, IDirectoryImmutableCopier assert sourcePath != null && (sourceHostOrNull != null || sourcePath.exists()); assert destinationDirectory != null && (destinationHostOrNull != null || destinationDirectory.isDirectory()); - assert (destinationHostOrNull != null && sshExecutable != null) + assert (destinationHostOrNull != null && sshExecutablePathOrNull != null) || (destinationHostOrNull == null); - assert (sourceHostOrNull != null && sshExecutable != null) || (sourceHostOrNull == null); + assert (sourceHostOrNull != null && sshExecutablePathOrNull != null) + || (sourceHostOrNull == null); final List<String> commandLineList = new ArrayList<String>(); final RsyncRecord remoteRsyncOrNull = @@ -552,11 +572,12 @@ public final class RsyncCopier implements IPathCopier, IDirectoryImmutableCopier commandLineList.add("--append"); } } - if (sshExecutable != null && (destinationHostOrNull != null || sourceHostOrNull != null) + if (sshExecutablePathOrNull != null + && (destinationHostOrNull != null || sourceHostOrNull != null) && rsyncModuleNameOrNull == null) { commandLineList.add("--rsh"); - commandLineList.add(getSshExecutableArgument(sshExecutable)); + commandLineList.add(getSshExecutableArgument(sshExecutablePathOrNull)); if (remoteRsyncOrNull != null) { commandLineList.add("--rsync-path");