aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-29 15:32:37 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-29 15:32:37 +0200
commitc1f929e068693467c3f485607f08ef88d4a5542c (patch)
tree7aafeefb534dd5bfeaf818bdcd78dba321fc726d /src/main
parentb5b6b934b768b4c4f29f6e63d5de9f308dcd3cba (diff)
create avatar path before saving avatar
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 89f7e639e..3613802aa 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -712,10 +712,14 @@ public class FileBackend {
avatar.size = file.length();
} else {
file = new File(mXmppConnectionService.getCacheDir().getAbsolutePath() + "/" + UUID.randomUUID().toString());
- file.getParentFile().mkdirs();
+ if (file.getParentFile().mkdirs()) {
+ Log.d(Config.LOGTAG, "created cache directory");
+ }
OutputStream os = null;
try {
- file.createNewFile();
+ if (!file.createNewFile()) {
+ Log.d(Config.LOGTAG, "unable to create temporary file " + file.getAbsolutePath());
+ }
os = new FileOutputStream(file);
MessageDigest digest = MessageDigest.getInstance("SHA-1");
digest.reset();
@@ -726,11 +730,20 @@ public class FileBackend {
mDigestOutputStream.close();
String sha1sum = CryptoHelper.bytesToHex(digest.digest());
if (sha1sum.equals(avatar.sha1sum)) {
+ File outputFile = new File(getAvatarPath(avatar.getFilename()));
+ if (outputFile.getParentFile().mkdirs()) {
+ Log.d(Config.LOGTAG, "created avatar directory");
+ }
String filename = getAvatarPath(avatar.getFilename());
- file.renameTo(new File(filename));
+ if (!file.renameTo(new File(filename))) {
+ Log.d(Config.LOGTAG, "unable to rename " + file.getAbsolutePath() + " to " + outputFile);
+ return false;
+ }
} else {
Log.d(Config.LOGTAG, "sha1sum mismatch for " + avatar.owner);
- file.delete();
+ if (!file.delete()) {
+ Log.d(Config.LOGTAG, "unable to delete temporary file");
+ }
return false;
}
avatar.size = bytes.length;