Skip to content

Commit a7d83c7

Browse files
committed
Simplified the approach by making a wrapper and did spelling fixes
1 parent 2fa0606 commit a7d83c7

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

src/uucore/src/lib/features/safe_traversal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ impl From<SafeTraversalError> for io::Error {
8080
}
8181

8282
/// Clear errno and return any error that was set after an operation
83-
/// This is used because the nix library does not propogate folder reading errors correctly
83+
/// This is used because the nix library does not propagate folder reading errors correctly
8484
pub fn take_errno() -> Option<io::Error> {
8585
let errno = Errno::last();
8686
Errno::clear();
8787
(errno != Errno::from_raw(0)).then(|| io::Error::from_raw_os_error(errno as i32))
8888
}
8989

90-
/// Clear errno before an operation, required to read error messages not propogated by nix from reading folders
90+
/// Clear errno before an operation, required to read error messages not propagated by nix from reading folders
9191
pub fn clear_errno() {
9292
Errno::clear();
9393
}

util/build-gnu.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# spell-checker:ignore (paths) abmon deref discrim eacces getlimits getopt ginstall inacc infloop inotify reflink ; (misc) INT_OFLOW OFLOW
66
# spell-checker:ignore baddecode submodules xstrtol distros ; (vars/env) SRCDIR vdir rcexp xpart dired OSTYPE ; (utils) gnproc greadlink gsed multihardlink texinfo CARGOFLAGS
77
# spell-checker:ignore openat TOCTOU CFLAGS
8-
# spell-checker:ignore hfsplus casefold chattr
8+
# spell-checker:ignore hfsplus casefold chattr dirp
99

1010
set -e
1111

@@ -362,17 +362,13 @@ test \$n_stat1 -ge \$n_stat2 \\' tests/ls/stat-free-color.sh
362362
# * the test says "maybe we should not fail when no context available"
363363
"${SED}" -i -e "s|returns_ 1||g" tests/cp/no-ctx.sh
364364

365-
# The rm-readdir-fail.sh test hooks readdir() but uutils rm uses nix library which calls readdir64_r().
366-
# readdir64_r has a different signature: int readdir64_r(DIR*, struct dirent64*, struct dirent64**)
367-
"${SED}" -i \
368-
-e 's/struct dirent \*readdir (DIR \*dirp)/int readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)/' \
369-
-e 's/struct dirent \*(\*real_readdir)(DIR \*dirp)/int (*real_func)(DIR *, struct dirent64 *, struct dirent64 **)/' \
370-
-e 's/real_readdir/real_func/g' \
371-
-e 's/dlsym (RTLD_NEXT, "readdir")/dlsym(RTLD_NEXT, "readdir64_r")/' \
372-
-e 's/struct dirent\* d;/int ret;/' \
373-
-e 's/! (d = real_func (dirp))/(ret = real_func(dirp, entry, result)) != 0 || !*result/' \
374-
-e 's/d->d_name/entry->d_name/g' \
375-
-e 's/d->d_namlen/entry->d_namlen/g' \
376-
-e 's/return d;/return 0;/' \
377-
-e 's/return NULL;/*result = NULL; return EIO;/' \
378-
tests/rm/rm-readdir-fail.sh
365+
# uutils rm uses nix which calls readdir64_r, so add a wrapper that delegates to the readdir hook
366+
"${SED}" -i '/^struct dirent \*readdir/i\
367+
int readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result) {\
368+
struct dirent *d = readdir(dirp);\
369+
if (!d) { *result = NULL; return errno ? EIO : 0; }\
370+
memcpy(entry, d, sizeof(*d));\
371+
*result = entry;\
372+
return 0;\
373+
}
374+
' tests/rm/rm-readdir-fail.sh

0 commit comments

Comments
 (0)