simpleqt commented on code in PR #458:
URL: https://github.com/apache/commons-codec/pull/458#discussion_r4652535123


##########
src/main/java/org/apache/commons/codec/digest/GitIdentifiers.java:
##########
@@ -211,18 +223,30 @@ public enum FileMode {
          */
         SYMBOLIC_LINK(new byte[] { '1', '2', '0', '0', '0', '0' });
 
-        private static FileMode get(final Path path) {
-            // Symbolic links first
-            if (Files.isSymbolicLink(path)) {
+        private static FileMode get(final Path path) throws IOException {
+            // Read one attribute set, preferring POSIX where the file system 
provides it. The basic view always exists and
+            // classifies links and directories; only POSIX permissions carry 
the owner-execute bit that Git records. Git
+            // records the executable bit only where the file system exposes 
POSIX permissions; elsewhere, for example with
+            // 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;

Review Comment:
   Good idea — done on `a2ae570`. `get` now reads one view (POSIX when the file 
system provides it, Basic otherwise), classifies the symbolic link and 
directory once, and only then applies the `instanceof PosixFileAttributes` 
owner-execute check. The duplicated fallback branch is gone, and the executable 
bit is still read only where POSIX permissions exist.
   
   Verification on `a2ae570`, local only:
   
   - focused non-symlink `GitIdentifiersTest` methods 
(`testTreeIdPathRecordsFilesWithoutPosixExecutableBitAsRegular`, 
`testBlobIdPath`, `testTreeIdPath`): 5 tests, 0 failures, 0 errors
   - full `mvn test`: 19976 tests, 0 failures, 3 errors, 20 skipped; the three 
errors are the pre-existing Windows symlink-privilege failures in 
`testBlobIdSymlink` and `testTreeIdPathUnix` (creating symlinks needs a 
privilege this host does not have), not related to this change
   - `mvn verify` with those two symlink-only methods excluded and jacoco 
skipped: 19975 tests, 0 failures, 0 errors, 20 skipped; RAT, Checkstyle, PMD, 
SpotBugs (0 BugInstances) and Javadoc all pass. Jacoco was skipped there 
because excluding the symlink tests lowers the aggregate coverage below the 
project thresholds, and CI runs the complete suite on Linux.
   - no CI run yet: the new head is subject to the fork approval gate, so this 
is local evidence only
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to