hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
705 stars 179 forks source link

getFileAttributes method of FileIdBothDirectoryInformation results value as 48 for directory. #794

Closed kvaishnavi97 closed 11 months ago

kvaishnavi97 commented 11 months ago

Hello,

I am using SMBJ 0.11.5 version. I have implemented a file browser using this api. With the help of list method of diskshare, I am listing out files/folders from a specific path as below.

for (FileIdBothDirectoryInformation f : diskShare.list(pathname)) { SMBFile SMBFile=new SMBFile(String.format(format_pattern, normalizedPathName, file.getFileName()), FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue() == file.getFileAttributes()); }

Here, I am determining FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue() == file.getFileAttributes() whether returned object is a file or folder. By default, folder/directory FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue() value is 16. This works fine with some folders. But getFileAttributes method returning value for below folders as 48 which is wrong (Attached screenshot).

Thanks.`

listingFolder

kvaishnavi97 commented 11 months ago

Here, MODAL,VIBRATION, MECHANICAL are folders but they do not come as directories because the getFileAttribute method does not give a value 16.

hierynomus commented 11 months ago

getFileAttributes() delivers a long value which you should bitwise AND, instead of checking equality.

So this would be the right check FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue() & file.getFileAttributes() > 0

Or you could use the EnumWithValue.EnumUtils.isSet(file.getAttributes(), FileAttributes.FILE_ATTRIBUTE_DIRECTORY) helper method.

kvaishnavi97 commented 11 months ago

getFileAttributes() delivers a long value which you should bitwise AND, instead of checking equality.

So this would be the right check FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue() & file.getFileAttributes() > 0

Or you could use the EnumWithValue.EnumUtils.isSet(file.getAttributes(), FileAttributes.FILE_ATTRIBUTE_DIRECTORY) helper method.

Yeah, I got it that later. Anyway, thank you for quick reply.