From c1f929e068693467c3f485607f08ef88d4a5542c Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 29 Apr 2018 15:32:37 +0200 Subject: create avatar path before saving avatar --- .../pixart/messenger/persistance/FileBackend.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/main/java/de/pixart/messenger/persistance') 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; -- cgit v1.2.3