some more simple fs cleanups.

the isSameFile() sha1 logic is just flat out buggy, in addition to wasting cpu.

Closes #9827
This commit is contained in:
Robert Muir 2015-02-23 13:24:30 -05:00
parent 4ef430d1e1
commit daa8e5f226
4 changed files with 12 additions and 24 deletions

View File

@ -78,9 +78,10 @@ public abstract class CheckFileCommand extends CliTool.Command {
try { try {
boolean supportsPosixPermissions = Files.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class); boolean supportsPosixPermissions = Files.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class);
if (supportsPosixPermissions) { if (supportsPosixPermissions) {
permissions.put(path, Files.getPosixFilePermissions(path)); PosixFileAttributes attributes = Files.readAttributes(path, PosixFileAttributes.class);
owners.put(path, Files.getOwner(path).getName()); permissions.put(path, attributes.permissions());
groups.put(path, Files.readAttributes(path, PosixFileAttributes.class).group().getName()); owners.put(path, attributes.owner().getName());
groups.put(path, attributes.group().getName());
} }
} catch (IOException e) { } catch (IOException e) {
// silently swallow if not supported, no need to log things // silently swallow if not supported, no need to log things

View File

@ -32,8 +32,6 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -220,7 +218,7 @@ public final class FileSystemUtils {
} }
/** /**
* Compares the content of two paths by comparing their SHA-SUM * Compares the content of two paths by comparing them
*/ */
private boolean isSameFile(Path first, Path second) throws IOException { private boolean isSameFile(Path first, Path second) throws IOException {
// do quick file size comparison before hashing // do quick file size comparison before hashing
@ -229,20 +227,9 @@ public final class FileSystemUtils {
return false; return false;
} }
try { byte[] firstBytes = Files.readAllBytes(first);
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); byte[] secondBytes = Files.readAllBytes(second);
return Arrays.equals(firstBytes, secondBytes);
messageDigest.update(Files.readAllBytes(first));
byte[] pathSha = messageDigest.digest();
messageDigest.reset();
messageDigest.update(Files.readAllBytes(second));
byte[] fileSha = messageDigest.digest();
return Arrays.equals(pathSha, fileSha);
} catch (NoSuchAlgorithmException e) {
return false;
}
} }
}); });
} }

View File

@ -224,7 +224,9 @@ public class IndexShardGateway extends AbstractIndexShardComponent implements Cl
StreamInput in = null; StreamInput in = null;
try { try {
if (logger.isTraceEnabled()) {
logger.trace("recovering translog file: {} length: {}", recoveringTranslogFile, Files.size(recoveringTranslogFile)); logger.trace("recovering translog file: {} length: {}", recoveringTranslogFile, Files.size(recoveringTranslogFile));
}
TranslogStream stream = TranslogStreams.translogStreamFor(recoveringTranslogFile); TranslogStream stream = TranslogStreams.translogStreamFor(recoveringTranslogFile);
try { try {
in = stream.openInput(recoveringTranslogFile); in = stream.openInput(recoveringTranslogFile);

View File

@ -375,9 +375,7 @@ public class PluginManager {
Tuple<Settings, Environment> initialSettings = InternalSettingsPreparer.prepareSettings(EMPTY_SETTINGS, true); Tuple<Settings, Environment> initialSettings = InternalSettingsPreparer.prepareSettings(EMPTY_SETTINGS, true);
try { try {
if (!Files.exists(initialSettings.v2().pluginsFile())) {
Files.createDirectories(initialSettings.v2().pluginsFile()); Files.createDirectories(initialSettings.v2().pluginsFile());
}
} catch (IOException e) { } catch (IOException e) {
displayHelp("Unable to create plugins dir: " + initialSettings.v2().pluginsFile()); displayHelp("Unable to create plugins dir: " + initialSettings.v2().pluginsFile());
System.exit(EXIT_CODE_ERROR); System.exit(EXIT_CODE_ERROR);