Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur <desperateCoder@users.noreply.github.com>2022-01-04 14:11:17 +0300
committerGitHub <noreply@github.com>2022-01-04 14:11:17 +0300
commit1dcabdb46ca28ff8b5a6035ecbcf3f4882c63c99 (patch)
tree4a38d88fa2364fb9d994f79be9ea45ac574377db /app/src/main
parente605c8fc3df3ba17a127e626d48ed91608bb39ab (diff)
parent3e1e06797be3e8918c9be1af365e9cff387b5b4f (diff)
Merge pull request #1199 from NeilSeligmann/fix/synchronizedTempCacheCreation
Thanks @NeilSeligmann! Looking forward to your next contribution! Stay safe, buddy!
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java15
1 files changed, 14 insertions, 1 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java
index 3695663b2..2e4bb9406 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/FilesUtil.java
@@ -46,6 +46,19 @@ public class FilesUtil {
}
/**
+ * Creates a temporary cache directory in a synchronized manner, in order to mitigate multi-threaded collisions
+ * @param tempDir - Temporal Cache Directory
+ * @return success
+ */
+ static synchronized boolean createTempCacheDirectory(@NonNull File tempDir) {
+ if (tempDir.exists()) {
+ return true;
+ }
+
+ return tempDir.mkdirs();
+ }
+
+ /**
* Creates a new {@link File}
*/
public static File getTempCacheFile(@NonNull Context context, String fileName) throws IOException {
@@ -59,7 +72,7 @@ public class FilesUtil {
}
if (!tempDir.exists()) {
DeckLog.verbose("-- The folder in which the new file should be created does not exist yet. Trying to create it…");
- if (tempDir.mkdirs()) {
+ if (createTempCacheDirectory(tempDir)) {
DeckLog.verbose("--- Creation successful");
} else {
throw new IOException("Directory for temporary file does not exist and could not be created.");