ppkarwasz commented on code in PR #458:
URL: https://github.com/apache/commons-codec/pull/458#discussion_r4622209396
##########
src/main/java/org/apache/commons/codec/digest/GitIdentifiers.java:
##########
@@ -219,7 +226,10 @@ private static FileMode get(final Path path) {
if (Files.isDirectory(path)) {
return DIRECTORY;
}
- if (Files.isExecutable(path)) {
+ // Windows reports every readable file as executable. Git records
the executable bit only where the file system
+ // provides POSIX permissions; elsewhere, for example with Git for
Windows and its default core.fileMode=false,
+ // regular files are stored as 100644.
+ if (Files.getFileAttributeView(path, PosixFileAttributeView.class)
!= null && Files.isExecutable(path)) {
Review Comment:
_Nit_: since we are retrieving the file attributes, we might as well use
them. We could for example:
- Retrieve an attribute view:
```java
BasicFileAttributeView view = Files.getFileAttributeView(path,
PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (view == null) {
view = Files.getFileAttributeView(path, BasicFileAttributeView.class,
LinkOption.NOFOLLOW_LINKS);
}
BasicFileAttributes attrs = view.readAttributes();
```
- Use `attrs.isSymbolicLink()`, `attrs.isDirectory()` and
```java
((PosixFileAttributes)
attrs).permissions().contains(PosixFilePermission.OWNER_EXECUTE);
```
to classify the file.
--
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]