ppkarwasz commented on code in PR #458:
URL: https://github.com/apache/commons-codec/pull/458#discussion_r4646887180
##########
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:
_Nit_: this logic repeats almost exactly the logic below, except the
`EXECUTABLE` result. Why don't we merge it with the logic below by using:
```java
return attributes instanceof PosixFileAttributes
&& ((PosixFileAttributes)
attributes).permissions().contains(PosixFilePermission.OWNER_EXECUTE)
? EXECUTABLE : REGULAR;
```
--
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]