|
| 1 | +This fixes https://github.com/termux/termux-packages/issues/24741 |
| 2 | + |
| 3 | +To maintain: |
| 4 | +keep the conditionally-compiled implementations of DirEntry and stat_mode_to_entry_type() |
| 5 | +synchronized with their upstream counterparts that are developed for non-32-bit-Android platforms. |
| 6 | +keep the S_IFIFO, etc. definitions synchronized with this file: |
| 7 | +https://github.com/rust-lang/libc/blob/c1d2b8e055e29b239a308f10b38a6b6138711612/src/unix/linux_like/mod.rs#L563 |
| 8 | + |
| 9 | +This patch was not created by an automatic tool - unfortunately, it was created by manually typing the |
| 10 | +syntax of the unified-diff format, in order to artifically extend the context of each hunk an |
| 11 | +abnormal number of lines after the changed lines (but not before the changed lines). |
| 12 | +The reason for this is so that if anything in the normal implementation of the blocks changes, |
| 13 | +this patch is explicitly forced to fail so that the maintainer is reminded to make an equivalent change |
| 14 | +in the implementation of the block for 32-bit Android. If another maintianer of this patch is not |
| 15 | +familiar with manually writing the unified-diff format, this documentation might be helpful to |
| 16 | +preserve this failsafe in future revisions of this patch: |
| 17 | +https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html |
| 18 | + |
| 19 | +--- a/src/wildcard.rs |
| 20 | ++++ b/src/wildcard.rs |
| 21 | +@@ -885,6 +885,9 @@ mod expander { |
| 22 | + // Ensure we don't fall into a symlink loop. |
| 23 | + // Ideally we would compare both devices and inodes, but devices require a stat call, so we |
| 24 | + // use inodes exclusively. |
| 25 | ++ #[cfg(all(target_os = "android", target_pointer_width = "32"))] |
| 26 | ++ let mut visited_inodes: HashSet<u64> = HashSet::new(); |
| 27 | ++ #[cfg(not(all(target_os = "android", target_pointer_width = "32")))] |
| 28 | + let mut visited_inodes: HashSet<libc::ino_t> = HashSet::new(); |
| 29 | + |
| 30 | + loop { |
| 31 | +--- a/src/wutil/dir_iter.rs |
| 32 | ++++ b/src/wutil/dir_iter.rs |
| 33 | +@@ -26,26 +26,52 @@ pub enum DirEntryType { |
| 34 | + whiteout, // whiteout (from BSD) |
| 35 | + } |
| 36 | + |
| 37 | +-/// An entry returned by DirIter. |
| 38 | ++/// An entry returned by DirIter on 32-bit Android. |
| 39 | ++#[cfg(all(target_os = "android", target_pointer_width = "32"))] |
| 40 | ++#[derive(Clone)] |
| 41 | ++pub struct DirEntry { |
| 42 | ++ /// File name of this entry. |
| 43 | ++ pub name: WString, |
| 44 | ++ |
| 45 | ++ /// inode of this entry. |
| 46 | ++ pub inode: u64, |
| 47 | ++ |
| 48 | ++ // Device, inode pair for this entry, or none if not yet computed. |
| 49 | ++ dev_inode: Cell<Option<DevInode>>, |
| 50 | ++ |
| 51 | ++ // The type of the entry. This is initially none; it may be populated eagerly via readdir() |
| 52 | ++ // on some filesystems, or later via stat(). If stat() fails, the error is silently ignored |
| 53 | ++ // and the type is left as none(). Note this is an unavoidable race. |
| 54 | ++ typ: Cell<Option<DirEntryType>>, |
| 55 | ++ |
| 56 | ++ // whether this could be a link, false if we know definitively it isn't. |
| 57 | ++ possible_link: Option<bool>, |
| 58 | ++ |
| 59 | ++ // fd of the DIR*, used for fstatat(). |
| 60 | ++ dirfd: Rc<DirFd>, |
| 61 | ++} |
| 62 | ++ |
| 63 | ++/// An entry returned by DirIter on everything except 32-bit Android. |
| 64 | ++#[cfg(not(all(target_os = "android", target_pointer_width = "32")))] |
| 65 | + #[derive(Clone)] |
| 66 | + pub struct DirEntry { |
| 67 | + /// File name of this entry. |
| 68 | + pub name: WString, |
| 69 | + |
| 70 | + /// inode of this entry. |
| 71 | + pub inode: libc::ino_t, |
| 72 | + |
| 73 | + // Device, inode pair for this entry, or none if not yet computed. |
| 74 | + dev_inode: Cell<Option<DevInode>>, |
| 75 | + |
| 76 | + // The type of the entry. This is initially none; it may be populated eagerly via readdir() |
| 77 | + // on some filesystems, or later via stat(). If stat() fails, the error is silently ignored |
| 78 | + // and the type is left as none(). Note this is an unavoidable race. |
| 79 | + typ: Cell<Option<DirEntryType>>, |
| 80 | + |
| 81 | + // whether this could be a link, false if we know definitively it isn't. |
| 82 | + possible_link: Option<bool>, |
| 83 | + |
| 84 | + // fd of the DIR*, used for fstatat(). |
| 85 | + dirfd: Rc<DirFd>, |
| 86 | + } |
| 87 | +@@ -148,18 +174,44 @@ fn dirent_type_to_entry_type(dt: u8) -> Option<DirEntryType> { |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | ++#[cfg(all(target_os = "android", target_pointer_width = "32"))] |
| 92 | ++fn stat_mode_to_entry_type(m: u32) -> Option<DirEntryType> { |
| 93 | ++ const S_IFIFO_32_bit_android: u32 = 0o1_0000; |
| 94 | ++ const S_IFCHR_32_bit_android: u32 = 0o2_0000; |
| 95 | ++ const S_IFBLK_32_bit_android: u32 = 0o6_0000; |
| 96 | ++ const S_IFDIR_32_bit_android: u32 = 0o4_0000; |
| 97 | ++ const S_IFREG_32_bit_android: u32 = 0o10_0000; |
| 98 | ++ const S_IFLNK_32_bit_android: u32 = 0o12_0000; |
| 99 | ++ const S_IFSOCK_32_bit_android: u32 = 0o14_0000; |
| 100 | ++ const S_IFMT_32_bit_android: u32 = 0o17_0000; |
| 101 | ++ match m & S_IFMT_32_bit_android { |
| 102 | ++ S_IFIFO_32_bit_android => Some(DirEntryType::fifo), |
| 103 | ++ S_IFCHR_32_bit_android => Some(DirEntryType::chr), |
| 104 | ++ S_IFDIR_32_bit_android => Some(DirEntryType::dir), |
| 105 | ++ S_IFBLK_32_bit_android => Some(DirEntryType::blk), |
| 106 | ++ S_IFREG_32_bit_android => Some(DirEntryType::reg), |
| 107 | ++ S_IFLNK_32_bit_android => Some(DirEntryType::lnk), |
| 108 | ++ S_IFSOCK_32_bit_android => Some(DirEntryType::sock), |
| 109 | ++ _ => { |
| 110 | ++ // todo!("whiteout") |
| 111 | ++ None |
| 112 | ++ } |
| 113 | ++ } |
| 114 | ++} |
| 115 | ++ |
| 116 | ++#[cfg(not(all(target_os = "android", target_pointer_width = "32")))] |
| 117 | + fn stat_mode_to_entry_type(m: libc::mode_t) -> Option<DirEntryType> { |
| 118 | + match m & S_IFMT { |
| 119 | + S_IFIFO => Some(DirEntryType::fifo), |
| 120 | + S_IFCHR => Some(DirEntryType::chr), |
| 121 | + S_IFDIR => Some(DirEntryType::dir), |
| 122 | + S_IFBLK => Some(DirEntryType::blk), |
| 123 | + S_IFREG => Some(DirEntryType::reg), |
| 124 | + S_IFLNK => Some(DirEntryType::lnk), |
| 125 | + S_IFSOCK => Some(DirEntryType::sock), |
| 126 | + _ => { |
| 127 | + // todo!("whiteout") |
| 128 | + None |
| 129 | + } |
| 130 | + } |
| 131 | + } |
0 commit comments