77import org .slf4j .Logger ;
88import org .slf4j .LoggerFactory ;
99
10- import javax .inject .Inject ;
11- import javax .inject .Singleton ;
1210import java .io .IOException ;
1311import java .nio .file .DirectoryIteratorException ;
1412import java .nio .file .DirectoryStream ;
1715import java .nio .file .Files ;
1816import java .nio .file .Path ;
1917
20- @ Singleton
21- public class FileSystemCapabilityChecker {
18+ public final class FileSystemCapabilityChecker {
2219
2320 private static final Logger LOG = LoggerFactory .getLogger (FileSystemCapabilityChecker .class );
2421
@@ -38,8 +35,8 @@ public enum Capability {
3835 WRITE_ACCESS ,
3936 }
4037
41- @ Inject
42- public FileSystemCapabilityChecker () {
38+ private FileSystemCapabilityChecker () {
39+
4340 }
4441
4542 /**
@@ -50,7 +47,7 @@ public FileSystemCapabilityChecker() {
5047 * @implNote Only short-running tests with constant time are performed
5148 * @since 1.9.2
5249 */
53- public void assertAllCapabilities (Path pathToVault ) throws MissingCapabilityException {
50+ public static void assertAllCapabilities (Path pathToVault ) throws MissingCapabilityException {
5451 assertReadAccess (pathToVault );
5552 assertWriteAccess (pathToVault );
5653 }
@@ -62,7 +59,7 @@ public void assertAllCapabilities(Path pathToVault) throws MissingCapabilityExce
6259 * @throws MissingCapabilityException if the check fails
6360 * @since 1.9.3
6461 */
65- public void assertReadAccess (Path pathToVault ) throws MissingCapabilityException {
62+ public static void assertReadAccess (Path pathToVault ) throws MissingCapabilityException {
6663 try (DirectoryStream <Path > ds = Files .newDirectoryStream (pathToVault )) {
6764 assert ds != null ;
6865 } catch (IOException e ) {
@@ -77,7 +74,7 @@ public void assertReadAccess(Path pathToVault) throws MissingCapabilityException
7774 * @throws MissingCapabilityException if the check fails
7875 * @since 1.9.3
7976 */
80- public void assertWriteAccess (Path pathToVault ) throws MissingCapabilityException {
77+ public static void assertWriteAccess (Path pathToVault ) throws MissingCapabilityException {
8178 Path checkDir = pathToVault .resolve ("c" );
8279 try {
8380 Files .createDirectories (checkDir );
@@ -90,7 +87,7 @@ public void assertWriteAccess(Path pathToVault) throws MissingCapabilityExceptio
9087 }
9188 }
9289
93- public int determineSupportedCleartextFileNameLength (Path pathToVault ) throws IOException {
90+ public static int determineSupportedCleartextFileNameLength (Path pathToVault ) throws IOException {
9491 int maxCiphertextLen = determineSupportedCiphertextFileNameLength (pathToVault );
9592 assert maxCiphertextLen >= Constants .MIN_CIPHER_NAME_LENGTH ;
9693 // math explained in https://github.com/cryptomator/cryptofs/issues/60#issuecomment-523238303;
@@ -105,22 +102,22 @@ public int determineSupportedCleartextFileNameLength(Path pathToVault) throws IO
105102 * @return Number of chars a .c9r file is allowed to have
106103 * @throws IOException If unable to perform this check
107104 */
108- public int determineSupportedCiphertextFileNameLength (Path pathToVault ) throws IOException {
105+ public static int determineSupportedCiphertextFileNameLength (Path pathToVault ) throws IOException {
109106 int subPathLength = Constants .MAX_ADDITIONAL_PATH_LENGTH - 2 ; // subtract "c/"
110107 return determineSupportedCiphertextFileNameLength (pathToVault .resolve ("c" ), subPathLength , Constants .MIN_CIPHER_NAME_LENGTH , Constants .MAX_CIPHER_NAME_LENGTH );
111108 }
112109
113110 /**
114111 * Determines the number of chars a filename is allowed to have inside of subdirectories of <code>dir</code> by running an experiment.
115112 *
116- * @param dir Path to a directory where to conduct the experiment (e.g. <code>/path/to/vault/c</code>)
117- * @param subPathLength Defines the combined number of chars of the subdirectories inside <code>dir</code>, including slashes but excluding the leading slash. Must be a minimum of 6
113+ * @param dir Path to a directory where to conduct the experiment (e.g. <code>/path/to/vault/c</code>)
114+ * @param subPathLength Defines the combined number of chars of the subdirectories inside <code>dir</code>, including slashes but excluding the leading slash. Must be a minimum of 6
118115 * @param minFileNameLength The minimum filename length to check
119116 * @param maxFileNameLength The maximum filename length to check
120117 * @return The supported filename length inside a subdirectory of <code>dir</code> with <code>subPathLength</code> chars
121118 * @throws IOException If unable to perform this check
122119 */
123- public int determineSupportedCiphertextFileNameLength (Path dir , int subPathLength , int minFileNameLength , int maxFileNameLength ) throws IOException {
120+ public static int determineSupportedCiphertextFileNameLength (Path dir , int subPathLength , int minFileNameLength , int maxFileNameLength ) throws IOException {
124121 Preconditions .checkArgument (subPathLength >= 6 , "subPathLength must be larger than charcount(a/nnn/)" );
125122 Preconditions .checkArgument (minFileNameLength > 0 );
126123 Preconditions .checkArgument (maxFileNameLength <= 999 );
@@ -141,7 +138,7 @@ public int determineSupportedCiphertextFileNameLength(Path dir, int subPathLengt
141138 }
142139 }
143140
144- private int determineSupportedCiphertextFileNameLength (Path p , int lowerBoundIncl , int upperBoundExcl ) {
141+ private static int determineSupportedCiphertextFileNameLength (Path p , int lowerBoundIncl , int upperBoundExcl ) {
145142 assert lowerBoundIncl < upperBoundExcl ;
146143 int mid = (lowerBoundIncl + upperBoundExcl ) / 2 ;
147144 assert mid < upperBoundExcl ;
@@ -156,7 +153,7 @@ private int determineSupportedCiphertextFileNameLength(Path p, int lowerBoundInc
156153 }
157154 }
158155
159- private boolean canHandleFileNameLength (Path parent , int nameLength ) {
156+ private static boolean canHandleFileNameLength (Path parent , int nameLength ) {
160157 Path checkDir = parent .resolve (String .format ("%03d" , nameLength ));
161158 Path checkFile = checkDir .resolve (Strings .repeat ("a" , nameLength ));
162159 try {
@@ -175,7 +172,7 @@ private boolean canHandleFileNameLength(Path parent, int nameLength) {
175172 }
176173 }
177174
178- private boolean canListDir (Path dir ) {
175+ private static boolean canListDir (Path dir ) {
179176 try (DirectoryStream <Path > ds = Files .newDirectoryStream (dir )) {
180177 ds .iterator ().hasNext (); // throws DirectoryIteratorException on Windows if child path too long
181178 return true ;
@@ -184,15 +181,15 @@ private boolean canListDir(Path dir) {
184181 }
185182 }
186183
187- private void deleteSilently (Path path ) {
184+ private static void deleteSilently (Path path ) {
188185 try {
189186 Files .delete (path );
190187 } catch (IOException e ) {
191188 LOG .trace ("Failed to delete " + path , e );
192189 }
193190 }
194191
195- private void deleteRecursivelySilently (Path dir ) {
192+ private static void deleteRecursivelySilently (Path dir ) {
196193 try {
197194 if (Files .exists (dir )) {
198195 MoreFiles .deleteRecursively (dir , RecursiveDeleteOption .ALLOW_INSECURE );
0 commit comments