Repository navigation
Feature: Improve UX when importing vaults with invalid structure - #4243
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR introduces vault directory validation with structured error reporting. A new Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java (1)
303-314:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDrag-and-drop still bypasses the new invalid-vault dialog.
This path only forwards entries where
containsVault(...)returns true, butcontainsVault(...)rejectsDirStructure.UNRELATED. That is the exact branch whereVaultListManager.assertIsVaultDirectory(...)now performs the detailed checks and throwsNotAVaultDirectoryException, so invalid vault directories are still ignored here instead of showing the new error dialog.Also applies to: 321-326
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java` around lines 303 - 314, handleDragEvent currently filters dropped files using containsVault(...) which returns false for DirStructure.UNRELATED and thus skips paths that should trigger VaultListManager.assertIsVaultDirectory(...) and display the NotAVaultDirectoryException dialog; update handleDragEvent (and the similar branch handling at the other drop location) to collect candidate paths from the dragboard without pre-filtering by containsVault, then for each candidate call VaultListManager.assertIsVaultDirectory(...) inside a try/catch that on success calls addVault(...) and on NotAVaultDirectoryException shows the new invalid-vault dialog; also ensure draggingVaultOver logic uses a light-weight predicate (or a separate quick check) to decide acceptTransferModes but do not suppress paths that must produce the error dialog.
🧹 Nitpick comments (1)
src/test/java/org/cryptomator/common/vaults/VaultListManagerTest.java (1)
19-68: ⚡ Quick winAdd coverage for the remaining reason branches.
The suite never exercises
VAULT_CONFIG_ACCESS_DENIEDorUNSUPPORTED_STRUCTURE, even though both now drive user-facing error messages. A targeted regression test for each would make the new validation contract much harder to break silently.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/org/cryptomator/common/vaults/VaultListManagerTest.java` around lines 19 - 68, Add two unit tests that exercise the NotAVaultDirectoryException.Reason.VAULT_CONFIG_ACCESS_DENIED and .UNSUPPORTED_STRUCTURE branches by calling VaultListManager.assertIsVaultDirectory: for VAULT_CONFIG_ACCESS_DENIED create the DATA_DIR_NAME and VAULTCONFIG_FILENAME but make the vault config file unreadable (use Files.setPosixFilePermissions or equivalent setup so reading the config triggers an access-denied path) and assert the thrown exception's notAVaultReason() is VAULT_CONFIG_ACCESS_DENIED; for UNSUPPORTED_STRUCTURE create a DATA_DIR_NAME and a combination of files/dirs that match the legacy/modern check failure scenario (e.g. a file structure that prevents locating VAULTCONFIG_FILENAME or MASTERKEY_FILENAME as expected) and assert the thrown reason is UNSUPPORTED_STRUCTURE; reference VaultListManager.assertIsVaultDirectory, NotAVaultDirectoryException.Reason, VAULTCONFIG_FILENAME, MASTERKEY_FILENAME and DATA_DIR_NAME when adding the tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/org/cryptomator/common/vaults/VaultListManager.java`:
- Around line 92-100: The add(Path) method in VaultListManager performs the
existence check off the FX thread but only enqueues vaultList.add(...) on the FX
thread, allowing race conditions where multiple callers add duplicates; fix by
making the check+add atomic on the FX thread—either move the get(...) and add
logic into a single Platform.runLater block that calls addVault(newVault) (which
uses isAlreadyAdded(...)) so the presence check and add occur together, or guard
against concurrent adds by introducing a concurrent Set of pending paths
checked/updated around newVault creation and before enqueueing
Platform.runLater; ensure you reference VaultListManager.add(Path),
newVaultSettings(...), addVault(Vault), isAlreadyAdded(...), Platform.runLater
and vaultList.add(newVault) when making the change.
- Around line 123-132: In VaultListManager.checkConfigFile, don’t map every
IOException to VAULT_CONFIG_ACCESS_DENIED; instead update the exception handling
around opening/reading vaultConfig (resolved from VAULTCONFIG_FILENAME) to
distinguish AccessDeniedException -> throw NotAVaultDirectoryException(...,
Reason.VAULT_CONFIG_ACCESS_DENIED), NoSuchFileException -> throw
NotAVaultDirectoryException(..., Reason.MISSING_VAULT_CONFIG), and any other
IOException -> throw NotAVaultDirectoryException(...,
Reason.UNSUPPORTED_STRUCTURE) (or the appropriate Reason for unexpected IO
errors), keeping the initial exists() check but accounting for race conditions
by relying on these specific catches in the try-with-resources block inside
checkConfigFile.
In `@src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java`:
- Around line 332-344: The async add can enqueue duplicates because two tasks
can concurrently call vaultListManager.add(target) after normalization; fix by
making the existence-check-and-add atomic: either (A) perform the
check-and-schedule on the FX thread (use Platform.runLater to check
vaultListManager.get(normalizedTarget) and only call
vaultListManager.add(normalizedTarget) / vaultList.add(...) if absent) or (B)
add an atomic/thread-safe method to VaultListManager (e.g., addIfAbsent(Path) or
synchronize inside VaultListManager.add so it checks get(normalizedPath) and
enqueues the vault on the FX thread in one synchronized/atomic operation) and
call that from addVault via the executor. Ensure you reference the normalized
target (the local variable target) when performing the check so duplicates are
detected before enqueuing.
---
Outside diff comments:
In `@src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java`:
- Around line 303-314: handleDragEvent currently filters dropped files using
containsVault(...) which returns false for DirStructure.UNRELATED and thus skips
paths that should trigger VaultListManager.assertIsVaultDirectory(...) and
display the NotAVaultDirectoryException dialog; update handleDragEvent (and the
similar branch handling at the other drop location) to collect candidate paths
from the dragboard without pre-filtering by containsVault, then for each
candidate call VaultListManager.assertIsVaultDirectory(...) inside a try/catch
that on success calls addVault(...) and on NotAVaultDirectoryException shows the
new invalid-vault dialog; also ensure draggingVaultOver logic uses a
light-weight predicate (or a separate quick check) to decide acceptTransferModes
but do not suppress paths that must produce the error dialog.
---
Nitpick comments:
In `@src/test/java/org/cryptomator/common/vaults/VaultListManagerTest.java`:
- Around line 19-68: Add two unit tests that exercise the
NotAVaultDirectoryException.Reason.VAULT_CONFIG_ACCESS_DENIED and
.UNSUPPORTED_STRUCTURE branches by calling
VaultListManager.assertIsVaultDirectory: for VAULT_CONFIG_ACCESS_DENIED create
the DATA_DIR_NAME and VAULTCONFIG_FILENAME but make the vault config file
unreadable (use Files.setPosixFilePermissions or equivalent setup so reading the
config triggers an access-denied path) and assert the thrown exception's
notAVaultReason() is VAULT_CONFIG_ACCESS_DENIED; for UNSUPPORTED_STRUCTURE
create a DATA_DIR_NAME and a combination of files/dirs that match the
legacy/modern check failure scenario (e.g. a file structure that prevents
locating VAULTCONFIG_FILENAME or MASTERKEY_FILENAME as expected) and assert the
thrown reason is UNSUPPORTED_STRUCTURE; reference
VaultListManager.assertIsVaultDirectory, NotAVaultDirectoryException.Reason,
VAULTCONFIG_FILENAME, MASTERKEY_FILENAME and DATA_DIR_NAME when adding the
tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0f4e0525-9194-47ee-9302-03ba4ee09aa2
📒 Files selected for processing (8)
src/main/java/org/cryptomator/common/vaults/NotAVaultDirectoryException.javasrc/main/java/org/cryptomator/common/vaults/VaultListManager.javasrc/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.javasrc/main/java/org/cryptomator/ui/dialogs/Dialogs.javasrc/main/java/org/cryptomator/ui/fxapp/AppLaunchEventHandler.javasrc/main/java/org/cryptomator/ui/mainwindow/VaultListController.javasrc/main/resources/i18n/strings.propertiessrc/test/java/org/cryptomator/common/vaults/VaultListManagerTest.java
do checking and adding on the fx thread.
|
Test results from UI test:
Overall an improvement, no regressions. |
This PR enhances the UX when an invalid vault is imported.
If the user imports a vault (drag'n'drop, import vault dialog, file association), the vault might be invalid (missing directory, no read access, etc...). We already do a test, but it is encapsulated inside cryptofs only saying "vault, legacy, none" without giving any reason. The user or the support employee needs more information.
Currently, the generic error window is shown, i.e.:
This is fixed by getting a "bad" result in the check analyzes the faulty vault more and displaying a helpful message. All three import user interactions (drag+drop, import dialog, file association) are adjusted to this.