Skip to content

Commit

Permalink
CHE-5040:Replace md5 calculation for avoid problem with big files (#5090
Browse files Browse the repository at this point in the history
)

* Replace md5 calculation for avoid problem with big files

Signed-off-by: Vitalii Parfonov <vparfonov@codenvy.com>
  • Loading branch information
Vitalii Parfonov authored May 17, 2017
1 parent ae70ebf commit 19360a0
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 19360a0

Please sign in to comment.