From 385574a618a641e9ab2642e1bd0be27ab2fc96aa Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 15 Mar 2023 12:10:15 +0100 Subject: [PATCH] prevent infinite loop --- .../common/mount/MountPointPreparationException.java | 4 ++++ .../org/cryptomator/common/mount/MountWithinParentUtil.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java b/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java index fb481167c..e4734e011 100644 --- a/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java +++ b/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java @@ -2,6 +2,10 @@ package org.cryptomator.common.mount; public class MountPointPreparationException extends RuntimeException { + public MountPointPreparationException(String msg) { + super(msg); + } + public MountPointPreparationException(Throwable cause) { super(cause); } diff --git a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java index 47986e5e5..0b1d3f669 100644 --- a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java +++ b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java @@ -51,8 +51,13 @@ public final class MountWithinParentUtil { if (SystemUtils.IS_OS_WINDOWS) { Files.setAttribute(hideaway, WIN_HIDDEN_ATTR, true, LinkOption.NOFOLLOW_LINKS); } + int attempts = 0; while (!Files.notExists(mountPoint)) { + if (attempts >= 10) { + throw new MountPointPreparationException("Path " + mountPoint + " could not be cleared"); + } Thread.sleep(1000); + attempts++; } } catch (IOException e) { throw new MountPointPreparationException(e);