New upstream version 2017.9
This commit is contained in:
commit
e5ac0cef85
134 files changed
+3986
-5324
No files matched your search
@@ -125,6 +125,48 @@ test_error_errno (void)
|
||||
g_assert_cmpint (fd, ==, -1);
|
||||
}
|
||||
|
||||
static void
|
||||
test_error_auto_nothrow (GError **error)
|
||||
{
|
||||
GLNX_AUTO_PREFIX_ERROR("foo", error);
|
||||
/* Side effect to avoid otherwise empty function */
|
||||
g_assert_no_error (*error);
|
||||
}
|
||||
|
||||
static void
|
||||
test_error_auto_throw (GError **error)
|
||||
{
|
||||
GLNX_AUTO_PREFIX_ERROR("foo", error);
|
||||
(void) glnx_throw (error, "oops");
|
||||
}
|
||||
|
||||
static void
|
||||
test_error_auto_throw_recurse (GError **error)
|
||||
{
|
||||
GLNX_AUTO_PREFIX_ERROR("foo", error);
|
||||
|
||||
if (TRUE)
|
||||
{
|
||||
GLNX_AUTO_PREFIX_ERROR("bar", error);
|
||||
(void) glnx_throw (error, "oops");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_error_auto (void)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
test_error_auto_nothrow (&error);
|
||||
g_assert_no_error (error);
|
||||
test_error_auto_throw (&error);
|
||||
g_assert_nonnull (error);
|
||||
g_assert_cmpstr (error->message, ==, "foo: oops");
|
||||
g_clear_error (&error);
|
||||
test_error_auto_throw_recurse (&error);
|
||||
g_assert_nonnull (error);
|
||||
g_assert_cmpstr (error->message, ==, "foo: bar: oops");
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
@@ -133,6 +175,7 @@ int main (int argc, char **argv)
|
||||
|
||||
g_test_add_func ("/error-throw", test_error_throw);
|
||||
g_test_add_func ("/error-errno", test_error_errno);
|
||||
g_test_add_func ("/error-auto", test_error_auto);
|
||||
|
||||
ret = g_test_run();
|
||||
|
||||
|
||||
@@ -137,12 +137,66 @@ test_renameat2_exchange (void)
|
||||
g_assert_no_error (local_error);
|
||||
}
|
||||
|
||||
static void
|
||||
test_tmpfile (void)
|
||||
{
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
GError **error = &local_error;
|
||||
g_auto(GLnxTmpfile) tmpf = { 0, };
|
||||
|
||||
if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, ".", O_WRONLY|O_CLOEXEC, &tmpf, error))
|
||||
goto out;
|
||||
|
||||
if (glnx_loop_write (tmpf.fd, "foo", strlen ("foo")) < 0)
|
||||
{
|
||||
(void)glnx_throw_errno_prefix (error, "write");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_NOREPLACE, AT_FDCWD, "foo", error))
|
||||
goto out;
|
||||
|
||||
out:
|
||||
g_assert_no_error (local_error);
|
||||
}
|
||||
|
||||
static void
|
||||
test_stdio_file (void)
|
||||
{
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
GError **error = &local_error;
|
||||
g_auto(GLnxTmpfile) tmpf = { 0, };
|
||||
g_autoptr(FILE) f = NULL;
|
||||
|
||||
if (!glnx_open_anonymous_tmpfile (O_RDWR|O_CLOEXEC, &tmpf, error))
|
||||
goto out;
|
||||
f = fdopen (tmpf.fd, "w");
|
||||
if (!f)
|
||||
{
|
||||
(void)glnx_throw_errno_prefix (error, "fdopen");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (fwrite ("hello", 1, strlen ("hello"), f) != strlen ("hello"))
|
||||
{
|
||||
(void)glnx_throw_errno_prefix (error, "fwrite");
|
||||
goto out;
|
||||
}
|
||||
if (!glnx_stdio_file_flush (f, error))
|
||||
goto out;
|
||||
|
||||
out:
|
||||
g_assert_no_error (local_error);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/tmpfile", test_tmpfile);
|
||||
g_test_add_func ("/stdio-file", test_stdio_file);
|
||||
g_test_add_func ("/renameat2-noreplace", test_renameat2_noreplace);
|
||||
g_test_add_func ("/renameat2-exchange", test_renameat2_exchange);
|
||||
|
||||
|
||||
@@ -107,22 +107,17 @@ do_write_run (GLnxDirFdIterator *dfd_iter, GError **error)
|
||||
{
|
||||
while (TRUE)
|
||||
{
|
||||
g_autoptr(GVariant) current_xattrs = NULL;
|
||||
glnx_fd_close int fd = -1;
|
||||
|
||||
struct dirent *dent;
|
||||
if (!glnx_dirfd_iterator_next_dent (dfd_iter, &dent, NULL, error))
|
||||
return FALSE;
|
||||
if (!dent)
|
||||
break;
|
||||
|
||||
fd = openat (dfd_iter->fd, dent->d_name, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
{
|
||||
glnx_set_error_from_errno (error);
|
||||
return FALSE;
|
||||
}
|
||||
glnx_fd_close int fd = -1;
|
||||
if (!glnx_openat_rdonly (dfd_iter->fd, dent->d_name, FALSE, &fd, error))
|
||||
return FALSE;
|
||||
|
||||
g_autoptr(GVariant) current_xattrs = NULL;
|
||||
if (!glnx_fd_get_all_xattrs (fd, ¤t_xattrs, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
@@ -156,22 +151,17 @@ do_read_run (GLnxDirFdIterator *dfd_iter,
|
||||
guint nattrs = 0;
|
||||
while (TRUE)
|
||||
{
|
||||
g_autoptr(GVariant) current_xattrs = NULL;
|
||||
glnx_fd_close int fd = -1;
|
||||
|
||||
struct dirent *dent;
|
||||
if (!glnx_dirfd_iterator_next_dent (dfd_iter, &dent, NULL, error))
|
||||
return FALSE;
|
||||
if (!dent)
|
||||
break;
|
||||
|
||||
fd = openat (dfd_iter->fd, dent->d_name, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
{
|
||||
glnx_set_error_from_errno (error);
|
||||
return FALSE;
|
||||
}
|
||||
glnx_fd_close int fd = -1;
|
||||
if (!glnx_openat_rdonly (dfd_iter->fd, dent->d_name, FALSE, &fd, error))
|
||||
return FALSE;
|
||||
|
||||
g_autoptr(GVariant) current_xattrs = NULL;
|
||||
if (!glnx_fd_get_all_xattrs (fd, ¤t_xattrs, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
|
||||
Reference in new issue
Block a user