aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2015-03-17 21:10:02 +0100
committerDaniel Gultsch <daniel@gultsch.de>2015-03-17 21:10:02 +0100
commitae274ac728bfb247e5a2b3249b7d2369909ae6f6 (patch)
tree743fc03b20d5e2d789e9f919b61089be31d395ae
parent4aab45533ac8a32be2fe66b266b845aed02acf1b (diff)
parent52af62d298da5780fc1f4a931b3007124b4760eb (diff)
Merge pull request #1041 from weiss/fix-cached-avatar-size
Set file size also for cached avatars
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java60
1 files changed, 31 insertions, 29 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index 62987aaa..c499d499 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -318,39 +318,41 @@ public class FileBackend {
}
public boolean save(Avatar avatar) {
+ File file;
if (isAvatarCached(avatar)) {
- return true;
- }
- String filename = getAvatarPath(avatar.getFilename());
- File file = new File(filename + ".tmp");
- file.getParentFile().mkdirs();
- try {
- file.createNewFile();
- FileOutputStream mFileOutputStream = new FileOutputStream(file);
- MessageDigest digest = MessageDigest.getInstance("SHA-1");
- digest.reset();
- DigestOutputStream mDigestOutputStream = new DigestOutputStream(
- mFileOutputStream, digest);
- mDigestOutputStream.write(avatar.getImageAsBytes());
- mDigestOutputStream.flush();
- mDigestOutputStream.close();
- avatar.size = file.length();
- String sha1sum = CryptoHelper.bytesToHex(digest.digest());
- if (sha1sum.equals(avatar.sha1sum)) {
- file.renameTo(new File(filename));
- return true;
- } else {
- Log.d(Config.LOGTAG, "sha1sum mismatch for " + avatar.owner);
- file.delete();
+ file = new File(getAvatarPath(avatar.getFilename()));
+ } else {
+ String filename = getAvatarPath(avatar.getFilename());
+ file = new File(filename + ".tmp");
+ file.getParentFile().mkdirs();
+ try {
+ file.createNewFile();
+ FileOutputStream mFileOutputStream = new FileOutputStream(file);
+ MessageDigest digest = MessageDigest.getInstance("SHA-1");
+ digest.reset();
+ DigestOutputStream mDigestOutputStream = new DigestOutputStream(
+ mFileOutputStream, digest);
+ mDigestOutputStream.write(avatar.getImageAsBytes());
+ mDigestOutputStream.flush();
+ mDigestOutputStream.close();
+ String sha1sum = CryptoHelper.bytesToHex(digest.digest());
+ if (sha1sum.equals(avatar.sha1sum)) {
+ file.renameTo(new File(filename));
+ } else {
+ Log.d(Config.LOGTAG, "sha1sum mismatch for " + avatar.owner);
+ file.delete();
+ return false;
+ }
+ } catch (FileNotFoundException e) {
+ return false;
+ } catch (IOException e) {
+ return false;
+ } catch (NoSuchAlgorithmException e) {
return false;
}
- } catch (FileNotFoundException e) {
- return false;
- } catch (IOException e) {
- return false;
- } catch (NoSuchAlgorithmException e) {
- return false;
}
+ avatar.size = file.length();
+ return true;
}
public String getAvatarPath(String avatar) {