diff options
author | Colin Walters <walters@verbum.org> | 2016-07-29 13:08:17 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2016-07-29 13:08:17 -0400 |
commit | 80e5af921878adfd99ec2e6cb974d88b3f6f5041 (patch) | |
tree | ab50a5e33d047664180ec4e2788a6b5176f84446 | |
parent | c072ef1ebab052bdecb0d9a52c14813728f83859 (diff) | |
download | libglnx-80e5af921878adfd99ec2e6cb974d88b3f6f5041.tar.gz |
shutil: Use new API to iterate ensuring d_type
This drops a lot of duplicate code.
-rw-r--r-- | glnx-shutil.c | 41 |
1 files changed, 1 insertions, 40 deletions
diff --git a/glnx-shutil.c b/glnx-shutil.c index 281e5bf..6ff9fa6 100644 --- a/glnx-shutil.c +++ b/glnx-shutil.c @@ -26,26 +26,6 @@ #include <glnx-errors.h> #include <glnx-local-alloc.h> -static unsigned char -struct_stat_to_dt (struct stat *stbuf) -{ - if (S_ISDIR (stbuf->st_mode)) - return DT_DIR; - if (S_ISREG (stbuf->st_mode)) - return DT_REG; - if (S_ISCHR (stbuf->st_mode)) - return DT_CHR; - if (S_ISBLK (stbuf->st_mode)) - return DT_BLK; - if (S_ISFIFO (stbuf->st_mode)) - return DT_FIFO; - if (S_ISLNK (stbuf->st_mode)) - return DT_LNK; - if (S_ISSOCK (stbuf->st_mode)) - return DT_SOCK; - return DT_UNKNOWN; -} - static gboolean glnx_shutil_rm_rf_children (GLnxDirFdIterator *dfd_iter, GCancellable *cancellable, @@ -56,31 +36,12 @@ glnx_shutil_rm_rf_children (GLnxDirFdIterator *dfd_iter, while (TRUE) { - if (!glnx_dirfd_iterator_next_dent (dfd_iter, &dent, cancellable, error)) + if (!glnx_dirfd_iterator_next_dent_ensure_dtype (dfd_iter, &dent, cancellable, error)) goto out; if (dent == NULL) break; - if (dent->d_type == DT_UNKNOWN) - { - struct stat stbuf; - if (fstatat (dfd_iter->fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW) == -1) - { - if (errno == ENOENT) - continue; - else - { - glnx_set_error_from_errno (error); - goto out; - } - } - dent->d_type = struct_stat_to_dt (&stbuf); - /* Assume unknown types are just treated like regular files */ - if (dent->d_type == DT_UNKNOWN) - dent->d_type = DT_REG; - } - if (dent->d_type == DT_DIR) { g_auto(GLnxDirFdIterator) child_dfd_iter = { 0, }; |