Skip to content
Snippets Groups Projects
Commit 5c8ce1c9 authored by tpylak's avatar tpylak
Browse files

DMV-21 error handling in IFileStore for exists() and lastChanged*()

SVN: 6912
parent cad70e2f
No related branches found
No related tags found
No related merge requests found
......@@ -534,7 +534,7 @@ public final class FileUtilities
private boolean terminated;
LastChangedWorker(final File root, final boolean subDirectoriesOnly, final long reference,
final boolean referenceIsRelative)
final boolean referenceIsRelative) throws UnknownLastChangedException
{
assert root != null;
......@@ -550,15 +550,15 @@ public final class FileUtilities
}
}
private void updateLastChanged(final File path)
private void updateLastChanged(final File path) throws UnknownLastChangedException
{
assert path != null;
final long lastModified = path.lastModified();
if (lastModified == 0)
{
throw new CheckedExceptionTunnel(new IOException(String.format(
"Cannot get the last modification date of '%s'.", path.getPath())));
throw new UnknownLastChangedException(String.format(
"Cannot get the last modification date of '%s'.", path.getPath()));
}
lastChanged = Math.max(lastModified, lastChanged);
......@@ -579,7 +579,7 @@ public final class FileUtilities
}
}
private void traverse(final File path)
private void traverse(final File path) throws UnknownLastChangedException
{
assert path != null;
......@@ -642,12 +642,12 @@ public final class FileUtilities
* entry, but only, if there are entries that are "young enough".
* @return The time when any file in (or below) <var>path</var> has last been changed in the
* file system.
* @throws CheckedExceptionTunnel of an {@link IOException} if the <var>path</var> does not
* exist or is not readable.
* @throws UnknownLastChangedException if the <var>path</var> does not exist or is not
* readable.
* @throws StopException if the thread that the method runs in gets interrupted.
*/
public static long lastChanged(final File path, final boolean subDirectoriesOnly,
final long stopWhenFindYounger)
final long stopWhenFindYounger) throws UnknownLastChangedException
{
return (new LastChangedWorker(path, subDirectoriesOnly, stopWhenFindYounger, false))
.getLastChanged();
......@@ -669,12 +669,12 @@ public final class FileUtilities
* there are entries that are "young enough".
* @return The time when any file in (or below) <var>path</var> has last been changed in the
* file system.
* @throws CheckedExceptionTunnel of an {@link IOException} if the <var>path</var> does not
* exist or is not readable.
* @throws UnknownLastChangedException if the <var>path</var> does not exist or is not
* readable.
* @throws StopException if the thread that the method runs in gets interrupted.
*/
public static long lastChangedRelative(final File path, final boolean subDirectoriesOnly,
final long stopWhenFindYoungerRelative)
final long stopWhenFindYoungerRelative) throws UnknownLastChangedException
{
return (new LastChangedWorker(path, subDirectoriesOnly, stopWhenFindYoungerRelative, true))
.getLastChanged();
......@@ -683,11 +683,11 @@ public final class FileUtilities
/**
* @return The time when any file in (or below) <var>path</var> has last been changed in the
* file system.
* @throws CheckedExceptionTunnel of an {@link IOException} if the <var>path</var> does not
* exist or is not readable.
* @throws UnknownLastChangedException if the <var>path</var> does not exist or is not
* readable.
* @throws StopException if the thread that the method runs in gets interrupted.
*/
public static long lastChanged(final File path)
public static long lastChanged(final File path) throws UnknownLastChangedException
{
return lastChanged(path, false, 0L);
}
......
......@@ -82,6 +82,7 @@ public class FileUtilitiesLastChangedTest
@Test(groups =
{ "slow" }, dataProvider = "testLastChanged")
public void testLastChanged(String dirToCheck, String dirToCreate)
throws UnknownLastChangedException
{
final File testDir = new File(workingDirectory, dirToCheck);
testDir.deleteOnExit();
......
/*
* Copyright 2008 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.common.utilities;
import java.io.IOException;
/**
* Used to signal the error of getting last modification time of a store item
*
* @author Tomasz Pylak
*/
public class UnknownLastChangedException extends IOException
{
private static final long serialVersionUID = 1L;
public UnknownLastChangedException(String errorMsg)
{
super(errorMsg);
}
}
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