summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index a4ee5c5..9308a17 100644
--- a/eval.c
+++ b/eval.c
@@ -277,8 +277,21 @@ bool eval_delete(const struct expr *expr, struct eval_state *state) {
}
int flag = 0;
- if (ftwbuf->typeflag == BFTW_DIR) {
- flag |= AT_REMOVEDIR;
+ if (ftwbuf->at_flags & AT_SYMLINK_NOFOLLOW) {
+ if (ftwbuf->typeflag == BFTW_DIR) {
+ flag |= AT_REMOVEDIR;
+ }
+ } else {
+ // We need to know the actual type of the path, not what it points to
+ struct bfs_stat sb;
+ if (bfs_stat(ftwbuf->at_fd, ftwbuf->at_path, ftwbuf->at_flags | AT_SYMLINK_NOFOLLOW, 0, &sb) == 0) {
+ if (S_ISDIR(sb.mode)) {
+ flag |= AT_REMOVEDIR;
+ }
+ } else {
+ eval_error(state);
+ return false;
+ }
}
if (unlinkat(ftwbuf->at_fd, ftwbuf->at_path, flag) != 0) {