Don't try to copy content we already have

Stephen Paul Weber created

Saves time, but also saves us copying over ourselves and destroying the file

Change summary

src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 5 
1 file changed, 4 insertions(+), 1 deletion(-)

Detailed changes

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);
         }