From 19360a0496ae228dc7bc24daeec2a02eb058eec3 Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Wed, 17 May 2017 10:04:53 +0300 Subject: [PATCH] CHE-5040:Replace md5 calculation for avoid problem with big files (#5090) * Replace md5 calculation for avoid problem with big files Signed-off-by: Vitalii Parfonov --- .../vfs/impl/file/event/detectors/EditorFileTracker.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/impl/file/event/detectors/EditorFileTracker.java b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/impl/file/event/detectors/EditorFileTracker.java index 89c93aea642..cf22c2e52b8 100644 --- a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/impl/file/event/detectors/EditorFileTracker.java +++ b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/impl/file/event/detectors/EditorFileTracker.java @@ -12,7 +12,6 @@ import com.google.common.hash.Hashing; -import org.eclipse.che.api.core.ForbiddenException; import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; @@ -30,6 +29,7 @@ import javax.inject.Named; import javax.inject.Singleton; import java.io.File; +import java.io.IOException; import java.nio.file.Files; import java.util.HashMap; import java.util.Map; @@ -39,6 +39,7 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; +import static com.google.common.io.Files.hash; import static java.nio.charset.Charset.defaultCharset; import static org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.DELETED; import static org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.MODIFIED; @@ -210,8 +211,9 @@ public void run() { private String hashFile(String path) { try { VirtualFile file = vfsProvider.getVirtualFileSystem().getRoot().getChild(Path.of(path)); - return Hashing.md5().hashString(file == null ? "" : file.getContentAsString(), defaultCharset()).toString(); - } catch (ServerException | ForbiddenException e) { + return file == null ? Hashing.md5().hashString("", defaultCharset()).toString() + : hash(file.toIoFile(), Hashing.md5()).toString(); + } catch (ServerException | IOException e) { LOG.error("Error trying to read {} file and broadcast it", path, e); } return null;