From 2a552849f1219996303541110d56a058d38aa474 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 22 Feb 2024 21:49:59 -0500 Subject: [PATCH] Don't try to copy content we already have Saves time, but also saves us copying over ourselves and destroying the file --- .../java/eu/siacs/conversations/persistance/FileBackend.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index b078428fdbdfd304826b5fce54bfc29e31e09979..9c35d6386fff5dc0bc971a4113c2f53af44ee541 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -743,7 +743,10 @@ public class FileBackend { "copy file (" + uri.toString() + ") to private storage " + file.getAbsolutePath()); file.getParentFile().mkdirs(); try { - file.createNewFile(); + if (!file.createNewFile() && file.length() > 0) { + if (file.canRead() && file.getName().startsWith("zb2")) return; // We have this content already + throw new FileCopyException(R.string.error_unable_to_create_temporary_file); + } } catch (IOException e) { throw new FileCopyException(R.string.error_unable_to_create_temporary_file); }