Skip to content
Snippets Groups Projects
Commit 862f04e7 authored by brinn's avatar brinn
Browse files

refactor: - rename IPathImmutableCopier.tryCopy() to tryImmutableCopy()

- better structure methods in RecursiveHardLinkMaker

SVN: 6978
parent 5864a601
No related branches found
No related tags found
No related merge requests found
......@@ -159,7 +159,7 @@ final class Directory extends AbstractNode implements IDirectory
assert name != null : "Name can not be null.";
final java.io.File file = getNodeFile(node);
final java.io.File fileLink =
LinkMakerProvider.getLinkMaker().tryCopy(file, nodeFile, name);
LinkMakerProvider.getLinkMaker().tryImmutableCopy(file, nodeFile, name);
if (fileLink != null)
{
final Link link = (Link) NodeFactory.createLinkNode(name, file);
......
......@@ -38,5 +38,5 @@ public interface IPathImmutableCopier
* @param nameOrNull the link name in the destination directory.
* @return the new path created, or <code>null</code> if the operation fails.
*/
File tryCopy(final File path, final File destinationDirectory, final String nameOrNull);
File tryImmutableCopy(final File path, final File destinationDirectory, final String nameOrNull);
}
......@@ -41,7 +41,7 @@ import ch.systemsx.cisd.common.process.ProcessExecutionHelper;
public final class RecursiveHardLinkMaker implements IPathImmutableCopier
{
private static final String HARD_LINK_EXEC = "ln";
private static final Logger operationLog =
LogFactory.getLogger(LogCategory.OPERATION, RecursiveHardLinkMaker.class);
......@@ -66,11 +66,6 @@ public final class RecursiveHardLinkMaker implements IPathImmutableCopier
return new RetryingOperationTimeout(0, 1, 0);
}
public static final IPathImmutableCopier create(final String linkExecPath)
{
return new RecursiveHardLinkMaker(linkExecPath, null);
}
private static class RetryingOperationTimeout
{
private final long millisToWaitForCompletion;
......@@ -103,6 +98,30 @@ public final class RecursiveHardLinkMaker implements IPathImmutableCopier
}
}
//
// Factory methods
//
/**
* Creates copier which won't retry an operation if it fails.
*
* @param linkExecPath The path to the <code>ln</code> executable.
*/
public static final IPathImmutableCopier create(final String linkExecPath)
{
return new RecursiveHardLinkMaker(linkExecPath, null);
}
/**
* Creates copier trying to find the path to the <code>ln</code> executable.
*
* @return <code>null</code> if the <code>ln</code> executable was not found.
*/
public static final IPathImmutableCopier tryCreate()
{
return tryCreate(null);
}
/**
* Creates copier which is able to retry the operation of creating each hard link of a file if
* it does not complete after a specified timeout.
......@@ -125,12 +144,6 @@ public final class RecursiveHardLinkMaker implements IPathImmutableCopier
return tryCreate(timeout);
}
/** Creates copier trying to find the path to hard link tool, null if nothing is found. */
public static final IPathImmutableCopier tryCreate()
{
return tryCreate(null);
}
private static final IPathImmutableCopier tryCreate(
RetryingOperationTimeout singleFileLinkTimeoutOrNull)
{
......@@ -142,6 +155,10 @@ public final class RecursiveHardLinkMaker implements IPathImmutableCopier
return new RecursiveHardLinkMaker(lnExec.getAbsolutePath(), singleFileLinkTimeoutOrNull);
}
//
// IPathImmutableCopier
//
/**
* Copies <var>path</var> (file or directory) to <var>destinationDirectory</var> by
* duplicating directory structure and creating hard link for each file.
......@@ -149,7 +166,7 @@ public final class RecursiveHardLinkMaker implements IPathImmutableCopier
* <i>Note that <var>nameOrNull</var> cannot already exist in given <var>destinationDirectory</var>.</i>
* </p>
*/
public final File tryCopy(final File path, final File destinationDirectory,
public final File tryImmutableCopy(final File path, final File destinationDirectory,
final String nameOrNull)
{
assert path != null : "Given path can not be null.";
......
......@@ -143,7 +143,7 @@ public class RecursiveHardLinkMakerTest
{
File inputDir = createDirectory(workingDirectory, "resource-to-copy");
createStructure(inputDir);
File newInput = createHardLinkCopier().tryCopy(inputDir, outputDir, null);
File newInput = createHardLinkCopier().tryImmutableCopy(inputDir, outputDir, null);
assert newInput != null;
assertStructureExists(newInput);
......@@ -170,7 +170,7 @@ public class RecursiveHardLinkMakerTest
File src = createFile(workingDirectory, "fileXXX");
assertFileExists(src);
File dest = createHardLinkCopier().tryCopy(src, outputDir, null);
File dest = createHardLinkCopier().tryImmutableCopy(src, outputDir, null);
assertFileExists(dest);
modifyDest(dest);
......
......@@ -272,7 +272,7 @@ public final class LocalProcessor implements IPathHandler, IRecoverableTimerTask
return;
}
}
extraTmpCopy = copier.tryCopy(path, tempDir, null);
extraTmpCopy = copier.tryImmutableCopy(path, tempDir, null);
if (extraTmpCopy == null)
{
notificationLog.error(String.format("Creating extra copy of '%s' failed.", path));
......
......@@ -85,7 +85,7 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory
// IPathImmutableCopier
//
public final File tryCopy(final File file, final File destinationDirectory,
public final File tryImmutableCopy(final File file, final File destinationDirectory,
final String nameOrNull)
{
final Status status = normalCopier.copy(file, destinationDirectory);
......
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