aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-07-29 20:53:21 +0800
committerPo Lu2023-07-29 20:53:21 +0800
commit9c5e9bb9be64bedb9aac8b12b4f0c717bcaa4da5 (patch)
treec921031eafef5097fbb42c0b8250badb2742975f /java
parent11b2399212f86a6c5f481063688837d91e876b41 (diff)
downloademacs-9c5e9bb9be64bedb9aac8b12b4f0c717bcaa4da5.tar.gz
emacs-9c5e9bb9be64bedb9aac8b12b4f0c717bcaa4da5.zip
Correct directory permissions reported for VFS files
* java/org/gnu/emacs/EmacsSafThread.java (statDocument1): * src/androidvfs.c (android_afs_stat, android_content_stat) (android_saf_root_stat): Report search permissions for files.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsSafThread.java59
1 files changed, 32 insertions, 27 deletions
diff --git a/java/org/gnu/emacs/EmacsSafThread.java b/java/org/gnu/emacs/EmacsSafThread.java
index cb69df01bfb..b0d014ffe94 100644
--- a/java/org/gnu/emacs/EmacsSafThread.java
+++ b/java/org/gnu/emacs/EmacsSafThread.java
@@ -97,6 +97,7 @@ public final class EmacsSafThread extends HandlerThread
97 /* File access mode constants. See `man 7 inode'. */ 97 /* File access mode constants. See `man 7 inode'. */
98 public static final int S_IRUSR = 0000400; 98 public static final int S_IRUSR = 0000400;
99 public static final int S_IWUSR = 0000200; 99 public static final int S_IWUSR = 0000200;
100 public static final int S_IXUSR = 0000100;
100 public static final int S_IFCHR = 0020000; 101 public static final int S_IFCHR = 0020000;
101 public static final int S_IFDIR = 0040000; 102 public static final int S_IFDIR = 0040000;
102 public static final int S_IFREG = 0100000; 103 public static final int S_IFREG = 0100000;
@@ -1010,7 +1011,8 @@ public final class EmacsSafThread extends HandlerThread
1010 Uri uriObject; 1011 Uri uriObject;
1011 String[] projection; 1012 String[] projection;
1012 long[] stat; 1013 long[] stat;
1013 int index; 1014 int flagsIndex, columnIndex, typeIndex;
1015 int sizeIndex, mtimeIndex, flags;
1014 long tem; 1016 long tem;
1015 String tem1; 1017 String tem1;
1016 Cursor cursor; 1018 Cursor cursor;
@@ -1041,7 +1043,16 @@ public final class EmacsSafThread extends HandlerThread
1041 if (cursor == null) 1043 if (cursor == null)
1042 return null; 1044 return null;
1043 1045
1044 if (!cursor.moveToFirst ()) 1046 /* Obtain the indices for columns wanted from this cursor. */
1047 flagsIndex = cursor.getColumnIndex (Document.COLUMN_FLAGS);
1048 sizeIndex = cursor.getColumnIndex (Document.COLUMN_SIZE);
1049 typeIndex = cursor.getColumnIndex (Document.COLUMN_MIME_TYPE);
1050 mtimeIndex = cursor.getColumnIndex (Document.COLUMN_LAST_MODIFIED);
1051
1052 if (!cursor.moveToFirst ()
1053 /* COLUMN_LAST_MODIFIED is allowed to be absent in a
1054 conforming documents provider. */
1055 || flagsIndex < 0 || sizeIndex < 0 || typeIndex < 0)
1045 { 1056 {
1046 cursor.close (); 1057 cursor.close ();
1047 return null; 1058 return null;
@@ -1052,34 +1063,22 @@ public final class EmacsSafThread extends HandlerThread
1052 1063
1053 try 1064 try
1054 { 1065 {
1055 index = cursor.getColumnIndex (Document.COLUMN_FLAGS); 1066 flags = cursor.getInt (flagsIndex);
1056 if (index < 0)
1057 return null;
1058
1059 tem = cursor.getInt (index);
1060 1067
1061 stat[0] |= S_IRUSR; 1068 stat[0] |= S_IRUSR;
1062 if ((tem & Document.FLAG_SUPPORTS_WRITE) != 0) 1069 if ((flags & Document.FLAG_SUPPORTS_WRITE) != 0)
1063 stat[0] |= S_IWUSR; 1070 stat[0] |= S_IWUSR;
1064 1071
1065 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N 1072 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
1066 && (tem & Document.FLAG_VIRTUAL_DOCUMENT) != 0) 1073 && (flags & Document.FLAG_VIRTUAL_DOCUMENT) != 0)
1067 stat[0] |= S_IFCHR; 1074 stat[0] |= S_IFCHR;
1068 1075
1069 index = cursor.getColumnIndex (Document.COLUMN_SIZE); 1076 if (cursor.isNull (sizeIndex))
1070 if (index < 0)
1071 return null;
1072
1073 if (cursor.isNull (index))
1074 stat[1] = -1; /* The size is unknown. */ 1077 stat[1] = -1; /* The size is unknown. */
1075 else 1078 else
1076 stat[1] = cursor.getLong (index); 1079 stat[1] = cursor.getLong (sizeIndex);
1077 1080
1078 index = cursor.getColumnIndex (Document.COLUMN_MIME_TYPE); 1081 tem1 = cursor.getString (typeIndex);
1079 if (index < 0)
1080 return null;
1081
1082 tem1 = cursor.getString (index);
1083 1082
1084 /* Check if this is a directory file. */ 1083 /* Check if this is a directory file. */
1085 if (tem1.equals (Document.MIME_TYPE_DIR) 1084 if (tem1.equals (Document.MIME_TYPE_DIR)
@@ -1087,9 +1086,17 @@ public final class EmacsSafThread extends HandlerThread
1087 time, but Android doesn't forbid document providers 1086 time, but Android doesn't forbid document providers
1088 from returning this information. */ 1087 from returning this information. */
1089 && (stat[0] & S_IFCHR) == 0) 1088 && (stat[0] & S_IFCHR) == 0)
1090 /* Since FLAG_SUPPORTS_WRITE doesn't apply to directories, 1089 {
1091 just assume they're writable. */ 1090 /* Since FLAG_SUPPORTS_WRITE doesn't apply to directories,
1092 stat[0] |= S_IFDIR | S_IWUSR; 1091 just assume they're writable. */
1092 stat[0] |= S_IFDIR | S_IWUSR | S_IXUSR;
1093
1094 /* Directory files cannot be modified if
1095 FLAG_DIR_SUPPORTS_CREATE is not set. */
1096
1097 if ((flags & Document.FLAG_DIR_SUPPORTS_CREATE) == 0)
1098 stat[0] &= ~S_IWUSR;
1099 }
1093 1100
1094 /* If this file is neither a character special nor a 1101 /* If this file is neither a character special nor a
1095 directory, indicate that it's a regular file. */ 1102 directory, indicate that it's a regular file. */
@@ -1097,12 +1104,10 @@ public final class EmacsSafThread extends HandlerThread
1097 if ((stat[0] & (S_IFDIR | S_IFCHR)) == 0) 1104 if ((stat[0] & (S_IFDIR | S_IFCHR)) == 0)
1098 stat[0] |= S_IFREG; 1105 stat[0] |= S_IFREG;
1099 1106
1100 index = cursor.getColumnIndex (Document.COLUMN_LAST_MODIFIED); 1107 if (mtimeIndex >= 0 && !cursor.isNull (mtimeIndex))
1101
1102 if (index >= 0 && !cursor.isNull (index))
1103 { 1108 {
1104 /* Content providers are allowed to not provide mtime. */ 1109 /* Content providers are allowed to not provide mtime. */
1105 tem = cursor.getLong (index); 1110 tem = cursor.getLong (mtimeIndex);
1106 stat[2] = tem; 1111 stat[2] = tem;
1107 } 1112 }
1108 } 1113 }