FileUtils#lastModifiedInstant should not log error if path doesn't exist

Change-Id: Id8447735beb24becb41612d3d29d5351f8273d22
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2019-08-17 00:16:32 +02:00
parent f383206ace
commit 31356f5d18
1 changed files with 7 additions and 1 deletions

View File

@ -55,6 +55,7 @@
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.LinkOption; import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
@ -677,9 +678,14 @@ static Instant lastModifiedInstant(Path path) {
try { try {
return Files.getLastModifiedTime(path, LinkOption.NOFOLLOW_LINKS) return Files.getLastModifiedTime(path, LinkOption.NOFOLLOW_LINKS)
.toInstant(); .toInstant();
} catch (NoSuchFileException e) {
LOG.debug(
"Cannot read lastModifiedInstant since path {} does not exist", //$NON-NLS-1$
path);
return Instant.EPOCH;
} catch (IOException e) { } catch (IOException e) {
LOG.error(MessageFormat LOG.error(MessageFormat
.format(JGitText.get().readLastModifiedFailed, path)); .format(JGitText.get().readLastModifiedFailed, path), e);
return Instant.ofEpochMilli(path.toFile().lastModified()); return Instant.ofEpochMilli(path.toFile().lastModified());
} }
} }