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:
parent
4ef430d1e1
commit
daa8e5f226
|
@ -78,9 +78,10 @@ public abstract class CheckFileCommand extends CliTool.Command {
|
|||
try {
|
||||
boolean supportsPosixPermissions = Files.getFileStore(path).supportsFileAttributeView(PosixFileAttributeView.class);
|
||||
if (supportsPosixPermissions) {
|
||||
permissions.put(path, Files.getPosixFilePermissions(path));
|
||||
owners.put(path, Files.getOwner(path).getName());
|
||||
groups.put(path, Files.readAttributes(path, PosixFileAttributes.class).group().getName());
|
||||
PosixFileAttributes attributes = Files.readAttributes(path, PosixFileAttributes.class);
|
||||
permissions.put(path, attributes.permissions());
|
||||
owners.put(path, attributes.owner().getName());
|
||||
groups.put(path, attributes.group().getName());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// silently swallow if not supported, no need to log things
|
||||
|
|
|
@ -32,8 +32,6 @@ import java.nio.charset.Charset;
|
|||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
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 {
|
||||
// do quick file size comparison before hashing
|
||||
|
@ -229,20 +227,9 @@ public final class FileSystemUtils {
|
|||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
|
||||
|
||||
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;
|
||||
}
|
||||
byte[] firstBytes = Files.readAllBytes(first);
|
||||
byte[] secondBytes = Files.readAllBytes(second);
|
||||
return Arrays.equals(firstBytes, secondBytes);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -224,7 +224,9 @@ public class IndexShardGateway extends AbstractIndexShardComponent implements Cl
|
|||
StreamInput in = null;
|
||||
|
||||
try {
|
||||
logger.trace("recovering translog file: {} length: {}", recoveringTranslogFile, Files.size(recoveringTranslogFile));
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("recovering translog file: {} length: {}", recoveringTranslogFile, Files.size(recoveringTranslogFile));
|
||||
}
|
||||
TranslogStream stream = TranslogStreams.translogStreamFor(recoveringTranslogFile);
|
||||
try {
|
||||
in = stream.openInput(recoveringTranslogFile);
|
||||
|
|
|
@ -375,9 +375,7 @@ public class PluginManager {
|
|||
Tuple<Settings, Environment> initialSettings = InternalSettingsPreparer.prepareSettings(EMPTY_SETTINGS, true);
|
||||
|
||||
try {
|
||||
if (!Files.exists(initialSettings.v2().pluginsFile())) {
|
||||
Files.createDirectories(initialSettings.v2().pluginsFile());
|
||||
}
|
||||
Files.createDirectories(initialSettings.v2().pluginsFile());
|
||||
} catch (IOException e) {
|
||||
displayHelp("Unable to create plugins dir: " + initialSettings.v2().pluginsFile());
|
||||
System.exit(EXIT_CODE_ERROR);
|
||||
|
|
Loading…
Reference in New Issue