|
| 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 | +--- a/src/wutil/dir_iter.rs |
| 10 | ++++ b/src/wutil/dir_iter.rs |
| 11 | +@@ -26,7 +26,33 @@ pub enum DirEntryType { |
| 12 | + whiteout, // whiteout (from BSD) |
| 13 | + } |
| 14 | + |
| 15 | +-/// An entry returned by DirIter. |
| 16 | ++/// An entry returned by DirIter on 32-bit Android. |
| 17 | ++#[cfg(all(target_os = "android", target_pointer_width = "32"))] |
| 18 | ++#[derive(Clone)] |
| 19 | ++pub struct DirEntry { |
| 20 | ++ /// File name of this entry. |
| 21 | ++ pub name: WString, |
| 22 | ++ |
| 23 | ++ /// inode of this entry. |
| 24 | ++ pub inode: u64, |
| 25 | ++ |
| 26 | ++ // Device, inode pair for this entry, or none if not yet computed. |
| 27 | ++ dev_inode: Cell<Option<DevInode>>, |
| 28 | ++ |
| 29 | ++ // The type of the entry. This is initially none; it may be populated eagerly via readdir() |
| 30 | ++ // on some filesystems, or later via stat(). If stat() fails, the error is silently ignored |
| 31 | ++ // and the type is left as none(). Note this is an unavoidable race. |
| 32 | ++ typ: Cell<Option<DirEntryType>>, |
| 33 | ++ |
| 34 | ++ // whether this could be a link, false if we know definitively it isn't. |
| 35 | ++ possible_link: Option<bool>, |
| 36 | ++ |
| 37 | ++ // fd of the DIR*, used for fstatat(). |
| 38 | ++ dirfd: Rc<DirFd>, |
| 39 | ++} |
| 40 | ++ |
| 41 | ++/// An entry returned by DirIter on everything except 32-bit Android. |
| 42 | ++#[cfg(not(all(target_os = "android", target_pointer_width = "32")))] |
| 43 | + #[derive(Clone)] |
| 44 | + pub struct DirEntry { |
| 45 | + /// File name of this entry. |
| 46 | +@@ -148,6 +153,32 @@ fn dirent_type_to_entry_type(dt: u8) -> Option<DirEntryType> { |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | ++#[cfg(all(target_os = "android", target_pointer_width = "32"))] |
| 51 | ++fn stat_mode_to_entry_type(m: u32) -> Option<DirEntryType> { |
| 52 | ++ const S_IFIFO_32_bit_android: u32 = 0o1_0000; |
| 53 | ++ const S_IFCHR_32_bit_android: u32 = 0o2_0000; |
| 54 | ++ const S_IFBLK_32_bit_android: u32 = 0o6_0000; |
| 55 | ++ const S_IFDIR_32_bit_android: u32 = 0o4_0000; |
| 56 | ++ const S_IFREG_32_bit_android: u32 = 0o10_0000; |
| 57 | ++ const S_IFLNK_32_bit_android: u32 = 0o12_0000; |
| 58 | ++ const S_IFSOCK_32_bit_android: u32 = 0o14_0000; |
| 59 | ++ const S_IFMT_32_bit_android: u32 = 0o17_0000; |
| 60 | ++ match m & S_IFMT_32_bit_android { |
| 61 | ++ S_IFIFO_32_bit_android => Some(DirEntryType::fifo), |
| 62 | ++ S_IFCHR_32_bit_android => Some(DirEntryType::chr), |
| 63 | ++ S_IFDIR_32_bit_android => Some(DirEntryType::dir), |
| 64 | ++ S_IFBLK_32_bit_android => Some(DirEntryType::blk), |
| 65 | ++ S_IFREG_32_bit_android => Some(DirEntryType::reg), |
| 66 | ++ S_IFLNK_32_bit_android => Some(DirEntryType::lnk), |
| 67 | ++ S_IFSOCK_32_bit_android => Some(DirEntryType::sock), |
| 68 | ++ _ => { |
| 69 | ++ // todo!("whiteout") |
| 70 | ++ None |
| 71 | ++ } |
| 72 | ++ } |
| 73 | ++} |
| 74 | ++ |
| 75 | ++#[cfg(not(all(target_os = "android", target_pointer_width = "32")))] |
| 76 | + fn stat_mode_to_entry_type(m: libc::mode_t) -> Option<DirEntryType> { |
| 77 | + match m & S_IFMT { |
| 78 | + S_IFIFO => Some(DirEntryType::fifo), |
| 79 | +diff --git a/src/wildcard.rs b/src/wildcard.rs |
| 80 | +index a84754a..f9454e9 100644 |
| 81 | +--- a/src/wildcard.rs |
| 82 | ++++ b/src/wildcard.rs |
| 83 | +@@ -885,7 +885,12 @@ mod expander { |
| 84 | + // Ensure we don't fall into a symlink loop. |
| 85 | + // Ideally we would compare both devices and inodes, but devices require a stat call, so we |
| 86 | + // use inodes exclusively. |
| 87 | +- let mut visited_inodes: HashSet<libc::ino_t> = HashSet::new(); |
| 88 | ++ |
| 89 | ++ #[cfg(all(target_os = "android", target_pointer_width = "32"))] |
| 90 | ++ let mut visited_inodes: HashSet<u64> = HashSet::new(); |
| 91 | ++ |
| 92 | ++ #[cfg(not(all(target_os = "android", target_pointer_width = "32")))] |
| 93 | ++ let mut visited_inodes: HashSet<libc::ino_t> = HashSet::new(); |
| 94 | + |
| 95 | + loop { |
| 96 | + let mut unique_entry = WString::new(); |
0 commit comments