Skip to content

Commit

Permalink
Implements methods to check whether a file path is hidden or is a met…
Browse files Browse the repository at this point in the history
…adata file

Fixes: SIRI-1028
  • Loading branch information
scireum-mbo committed Dec 10, 2024
1 parent cff6289 commit f379ec4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/sirius/kernel/commons/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,34 @@ public static String getFilenameWithoutExtension(@Nullable String path) {
return Strings.splitAtLast(getFilenameAndExtension(path), ".").getFirst();
}

/**
* Determines if the given path is hidden.
* <p>
* A path is considered hidden if it starts with a dot.
*
* @param path the path to check
* @return <tt>true</tt> if the path is hidden, <tt>false</tt> otherwise
*/
public static boolean isHidden(@Nullable String path) {
return path != null && path.startsWith(".");
}

/**
* Determines if the given path is a metadata file.
* <p>
* A metadata file is a file which is not part of the actual content but rather contains metadata or is used by
* the operating system or other tools.
*
* @param path the path to check
* @return <tt>true</tt> if the path is a metadata file that is listed in the METADATA_FILES list, <tt>false</tt> otherwise
*/
public static boolean isMetadata(@Nullable String path) {
if (Strings.isEmpty(path)) {
return false;
}
return METADATA_FILES.stream().anyMatch(path::contains);
}

/**
* If the given file is not null and exists, tries to delete that file and logs when a file cannot be deleted. T
* his is useful for error reporting and to diagnose why a file cannot be deleted.
Expand Down

0 comments on commit f379ec4

Please sign in to comment.