summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2015-02-15 14:11:58 -0500
committerColin Walters <walters@verbum.org>2015-02-15 14:11:58 -0500
commit16862cc4d4e38493705386cf26e2eb46063809ea (patch)
tree77212c71f5ff0510dc5125eeea310f0b99901087
parent6f5b70922ee1f329c24b8a74f61be4f4c0c946ef (diff)
downloadlibgsystem-16862cc4d4e38493705386cf26e2eb46063809ea.tar.gz
Start using libglnx
We can pull in libglnx here, and have this module become a GFile * wrapper plus legacy code.
-rw-r--r--.gitmodules3
-rw-r--r--Makefile-libgsystem.am4
-rw-r--r--Makefile.am6
-rw-r--r--buildutil/glib-tap.mk1
m---------libglnx0
-rw-r--r--src/gsystem-shutil.c151
6 files changed, 16 insertions, 149 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..e5084af
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "libglnx"]
+ path = libglnx
+ url = https://git.gnome.org/browse/libglnx
diff --git a/Makefile-libgsystem.am b/Makefile-libgsystem.am
index 676a230..9ee5fcd 100644
--- a/Makefile-libgsystem.am
+++ b/Makefile-libgsystem.am
@@ -43,9 +43,9 @@ libgsystem_la_SOURCES = \
src/gsystem-subprocess.c \
$(NULL)
-libgsystem_la_CFLAGS = $(AM_CFLAGS) $(BUILDDEP_GIO_UNIX_CFLAGS) $(BUILDDEP_SYSTEMD_JOURNAL_CFLAGS) -I$(srcdir)/src -DGSYSTEM_CONFIG_XATTRS
+libgsystem_la_CFLAGS = $(AM_CFLAGS) $(BUILDDEP_GIO_UNIX_CFLAGS) $(BUILDDEP_SYSTEMD_JOURNAL_CFLAGS) -I$(srcdir)/src -I$(srcdir)/libglnx -DGSYSTEM_CONFIG_XATTRS
libgsystem_la_LDFLAGS = -version-info 0:0:0 -Bsymbolic-functions -export-symbols-regex "^gs_" -no-undefined -export-dynamic
-libgsystem_la_LIBADD = $(BUILDDEP_GIO_UNIX_LIBS) $(BUILDDEP_SYSTEMD_JOURNAL_LIBS)
+libgsystem_la_LIBADD = $(BUILDDEP_GIO_UNIX_LIBS) $(BUILDDEP_SYSTEMD_JOURNAL_LIBS) libglnx.la
pkgconfig_DATA += src/libgsystem.pc
diff --git a/Makefile.am b/Makefile.am
index 74bbbdf..6a76e9f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,5 +31,11 @@ if BUILDOPT_INTROSPECTION
include $(INTROSPECTION_MAKEFILE)
endif
+libglnx_srcpath := $(srcdir)/libglnx
+libglnx_cflags := $(BUILDDEP_GIO_UNIX_CFLAGS) -I$(libglnx_srcpath)
+libglnx_libs := $(BUILDDEP_GIO_UNIX_LIBS)
+
+noinst_LTLIBRARIES += libglnx.la
+include libglnx/Makefile-libglnx.am
include Makefile-libgsystem.am
include Makefile-tests.am
diff --git a/buildutil/glib-tap.mk b/buildutil/glib-tap.mk
index f25bb83..6b4af88 100644
--- a/buildutil/glib-tap.mk
+++ b/buildutil/glib-tap.mk
@@ -16,7 +16,6 @@ installed_test_PROGRAMS =
installed_test_SCRIPTS =
nobase_installed_test_DATA =
-noinst_LTLIBRARIES =
noinst_PROGRAMS =
noinst_SCRIPTS =
noinst_DATA =
diff --git a/libglnx b/libglnx
new file mode 160000
+Subproject ba67dd39a7d5cc779f83bb22512740cdb4c61b3
diff --git a/src/gsystem-shutil.c b/src/gsystem-shutil.c
index c15dc3f..e8e6ca3 100644
--- a/src/gsystem-shutil.c
+++ b/src/gsystem-shutil.c
@@ -25,8 +25,7 @@
#define _GNU_SOURCE
#endif
-#define _GSYSTEM_NO_LOCAL_ALLOC
-#include "libgsystem.h"
+#include <libglnx.h>
#include "gsystem-glib-compat.h"
#include <glib-unix.h>
#include <string.h>
@@ -34,6 +33,9 @@
#include <dirent.h>
#include <fcntl.h>
+#define _GSYSTEM_NO_LOCAL_ALLOC
+#include "libgsystem.h"
+
/* Taken from systemd/src/shared/util.h */
union dirent_storage {
struct dirent dent;
@@ -261,97 +263,6 @@ gs_shutil_cp_a (GFile *src,
cancellable, error);
}
-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
-gs_shutil_rm_rf_children (GSDirFdIterator *dfd_iter,
- GCancellable *cancellable,
- GError **error)
-{
- gboolean ret = FALSE;
- struct dirent *dent;
-
- while (TRUE)
- {
- if (!gs_dirfd_iterator_next_dent (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)
- {
- int errsv = errno;
- if (errsv == ENOENT)
- continue;
- else
- {
- gs_set_error_from_errno (error, errsv);
- 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)
- {
- gs_dirfd_iterator_cleanup GSDirFdIterator child_dfd_iter = { 0, };
-
- if (!gs_dirfd_iterator_init_at (dfd_iter->fd, dent->d_name, FALSE,
- &child_dfd_iter, error))
- goto out;
-
- if (!gs_shutil_rm_rf_children (&child_dfd_iter, cancellable, error))
- goto out;
-
- if (unlinkat (dfd_iter->fd, dent->d_name, AT_REMOVEDIR) == -1)
- {
- gs_set_error_from_errno (error, errno);
- goto out;
- }
- }
- else
- {
- if (unlinkat (dfd_iter->fd, dent->d_name, 0) == -1)
- {
- if (errno != ENOENT)
- {
- gs_set_error_from_errno (error, errno);
- goto out;
- }
- }
- }
- }
-
- ret = TRUE;
- out:
- return ret;
-}
-
/**
* gs_shutil_rm_rf_at:
* @dfd: A directory file descriptor, or -1 for current
@@ -369,59 +280,7 @@ gs_shutil_rm_rf_at (int dfd,
GCancellable *cancellable,
GError **error)
{
- gboolean ret = FALSE;
- int target_dfd = -1;
- gs_dirfd_iterator_cleanup GSDirFdIterator dfd_iter = { 0, };
-
- /* With O_NOFOLLOW first */
- target_dfd = openat (dfd, path,
- O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
-
- if (target_dfd == -1)
- {
- int errsv = errno;
- if (errsv == ENOENT)
- {
- ;
- }
- else if (errsv == ENOTDIR || errsv == ELOOP)
- {
- if (unlinkat (dfd, path, 0) != 0)
- {
- gs_set_error_from_errno (error, errno);
- goto out;
- }
- }
- else
- {
- gs_set_error_from_errno (error, errno);
- goto out;
- }
- }
- else
- {
- if (!gs_dirfd_iterator_init_take_fd (target_dfd, &dfd_iter, error))
- goto out;
- target_dfd = -1;
-
- if (!gs_shutil_rm_rf_children (&dfd_iter, cancellable, error))
- goto out;
-
- if (unlinkat (dfd, path, AT_REMOVEDIR) == -1)
- {
- int errsv = errno;
- if (errsv != ENOENT)
- {
- gs_set_error_from_errno (error, errno);
- goto out;
- }
- }
- }
-
- ret = TRUE;
- out:
- if (target_dfd != -1) (void) close (target_dfd);
- return ret;
+ return glnx_shutil_rm_rf_at (dfd, path, cancellable, error);
}
/**