From 3f0306714a0dffefbc3e12df0fea3162c18a1e17 Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Thu, 5 Jan 2012 20:20:14 +0000 Subject: [PATCH] Make HardLinkMaker and FastHardLinkMaker fall back to regular copies if creating a hardlink is not supported. SVN: 24112 --- .../common/filesystem/FastHardLinkMaker.java | 15 ++++++++++++++- .../cisd/common/filesystem/HardLinkMaker.java | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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 92af00b7e99..e3b8b35dffa 100644 --- a/common/source/java/ch/systemsx/cisd/common/filesystem/FastHardLinkMaker.java +++ b/common/source/java/ch/systemsx/cisd/common/filesystem/FastHardLinkMaker.java @@ -22,6 +22,7 @@ import ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked; import ch.systemsx.cisd.base.unix.Unix; import ch.systemsx.cisd.common.TimingParameters; import ch.systemsx.cisd.common.concurrent.MonitoringProxy; +import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.exceptions.Status; /** @@ -66,7 +67,19 @@ public class FastHardLinkMaker implements IFileImmutableCopier return Status.OK; } catch (IOExceptionUnchecked ex) { - return Status.createError(ex.getCause().getMessage()); + final String errorMsg = ex.getCause().getMessage(); + if (errorMsg.endsWith("Operation not supported")) + { + try + { + FileUtilities.copyFileTo(source, destination, true); + return Status.OK; + } catch (EnvironmentFailureException ex2) + { + return Status.createError(ex2.getMessage()); + } + } + return Status.createError(errorMsg); } } }; diff --git a/common/source/java/ch/systemsx/cisd/common/filesystem/HardLinkMaker.java b/common/source/java/ch/systemsx/cisd/common/filesystem/HardLinkMaker.java index 01d1b81dd66..bbb5985e06a 100644 --- a/common/source/java/ch/systemsx/cisd/common/filesystem/HardLinkMaker.java +++ b/common/source/java/ch/systemsx/cisd/common/filesystem/HardLinkMaker.java @@ -28,6 +28,7 @@ import org.apache.log4j.Logger; import ch.systemsx.cisd.base.exceptions.InterruptedExceptionUnchecked; import ch.systemsx.cisd.base.utilities.OSUtilities; import ch.systemsx.cisd.common.TimingParameters; +import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.exceptions.Status; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; @@ -179,6 +180,21 @@ public class HardLinkMaker implements IFileImmutableCopier final Status ok = runRepeatableProcess(processTask, timingParameters.getMaxRetriesOnFailure(), timingParameters.getIntervalToWaitAfterFailureMillis()); + if (ok.isError()) + { + final String errorMsg = ok.tryGetErrorMessage(); + if (errorMsg != null && errorMsg.endsWith("Operation not supported")) + { + try + { + FileUtilities.copyFileTo(source, destFile, true); + return Status.OK; + } catch (EnvironmentFailureException ex) + { + return Status.createError(ex.getMessage()); + } + } + } return ok; } -- GitLab