Lines Matching refs:new
96 static int flush_exec(struct dirtree *new, struct exec_range *aa)
109 if (aa->dir && new && new->parent) {
111 rc = fchdir(new->parent->dirfd);
114 perror_msg_raw(revert ? new->name : ".");
164 static void do_print(struct dirtree *new, char c)
166 char *s=dirtree_path(new, 0);
173 static void execdir(struct dirtree *new, int flush)
179 if (new && TT.topdir == -1) return;
184 if (!aa->plus || (new && !aa->dir)) continue;
190 toys.exitval |= flush_exec(new, aa);
199 // Push new per-directory struct for -execdir/okdir + codepath. (Can't
200 // use new->extra because command line may have multiple -execdir)
211 static int do_find(struct dirtree *new)
213 int pcount = 0, print = 0, not = 0, active = !!new, test = active, recurse;
221 if (new) {
223 if (new->again&2) {
224 if (!new->parent || errno != ENOENT) {
225 perror_msg("'%s'", s = dirtree_path(new, 0));
230 if (new->parent) {
231 if (!dirtree_notdotdot(new)) return 0;
232 if (TT.xdev && new->st.st_dev != new->parent->st.st_dev) recurse = 0;
233 } else TT.start = new->name;
235 if (S_ISDIR(new->st.st_mode)) {
236 // Descending into new directory
237 if (!new->again) {
240 for (n = new->parent; n; n = n->parent) {
241 if (n->st.st_ino==new->st.st_ino && n->st.st_dev==new->st.st_dev) {
242 error_msg("'%s': loop detected", s = dirtree_path(new, 0));
250 execdir(new, 0);
256 execdir(new, 1);
307 if (new && check)
308 test = !unlinkat(dirtree_parentfd(new), new->name,
309 S_ISDIR(new->st.st_mode) ? AT_REMOVEDIR : 0);
331 if (check) do_print(new, s[5] ? 0 : '\n');
336 if (S_ISDIR(new->st.st_mode)) {
337 int fd = openat(dirtree_parentfd(new), new->name, O_RDONLY);
345 } else if (S_ISREG(new->st.st_mode)) {
346 if (new->st.st_size) test = 0;
350 if (check && bufgetpwuid(new->st.st_uid)) test = 0;
352 if (check && bufgetgrgid(new->st.st_gid)) test = 0;
354 if (check && S_ISDIR(new->st.st_mode) && !TT.depth) recurse = 0;
356 if (check && faccessat(dirtree_parentfd(new), new->name,X_OK,0)) test = 0;
371 char *arg = ss[1], *path = 0, *name = new ? new->name : arg;
374 if (new && s[i] == 'l')
375 name = path = xreadlinkat(dirtree_parentfd(new), new->name);
376 else if (new && is_path) name = path = dirtree_path(new, 0);
378 if ((check || !new) && name) name = strlower(name);
379 if (!new) dlist_add(&TT.argdata, name);
391 char *path = dirtree_path(new, 0), *context;
405 m2 = new->st.st_mode & 07777;
420 if ((new->st.st_mode & S_IFMT) == types[i]) break;
430 time_t thyme = (int []){new->st.st_atime, new->st.st_ctime,
431 new->st.st_mtime}[stridx("acm", *s)];
443 if (check) test = compare_numsign(new->st.st_size, 512, ss[1]);
445 if (check) test = compare_numsign(new->st.st_nlink, 0, ss[1]);
447 if (check) test = compare_numsign(new->st.st_ino, 0, ss[1]);
450 struct dirtree *dt = new;
476 if (!new) {
502 if (*s == 'u') test = new->st.st_uid == udl->u.uid;
503 else if (*s == 'g') test = new->st.st_gid == udl->u.gid;
505 struct timespec *tm = (void *)(((char *)&new->st)
523 if (!new) {
562 // name is always a new malloc, so we can always free it.
563 name = aa->dir ? xstrdup(new->name) : dirtree_path(new, 0);
590 toys.exitval |= flush_exec(new, aa);
592 } else test = !flush_exec(new, aa);
624 printf(next, (ch == 'i') ? (long long)new->st.st_ino
625 : (long long)new->st.st_size);
630 if (ch == 'G') next[len] = 'd', ll = new->st.st_gid;
631 else if (ch == 'm') next[len] = 'o', ll = new->st.st_mode&~S_IFMT;
632 else if (ch == 'U') next[len] = 'd', ll = new->st.st_uid;
633 else if (ch == 'f') ll = (long)new->name;
634 else if (ch == 'g') ll = (long)getgroupname(new->st.st_gid);
635 else if (ch == 'u') ll = (long)getusername(new->st.st_uid);
637 ll = (long)(ff = xreadlinkat(dirtree_parentfd(new), new->name));
640 mode_to_string(new->st.st_mode, buf);
645 ll = (long)(ff = dirtree_path(new, 0));
647 } else if (ch == 'p') ll = (long)(ff = dirtree_path(new, 0));
650 sprintf(buf, "%lld.%ld", (long long)new->st.st_mtim.tv_sec,
651 new->st.st_mtim.tv_nsec);
654 char *path = dirtree_path(new, 0);
678 if (new) {
680 if (!print && test) do_print(new, '\n');
682 if (S_ISDIR(new->st.st_mode)) execdir(new, 0);