comparison toys/posix/rm.c @ 746:5caa4035c1c8

essat's flag not to follow symlinks isn't in the system call, and if libc is supposed to implement this as a wrapper uClibc gets it wrong. So use the stat info about symlinks instead. (Doesn't check the parent directory, but if that's read only we can't delete the file anyway so prompting is moot.)
author Rob Landley <rob@landley.net>
date Mon, 10 Dec 2012 01:48:02 -0600
parents 451d7e91232e
children 8947c0d35e58
comparison
equal deleted inserted replaced
745:0faab963ea92 746:5caa4035c1c8
33 // Intentionally fail non-recursive attempts to remove even an empty dir 33 // Intentionally fail non-recursive attempts to remove even an empty dir
34 // (via wrong flags to unlinkat) because POSIX says to. 34 // (via wrong flags to unlinkat) because POSIX says to.
35 if (dir && !(flags & (FLAG_r|FLAG_R))) goto skip; 35 if (dir && !(flags & (FLAG_r|FLAG_R))) goto skip;
36 36
37 // This is either the posix section 2(b) prompt or the section 3 prompt. 37 // This is either the posix section 2(b) prompt or the section 3 prompt.
38 if (!(flags & FLAG_f) && faccessat(fd, try->name, W_OK, AT_SYMLINK_NOFOLLOW)) 38 if (!(flags & FLAG_f)
39 or++; 39 && (!S_ISLNK(try->st.st_mode) && faccessat(fd, try->name, W_OK, 0))) or++;
40 if (!(dir && try->data == -1) && ((or && isatty(0)) || (flags & FLAG_i))) { 40 if (!(dir && try->data == -1) && ((or && isatty(0)) || (flags & FLAG_i))) {
41 char *s = dirtree_path(try, 0); 41 char *s = dirtree_path(try, 0);
42 fprintf(stderr, "rm %s%s", or ? "ro " : "", dir ? "dir " : ""); 42 fprintf(stderr, "rm %s%s", or ? "ro " : "", dir ? "dir " : "");
43 or = yesno(s, 0); 43 or = yesno(s, 0);
44 free(s); 44 free(s);