fix(all/documentsprovider): correct S_IFLNK constant and symlink detection mask

S_IFLNK was defined as 0x8000, which is actually S_IFREG (regular file),
not a symlink. The correct POSIX value is 0120000 (octal) = 0xA000 (hex).

Additionally, the symlink check used `st_mode & S_IFLNK` which is not the
correct POSIX approach for file type testing. The proper method is to mask
with S_IFMT (0170000) first: `(st_mode & S_IFMT) == S_IFLNK`.
This commit is contained in:
PlayDay 2026-03-16 11:14:14 +01:00
parent c35b8b8e96
commit c6c91eef51

View file

@ -31,7 +31,10 @@ public class InternalDataDocumentsProvider extends DocumentsProvider {
private static final String[] directoryColumns =
{"document_id", "mime_type", "_display_name", "last_modified", "flags",
"_size", "full_path", "lstat_info"};
private static final int S_IFLNK = 0x8000;
@SuppressWarnings("OctalInteger")
private static final int S_IFMT = 0170000;
@SuppressWarnings("OctalInteger")
private static final int S_IFLNK = 0120000;
private String packageName;
private File dataDirectory;
@ -47,7 +50,7 @@ public class InternalDataDocumentsProvider extends DocumentsProvider {
if (root.isDirectory()) {
try {
// Only delete recursively if the directory is not a symlink
if ((Os.lstat(root.getPath()).st_mode & S_IFLNK) != S_IFLNK) {
if ((Os.lstat(root.getPath()).st_mode & S_IFMT) != S_IFLNK) {
File[] files = root.listFiles();
if (files != null) {
for (File file : files) {
@ -324,7 +327,7 @@ public class InternalDataDocumentsProvider extends DocumentsProvider {
sb.append(";");
sb.append(lstat.st_gid);
// Append symlink target if it is a symlink
if ((lstat.st_mode & S_IFLNK) == S_IFLNK) {
if ((lstat.st_mode & S_IFMT) == S_IFLNK) {
sb.append(";");
sb.append(Os.readlink(path));
}