Skip to content

Commit 766b562

Browse files
author
Armin Schrenk
authored
Merge pull request #105 from cryptomator/feature/detailed-diagnosticresult-api
Extend HealthAPI to get more specific information about results
2 parents 7aa0a5c + 3e46114 commit 766b562

File tree

7 files changed

+69
-0
lines changed

7 files changed

+69
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.cryptomator.cryptofs.health.api;
2+
3+
public class CommonDetailKeys {
4+
5+
public static final String ENCRYPTED_PATH = "Encrypted Path";
6+
public static final String DIR_ID = "Directory ID";
7+
public static final String DIR_ID_FILE = "Directory ID File";
8+
9+
private CommonDetailKeys() {};
10+
11+
}

src/main/java/org/cryptomator/cryptofs/health/api/DiagnosticResult.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.cryptomator.cryptolib.api.Masterkey;
66

77
import java.nio.file.Path;
8+
import java.util.Map;
89

910
public interface DiagnosticResult {
1011

@@ -42,4 +43,12 @@ default void fix(Path pathToVault, VaultConfig config, Masterkey masterkey, Cryp
4243
throw new UnsupportedOperationException("Preliminary API not yet implemented");
4344
}
4445

46+
/**
47+
* Get more specific info about the result like names of affected resources.
48+
*
49+
* @return A map of strings containing result specific information
50+
*/
51+
default Map<String, String> details() {
52+
return Map.of();
53+
}
4554
}

src/main/java/org/cryptomator/cryptofs/health/dirid/DirIdCollision.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
44

55
import java.nio.file.Path;
6+
import java.util.Map;
7+
8+
import static org.cryptomator.cryptofs.health.api.CommonDetailKeys.DIR_ID;
9+
import static org.cryptomator.cryptofs.health.api.CommonDetailKeys.DIR_ID_FILE;
610

711
/**
812
* The directory id is used more than once.
@@ -28,4 +32,11 @@ public Severity getSeverity() {
2832
public String toString() {
2933
return String.format("Directory ID reused: %s found in %s and %s", dirId, file, otherFile);
3034
}
35+
36+
@Override
37+
public Map<String, String> details() {
38+
return Map.of(DIR_ID, dirId, //
39+
DIR_ID_FILE, file.toString(), //
40+
"Other " + DIR_ID_FILE, otherFile.toString());
41+
}
3142
}

src/main/java/org/cryptomator/cryptofs/health/dirid/HealthyDir.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
44

55
import java.nio.file.Path;
6+
import java.util.Map;
7+
8+
import static org.cryptomator.cryptofs.health.api.CommonDetailKeys.DIR_ID;
9+
import static org.cryptomator.cryptofs.health.api.CommonDetailKeys.DIR_ID_FILE;
10+
import static org.cryptomator.cryptofs.health.api.CommonDetailKeys.ENCRYPTED_PATH;
611

712
/**
813
* Valid dir.c9r file, existing target dir
@@ -28,4 +33,11 @@ public Severity getSeverity() {
2833
public String toString() {
2934
return String.format("Good directory %s (%s) -> %s", dirIdFile, dirId, dir);
3035
}
36+
37+
@Override
38+
public Map<String, String> details() {
39+
return Map.of(DIR_ID, dirId, //
40+
DIR_ID_FILE, dirIdFile.toString(), //
41+
ENCRYPTED_PATH, dir.toString());
42+
}
3143
}

src/main/java/org/cryptomator/cryptofs/health/dirid/MissingDirectory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
44

55
import java.nio.file.Path;
6+
import java.util.Map;
7+
8+
import static org.cryptomator.cryptofs.health.api.CommonDetailKeys.DIR_ID;
9+
import static org.cryptomator.cryptofs.health.api.CommonDetailKeys.DIR_ID_FILE;
610

711
/**
812
* Valid dir.c9r file, nonexisting dir
913
*/
1014
public class MissingDirectory implements DiagnosticResult {
1115

16+
//TODO: maybe add not-existing dir path
1217
final String dirId;
1318
final Path file;
1419

@@ -27,5 +32,10 @@ public String toString() {
2732
return String.format("dir.c9r file (%s) points to non-existing directory.", file);
2833
}
2934

35+
@Override
36+
public Map<String, String> details() {
37+
return Map.of(DIR_ID, dirId, //
38+
DIR_ID_FILE, file.toString());
39+
}
3040
// fix: create dir?
3141
}

src/main/java/org/cryptomator/cryptofs/health/dirid/ObeseDirFile.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
55

66
import java.nio.file.Path;
7+
import java.util.Map;
8+
9+
import static org.cryptomator.cryptofs.health.api.CommonDetailKeys.DIR_ID_FILE;
710

811
/**
912
* The dir.c9r file's size is too large.
@@ -28,6 +31,11 @@ public String toString() {
2831
return String.format("Unexpected file size of %s: %d should be ≤ %d", dirFile, size, Constants.MAX_DIR_FILE_LENGTH);
2932
}
3033

34+
@Override
35+
public Map<String, String> details() {
36+
return Map.of(DIR_ID_FILE, dirFile.toString(), //
37+
"Size", Long.toString(size));
38+
}
3139
// potential fix: assign new dir id, move target dir
3240

3341
}

src/main/java/org/cryptomator/cryptofs/health/dirid/OrphanDir.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
44

55
import java.nio.file.Path;
6+
import java.util.Map;
7+
8+
import static org.cryptomator.cryptofs.health.api.CommonDetailKeys.ENCRYPTED_PATH;
69

710
/**
811
* An orphan directory is a detached node, not referenced by any dir.c9r file.
@@ -25,5 +28,10 @@ public String toString() {
2528
return String.format("Orphan directory: %s", dir);
2629
}
2730

31+
@Override
32+
public Map<String, String> details() {
33+
return Map.of(ENCRYPTED_PATH, dir.toString());
34+
}
35+
2836
// fix: create new dirId inside of L+F dir and rename existing dir accordingly.
2937
}

0 commit comments

Comments
 (0)