This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-codec.git
commit 1660ecdce5a62e0940134ce9bb5ce7ab562fe849 Author: simpleqt <[email protected]> AuthorDate: Sat Nov 21 20:44:13 2026 +0800 GitIdentifiers: classify once from the file attributes Address the review nit on FileMode.get: read one BasicFileAttributeView (POSIX preferred, Basic fallback), classify symbolic link and directory once, and use an instanceof PosixFileAttributes check for the owner-execute bit. This removes the duplicated fallback classification. The executable bit is still only read where the file system exposes POSIX permissions; without a POSIX view the attributes are BasicFileAttributes and the file is REGULAR. --- .../java/org/apache/commons/codec/digest/GitIdentifiers.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/codec/digest/GitIdentifiers.java b/src/main/java/org/apache/commons/codec/digest/GitIdentifiers.java index 634bdca6..f323f75d 100644 --- a/src/main/java/org/apache/commons/codec/digest/GitIdentifiers.java +++ b/src/main/java/org/apache/commons/codec/digest/GitIdentifiers.java @@ -230,23 +230,19 @@ public class GitIdentifiers { // Git for Windows and its default core.fileMode=false, regular files are stored as 100644 even though Windows // reports every readable file as executable. BasicFileAttributeView view = Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); - final BasicFileAttributes attributes; if (view == null) { view = Files.getFileAttributeView(path, BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); - attributes = view.readAttributes(); - if (attributes.isSymbolicLink()) { - return SYMBOLIC_LINK; - } - return attributes.isDirectory() ? DIRECTORY : REGULAR; } - attributes = view.readAttributes(); + final BasicFileAttributes attributes = view.readAttributes(); if (attributes.isSymbolicLink()) { return SYMBOLIC_LINK; } if (attributes.isDirectory()) { return DIRECTORY; } - return ((PosixFileAttributes) attributes).permissions().contains(PosixFilePermission.OWNER_EXECUTE) ? EXECUTABLE : REGULAR; + final boolean executable = attributes instanceof PosixFileAttributes && + ((PosixFileAttributes) attributes).permissions().contains(PosixFilePermission.OWNER_EXECUTE); + return executable ? EXECUTABLE : REGULAR; } /**
