MCPcopy Create free account
hub / github.com/coreutils/coreutils / excise

Function excise

src/remove.c:390–433  ·  view source on GitHub ↗

Remove the file system object specified by ENT. IS_DIR specifies whether it is expected to be a directory or non-directory. Return RM_OK upon success, else RM_ERROR. */

Source from the content-addressed store, hash-verified

388 whether it is expected to be a directory or non-directory.
389 Return RM_OK upon success, else RM_ERROR. */
390static enum RM_status
391excise (FTS *fts, FTSENT *ent, struct rm_options const *x, bool is_dir)
392{
393 int flag = is_dir ? AT_REMOVEDIR : 0;
394 if (unlinkat (fts->fts_cwd_fd, ent->fts_accpath, flag) == 0)
395 {
396 if (x->verbose)
397 {
398 printf ((is_dir
399 ? _("removed directory %s\n")
400 : _("removed %s\n")), quoteaf (ent->fts_path));
401 }
402 return RM_OK;
403 }
404
405 /* The unlinkat from kernels like linux-2.6.32 reports EROFS even for
406 nonexistent files. When the file is indeed missing, map that to ENOENT,
407 so that rm -f ignores it, as required. Even without -f, this is useful
408 because it makes rm print the more precise diagnostic. */
409 if (errno == EROFS)
410 {
411 struct stat st;
412 if ( ! (fstatat (fts->fts_cwd_fd, ent->fts_accpath, &st,
413 AT_SYMLINK_NOFOLLOW)
414 && errno == ENOENT))
415 errno = EROFS;
416 }
417
418 if (ignorable_missing (x, errno))
419 return RM_OK;
420
421 /* When failing to rmdir an unreadable directory, we see errno values
422 like EISDIR or ENOTDIR (or, on Solaris 10, EEXIST), but they would be
423 meaningless in a diagnostic. When that happens, use the earlier, more
424 descriptive errno value. */
425 if (ent->fts_info == FTS_DNR
426 && (errno == ENOTEMPTY || errno == EISDIR || errno == ENOTDIR
427 || errno == EEXIST)
428 && ent->fts_errno != 0)
429 errno = ent->fts_errno;
430 error (0, errno, _("cannot remove %s"), quoteaf (ent->fts_path));
431 mark_ancestor_dirs (ent);
432 return RM_ERROR;
433}
434
435/* This function is called once for every file system object that fts
436 encounters. fts performs a depth-first traversal.

Callers 1

rm_ftsFunction · 0.85

Calls 2

ignorable_missingFunction · 0.85
mark_ancestor_dirsFunction · 0.85

Tested by

no test coverage detected