From dfc2e6381b44785aa038fd4f45af7703657c67e4 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Thu, 12 Feb 2015 11:36:47 +0100 Subject: [PATCH] CliTool: CheckFileCommand checks for file existence As a CliTool command could potentially also delete files, the CheckFileCommand needs to check if those files exist, before trying to get permissions/owners/groups from that path. --- .../elasticsearch/common/cli/CheckFileCommand.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/elasticsearch/common/cli/CheckFileCommand.java b/src/main/java/org/elasticsearch/common/cli/CheckFileCommand.java index 24f58be392a..c72b826ac13 100644 --- a/src/main/java/org/elasticsearch/common/cli/CheckFileCommand.java +++ b/src/main/java/org/elasticsearch/common/cli/CheckFileCommand.java @@ -92,6 +92,10 @@ public abstract class CheckFileCommand extends CliTool.Command { // check if permissions differ for (Map.Entry> entry : permissions.entrySet()) { + if (!Files.exists(entry.getKey())) { + continue; + } + Set permissionsBeforeWrite = entry.getValue(); Set permissionsAfterWrite = Files.getPosixFilePermissions(entry.getKey()); if (!permissionsBeforeWrite.equals(permissionsAfterWrite)) { @@ -103,6 +107,10 @@ public abstract class CheckFileCommand extends CliTool.Command { // check if owner differs for (Map.Entry entry : owners.entrySet()) { + if (!Files.exists(entry.getKey())) { + continue; + } + String ownerBeforeWrite = entry.getValue(); String ownerAfterWrite = Files.getOwner(entry.getKey()).getName(); if (!ownerAfterWrite.equals(ownerBeforeWrite)) { @@ -112,6 +120,10 @@ public abstract class CheckFileCommand extends CliTool.Command { // check if group differs for (Map.Entry entry : groups.entrySet()) { + if (!Files.exists(entry.getKey())) { + continue; + } + String groupBeforeWrite = entry.getValue(); String groupAfterWrite = Files.readAttributes(entry.getKey(), PosixFileAttributes.class).group().getName(); if (!groupAfterWrite.equals(groupBeforeWrite)) {