mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 11:12:11 +01:00
Merge branch 'wjt/g-file-info-filesystem-readonly-fails' into 'master'
Improve tests/g-file-info-filesystem-readonly, and run it in CI. Closes #1590 See merge request GNOME/glib!466
This commit is contained in:
commit
b323635d79
@ -1,4 +1,4 @@
|
||||
image: registry.gitlab.gnome.org/gnome/glib/master:v9
|
||||
image: registry.gitlab.gnome.org/gnome/glib/master:v10
|
||||
|
||||
stages:
|
||||
- build
|
||||
|
@ -3,9 +3,11 @@ FROM fedora:27
|
||||
RUN dnf -y install \
|
||||
autoconf \
|
||||
automake \
|
||||
bindfs \
|
||||
desktop-file-utils \
|
||||
elfutils-libelf-devel \
|
||||
findutils \
|
||||
fuse \
|
||||
gamin-devel \
|
||||
gcc \
|
||||
gcc-c++ \
|
||||
|
23
.gitlab-ci/README.md
Normal file
23
.gitlab-ci/README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# CI support stuff
|
||||
|
||||
## Docker image
|
||||
|
||||
GitLab CI jobs run in a Docker image, defined here. To update that image
|
||||
(perhaps to install some more packages):
|
||||
|
||||
1. Edit `.gitlab-ci/Dockerfile` with the changes you want
|
||||
2. Edit `.gitlab-ci/run-docker.sh` and bump the version in `TAG`
|
||||
3. Run `.gitlab-ci/run-docker.sh` to build the new image, and launch a shell
|
||||
inside it
|
||||
* When you're done, exit the shell in the usual way
|
||||
4. Run `.gitlab-ci/run-docker.sh --push` to upload the new image to the GNOME
|
||||
GitLab Docker registry
|
||||
* If this is the first time you're doing this, you'll need to log into the
|
||||
registry
|
||||
* If you use 2-factor authentication on your GNOME GitLab account, you'll
|
||||
need to [create a personal access token][pat] and use that rather than
|
||||
your normal password
|
||||
5. Edit `.gitlab-ci.yml` (in the root of this repository) to use your new
|
||||
image
|
||||
|
||||
[pat]: https://gitlab.gnome.org/profile/personal_access_tokens
|
@ -2,8 +2,9 @@
|
||||
|
||||
set -e
|
||||
|
||||
TAG="registry.gitlab.gnome.org/gnome/glib/master:v9"
|
||||
TAG="registry.gitlab.gnome.org/gnome/glib/master:v10"
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
docker build --build-arg HOST_USER_ID="$UID" --tag "${TAG}" \
|
||||
--file "Dockerfile" .
|
||||
|
||||
|
@ -19,11 +19,48 @@
|
||||
* if advised of the possibility of such damage.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gunixmounts.h>
|
||||
|
||||
static void
|
||||
run (GError **error,
|
||||
const gchar *argv0,
|
||||
...)
|
||||
{
|
||||
GPtrArray *args;
|
||||
const gchar *arg;
|
||||
va_list ap;
|
||||
GSubprocess *subprocess;
|
||||
|
||||
args = g_ptr_array_new ();
|
||||
|
||||
va_start (ap, argv0);
|
||||
g_ptr_array_add (args, (gchar *) argv0);
|
||||
while ((arg = va_arg (ap, const gchar *)))
|
||||
g_ptr_array_add (args, (gchar *) arg);
|
||||
g_ptr_array_add (args, NULL);
|
||||
va_end (ap);
|
||||
|
||||
subprocess = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
|
||||
g_ptr_array_free (args, TRUE);
|
||||
|
||||
if (subprocess == NULL)
|
||||
return;
|
||||
|
||||
g_subprocess_wait_check (subprocess, NULL, error);
|
||||
g_object_unref (subprocess);
|
||||
}
|
||||
|
||||
static void
|
||||
assert_remove (const gchar *file)
|
||||
{
|
||||
if (g_remove (file) != 0)
|
||||
g_error ("failed to remove %s: %s", file, g_strerror (errno));
|
||||
}
|
||||
|
||||
static void
|
||||
test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
{
|
||||
@ -31,9 +68,9 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
GFile *mounted_file;
|
||||
GUnixMountMonitor *mount_monitor = NULL;
|
||||
gchar *bindfs, *fusermount;
|
||||
gchar *command_mount, *command_mount_ro, *command_umount;
|
||||
gchar *curdir, *dir_to_mount, *dir_mountpoint;
|
||||
gchar *file_in_mount, *file_in_mountpoint;
|
||||
GError *error = NULL;
|
||||
|
||||
/* installed by package 'bindfs' in Fedora */
|
||||
bindfs = g_find_program_in_path ("bindfs");
|
||||
@ -68,8 +105,8 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
|
||||
/* Use bindfs, which does not need root privileges, to mount the contents of one dir
|
||||
* into another dir (and do the mount as readonly as per passed '-o ro' option) */
|
||||
command_mount_ro = g_strdup_printf ("%s -n -o ro '%s' '%s'", bindfs, dir_to_mount, dir_mountpoint);
|
||||
g_spawn_command_line_sync (command_mount_ro, NULL, NULL, NULL, NULL);
|
||||
run (&error, bindfs, "-n", "-o", "ro", dir_to_mount, dir_mountpoint, NULL);
|
||||
g_assert_no_error (error);
|
||||
|
||||
/* Let's check now, that the file is in indeed in a readonly filesystem */
|
||||
file_in_mountpoint = g_strdup_printf ("%s/example.txt", dir_mountpoint);
|
||||
@ -83,7 +120,9 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
}
|
||||
|
||||
file_info = g_file_query_filesystem_info (mounted_file,
|
||||
G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, NULL, NULL);
|
||||
G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_nonnull (file_info);
|
||||
if (! g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY))
|
||||
{
|
||||
g_test_skip ("Failed to create readonly file needed to proceed further with the test");
|
||||
@ -91,10 +130,10 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
}
|
||||
|
||||
/* Now we unmount, and mount again but this time rw (not readonly) */
|
||||
command_umount = g_strdup_printf ("%s -u '%s'", fusermount, dir_mountpoint);
|
||||
g_spawn_command_line_sync (command_umount, NULL, NULL, NULL, NULL);
|
||||
command_mount = g_strdup_printf ("%s -n '%s' '%s'", bindfs, dir_to_mount, dir_mountpoint);
|
||||
g_spawn_command_line_sync (command_mount, NULL, NULL, NULL, NULL);
|
||||
run (&error, fusermount, "-z", "-u", dir_mountpoint, NULL);
|
||||
g_assert_no_error (error);
|
||||
run (&error, bindfs, "-n", dir_to_mount, dir_mountpoint, NULL);
|
||||
g_assert_no_error (error);
|
||||
|
||||
if (with_mount_monitor)
|
||||
{
|
||||
@ -108,40 +147,28 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
|
||||
g_clear_object (&mounted_file);
|
||||
mounted_file = g_file_new_for_path (file_in_mountpoint);
|
||||
file_info = g_file_query_filesystem_info (mounted_file,
|
||||
G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, NULL, NULL);
|
||||
G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_nonnull (file_info);
|
||||
|
||||
if (g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY))
|
||||
{
|
||||
/* ¡¡ GIO still reports filesystem as being Readonly !!
|
||||
* Let's check if that's true by trying to write to file */
|
||||
GFileOutputStream *write_stream;
|
||||
write_stream = g_file_append_to (mounted_file, G_FILE_CREATE_NONE, NULL, NULL);
|
||||
if (write_stream != NULL)
|
||||
{
|
||||
/* The file has been opened for writing without error, so ¡¡ GIO IS WRONG !! */
|
||||
g_object_unref (write_stream);
|
||||
g_test_fail (); /* Marking test as FAILED */
|
||||
}
|
||||
}
|
||||
g_assert_false (g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY));
|
||||
|
||||
/* Clean up */
|
||||
g_clear_object (&mount_monitor);
|
||||
g_clear_object (&file_info);
|
||||
g_clear_object (&mounted_file);
|
||||
g_spawn_command_line_sync (command_umount, NULL, NULL, NULL, NULL); /* unmount */
|
||||
run (&error, fusermount, "-z", "-u", dir_mountpoint, NULL);
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_remove (file_in_mount);
|
||||
g_remove (dir_to_mount);
|
||||
g_remove (dir_mountpoint);
|
||||
assert_remove (file_in_mount);
|
||||
assert_remove (dir_to_mount);
|
||||
assert_remove (dir_mountpoint);
|
||||
|
||||
g_free (bindfs);
|
||||
g_free (fusermount);
|
||||
g_free (curdir);
|
||||
g_free (dir_to_mount);
|
||||
g_free (dir_mountpoint);
|
||||
g_free (command_mount);
|
||||
g_free (command_mount_ro);
|
||||
g_free (command_umount);
|
||||
g_free (file_in_mount);
|
||||
g_free (file_in_mountpoint);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user