| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | /* GLib testing framework examples and tests
 | 
					
						
							|  |  |  |  * Copyright (C) 2008 Red Hat, Inc. | 
					
						
							|  |  |  |  * Authors: Tomas Bzatek <tbzatek@redhat.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This work is provided "as is"; redistribution and modification | 
					
						
							|  |  |  |  * in whole or in part, in any medium, physical or electronic is | 
					
						
							|  |  |  |  * permitted without restriction. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This work is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * In no event shall the authors or contributors be liable for any | 
					
						
							|  |  |  |  * direct, indirect, incidental, special, exemplary, or consequential | 
					
						
							|  |  |  |  * damages (including, but not limited to, procurement of substitute | 
					
						
							|  |  |  |  * goods or services; loss of use, data, or profits; or business | 
					
						
							|  |  |  |  * interruption) however caused and on any theory of liability, whether | 
					
						
							|  |  |  |  * in contract, strict liability, or tort (including negligence or | 
					
						
							|  |  |  |  * otherwise) arising in any way out of the use of this software, even | 
					
						
							|  |  |  |  * if advised of the possibility of such damage. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <glib/glib.h>
 | 
					
						
							|  |  |  | #include <gio/gio.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2013-03-04 20:03:26 +01:00
										 |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2010-02-19 19:00:02 +01:00
										 |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | #include <sys/types.h>
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2008-07-01 06:32:35 +00:00
										 |  |  | #include <sys/stat.h>
 | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define DEFAULT_TEST_DIR		"testdir_live-g-file"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | #define PATTERN_FILE_SIZE	0x10000
 | 
					
						
							|  |  |  | #define TEST_HANDLE_SPECIAL	TRUE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum StructureExtraFlags | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   TEST_DELETE_NORMAL = 1 << 0, | 
					
						
							|  |  |  |   TEST_DELETE_TRASH = 1 << 1, | 
					
						
							|  |  |  |   TEST_DELETE_NON_EMPTY = 1 << 2, | 
					
						
							|  |  |  |   TEST_DELETE_FAILURE = 1 << 3, | 
					
						
							|  |  |  |   TEST_NOT_EXISTS = 1 << 4, | 
					
						
							|  |  |  |   TEST_ENUMERATE_FILE = 1 << 5, | 
					
						
							|  |  |  |   TEST_NO_ACCESS = 1 << 6, | 
					
						
							|  |  |  |   TEST_COPY = 1 << 7, | 
					
						
							|  |  |  |   TEST_MOVE = 1 << 8, | 
					
						
							|  |  |  |   TEST_COPY_ERROR_RECURSE = 1 << 9, | 
					
						
							|  |  |  |   TEST_ALREADY_EXISTS = 1 << 10, | 
					
						
							|  |  |  |   TEST_TARGET_IS_FILE = 1 << 11, | 
					
						
							|  |  |  |   TEST_CREATE = 1 << 12, | 
					
						
							|  |  |  |   TEST_REPLACE = 1 << 13, | 
					
						
							|  |  |  |   TEST_APPEND = 1 << 14, | 
					
						
							|  |  |  |   TEST_OPEN = 1 << 15, | 
					
						
							|  |  |  |   TEST_OVERWRITE = 1 << 16, | 
					
						
							|  |  |  |   TEST_INVALID_SYMLINK = 1 << 17, | 
					
						
							| 
									
										
										
										
											2013-03-04 20:03:26 +01:00
										 |  |  |   TEST_HIDDEN = 1 << 18, | 
					
						
							|  |  |  |   TEST_DOT_HIDDEN = 1 << 19, | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct StructureItem | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const char *filename; | 
					
						
							|  |  |  |   const char *link_to; | 
					
						
							|  |  |  |   GFileType file_type; | 
					
						
							|  |  |  |   GFileCreateFlags create_flags; | 
					
						
							|  |  |  |   guint32 mode; | 
					
						
							|  |  |  |   gboolean handle_special; | 
					
						
							|  |  |  |   enum StructureExtraFlags extra_flags; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define TEST_DIR_NO_ACCESS		"dir_no-access"
 | 
					
						
							|  |  |  | #define TEST_DIR_NO_WRITE		"dir_no-write"
 | 
					
						
							|  |  |  | #define TEST_DIR_TARGET			"dir-target"
 | 
					
						
							|  |  |  | #define TEST_NAME_NOT_EXISTS	"not_exists"
 | 
					
						
							|  |  |  | #define TEST_TARGET_FILE		"target-file"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-06 09:53:35 +00:00
										 |  |  | static const struct StructureItem sample_struct[] = { | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | /*	 filename				link	file_type				create_flags		mode | handle_special | extra_flags              */ | 
					
						
							|  |  |  |     {"dir1",				NULL,	G_FILE_TYPE_DIRECTORY,	G_FILE_CREATE_NONE, 0, 0, TEST_DELETE_NORMAL | TEST_DELETE_NON_EMPTY | TEST_REPLACE | TEST_OPEN}, | 
					
						
							|  |  |  |     {"dir1/subdir",			NULL,	G_FILE_TYPE_DIRECTORY,	G_FILE_CREATE_NONE, 0, 0, TEST_COPY	| TEST_COPY_ERROR_RECURSE | TEST_APPEND}, | 
					
						
							|  |  |  |     {"dir2",				NULL,	G_FILE_TYPE_DIRECTORY,	G_FILE_CREATE_NONE, 0, 0, TEST_DELETE_NORMAL | TEST_MOVE | TEST_CREATE}, | 
					
						
							|  |  |  |     {TEST_DIR_TARGET,		NULL,	G_FILE_TYPE_DIRECTORY,	G_FILE_CREATE_NONE, 0, 0, TEST_COPY | TEST_COPY_ERROR_RECURSE}, | 
					
						
							|  |  |  |     {TEST_DIR_NO_ACCESS,	NULL,	G_FILE_TYPE_DIRECTORY,	G_FILE_CREATE_PRIVATE, S_IRUSR + S_IWUSR + S_IRGRP + S_IWGRP + S_IROTH + S_IWOTH, 0, TEST_NO_ACCESS | TEST_OPEN}, | 
					
						
							|  |  |  |     {TEST_DIR_NO_WRITE,		NULL,	G_FILE_TYPE_DIRECTORY,	G_FILE_CREATE_PRIVATE, S_IRUSR + S_IXUSR + S_IRGRP + S_IXGRP + S_IROTH + S_IXOTH, 0, 0}, | 
					
						
							|  |  |  |     {TEST_TARGET_FILE,		NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, 0, TEST_COPY | TEST_OPEN}, | 
					
						
							|  |  |  | 	{"normal_file",			NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, 0, TEST_ENUMERATE_FILE | TEST_CREATE | TEST_OVERWRITE}, | 
					
						
							|  |  |  | 	{"normal_file-symlink",	"normal_file",	G_FILE_TYPE_SYMBOLIC_LINK, G_FILE_CREATE_NONE, 0, 0, TEST_ENUMERATE_FILE | TEST_COPY | TEST_OPEN}, | 
					
						
							|  |  |  |     {"executable_file",		NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, S_IRWXU + S_IRWXG + S_IRWXO, 0, TEST_DELETE_TRASH | TEST_COPY | TEST_OPEN | TEST_OVERWRITE | TEST_REPLACE}, | 
					
						
							|  |  |  |     {"private_file",		NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_PRIVATE, 0, 0, TEST_COPY | TEST_OPEN | TEST_OVERWRITE | TEST_APPEND}, | 
					
						
							|  |  |  |     {"normal_file2",		NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, 0, TEST_COPY | TEST_OVERWRITE | TEST_REPLACE}, | 
					
						
							|  |  |  |     {"readonly_file",		NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, S_IRUSR + S_IRGRP + S_IROTH, 0, TEST_DELETE_NORMAL | TEST_OPEN}, | 
					
						
							| 
									
										
										
										
											2008-06-13 03:56:26 +00:00
										 |  |  |     {"UTF_pr\xcc\x8ci\xcc\x81lis\xcc\x8c z", | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     						NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, 0, TEST_COPY | TEST_CREATE | TEST_OPEN | TEST_OVERWRITE}, | 
					
						
							| 
									
										
										
										
											2008-06-13 03:56:26 +00:00
										 |  |  |     {"dir_pr\xcc\x8ci\xcc\x81lis\xcc\x8c z", | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     						NULL,	G_FILE_TYPE_DIRECTORY,	G_FILE_CREATE_NONE, 0, 0, TEST_DELETE_NORMAL | TEST_CREATE}, | 
					
						
							|  |  |  |     {"pattern_file",		NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, TEST_HANDLE_SPECIAL, TEST_COPY | TEST_OPEN | TEST_APPEND}, | 
					
						
							|  |  |  |     {TEST_NAME_NOT_EXISTS,	NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, TEST_HANDLE_SPECIAL, TEST_DELETE_NORMAL | TEST_NOT_EXISTS | TEST_COPY | TEST_OPEN}, | 
					
						
							|  |  |  |     {TEST_NAME_NOT_EXISTS,	NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, TEST_HANDLE_SPECIAL, TEST_DELETE_TRASH | TEST_NOT_EXISTS | TEST_MOVE}, | 
					
						
							|  |  |  |     {"not_exists2",			NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, TEST_HANDLE_SPECIAL, TEST_NOT_EXISTS | TEST_CREATE}, | 
					
						
							|  |  |  |     {"not_exists3",			NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, TEST_HANDLE_SPECIAL, TEST_NOT_EXISTS | TEST_REPLACE}, | 
					
						
							|  |  |  |     {"not_exists4",			NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, TEST_HANDLE_SPECIAL, TEST_NOT_EXISTS | TEST_APPEND}, | 
					
						
							|  |  |  |     {"dir_no-execute/file",	NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, TEST_HANDLE_SPECIAL, TEST_DELETE_NORMAL | TEST_DELETE_FAILURE | TEST_NOT_EXISTS | TEST_OPEN}, | 
					
						
							|  |  |  | 	{"lost_symlink",		"nowhere",	G_FILE_TYPE_SYMBOLIC_LINK, G_FILE_CREATE_NONE, 0, 0, TEST_COPY | TEST_DELETE_NORMAL | TEST_OPEN | TEST_INVALID_SYMLINK}, | 
					
						
							| 
									
										
										
										
											2013-03-04 20:03:26 +01:00
										 |  |  |     {"dir_hidden",		NULL,	G_FILE_TYPE_DIRECTORY,	G_FILE_CREATE_NONE, 0, 0, 0}, | 
					
						
							|  |  |  |     {"dir_hidden/.hidden",		NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, TEST_HANDLE_SPECIAL, 0}, | 
					
						
							|  |  |  |     {"dir_hidden/.a-hidden-file",	NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, 0, TEST_HIDDEN}, | 
					
						
							|  |  |  |     {"dir_hidden/file-in-.hidden1",	NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, 0, TEST_HIDDEN | TEST_DOT_HIDDEN}, | 
					
						
							|  |  |  |     {"dir_hidden/file-in-.hidden2",	NULL,	G_FILE_TYPE_REGULAR,	G_FILE_CREATE_NONE, 0, 0, TEST_HIDDEN | TEST_DOT_HIDDEN}, | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-19 19:00:02 +01:00
										 |  |  | static gboolean test_suite; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | static gboolean write_test; | 
					
						
							|  |  |  | static gboolean verbose; | 
					
						
							|  |  |  | static gboolean posix_compat; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  | #ifdef G_OS_UNIX
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * check_cap_dac_override: | 
					
						
							|  |  |  |  * @tmpdir: A temporary directory in which we can create and delete files | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Check whether the current process can bypass DAC permissions. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Traditionally, "privileged" processes (those with effective uid 0) | 
					
						
							|  |  |  |  * could do this (and bypass many other checks), and "unprivileged" | 
					
						
							|  |  |  |  * processes could not. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * In Linux, the special powers of euid 0 are divided into many | 
					
						
							|  |  |  |  * capabilities: see `capabilities(7)`. The one we are interested in | 
					
						
							|  |  |  |  * here is `CAP_DAC_OVERRIDE`. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * We do this generically instead of actually looking at the capability | 
					
						
							|  |  |  |  * bits, so that the right thing will happen on non-Linux Unix | 
					
						
							|  |  |  |  * implementations, in particular if they have something equivalent to | 
					
						
							|  |  |  |  * but not identical to Linux permissions. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Returns: %TRUE if we have Linux `CAP_DAC_OVERRIDE` or equivalent | 
					
						
							|  |  |  |  *  privileges | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static gboolean | 
					
						
							|  |  |  | check_cap_dac_override (const char *tmpdir) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   gchar *dac_denies_write; | 
					
						
							|  |  |  |   gchar *inside; | 
					
						
							|  |  |  |   gboolean have_cap; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   dac_denies_write = g_build_filename (tmpdir, "dac-denies-write", NULL); | 
					
						
							|  |  |  |   inside = g_build_filename (dac_denies_write, "inside", NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-31 12:20:53 +00:00
										 |  |  |   g_assert_no_errno (mkdir (dac_denies_write, S_IRWXU)); | 
					
						
							|  |  |  |   g_assert_no_errno (chmod (dac_denies_write, 0)); | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (mkdir (inside, S_IRWXU) == 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       g_test_message ("Looks like we have CAP_DAC_OVERRIDE or equivalent"); | 
					
						
							| 
									
										
										
										
											2020-10-31 12:20:53 +00:00
										 |  |  |       g_assert_no_errno (rmdir (inside)); | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  |       have_cap = TRUE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       int saved_errno = errno; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       g_test_message ("We do not have CAP_DAC_OVERRIDE or equivalent"); | 
					
						
							|  |  |  |       g_assert_cmpint (saved_errno, ==, EACCES); | 
					
						
							|  |  |  |       have_cap = FALSE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-31 12:20:53 +00:00
										 |  |  |   g_assert_no_errno (chmod (dac_denies_write, S_IRWXU)); | 
					
						
							|  |  |  |   g_assert_no_errno (rmdir (dac_denies_write)); | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  |   g_free (dac_denies_write); | 
					
						
							|  |  |  |   g_free (inside); | 
					
						
							|  |  |  |   return have_cap; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-08 04:38:54 +00:00
										 |  |  | #ifdef G_HAVE_ISO_VARARGS
 | 
					
						
							| 
									
										
										
										
											2015-05-11 17:03:00 +01:00
										 |  |  | #define log(...) if (verbose)  g_printerr (__VA_ARGS__)
 | 
					
						
							| 
									
										
										
										
											2008-12-08 04:38:54 +00:00
										 |  |  | #elif defined(G_HAVE_GNUC_VARARGS)
 | 
					
						
							| 
									
										
										
										
											2015-05-11 17:03:00 +01:00
										 |  |  | #define log(msg...) if (verbose)  g_printerr (msg)
 | 
					
						
							| 
									
										
										
										
											2008-12-08 04:38:54 +00:00
										 |  |  | #else  /* no varargs macros */
 | 
					
						
							|  |  |  | static void log (const g_char *format, ...) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   va_list args; | 
					
						
							|  |  |  |   va_start (args, format); | 
					
						
							| 
									
										
										
										
											2015-05-11 17:03:00 +01:00
										 |  |  |   if (verbose) g_printerr (format, args); | 
					
						
							| 
									
										
										
										
											2008-12-08 04:38:54 +00:00
										 |  |  |   va_end (args); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-06 09:53:35 +00:00
										 |  |  | static GFile * | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | create_empty_file (GFile * parent, const char *filename, | 
					
						
							|  |  |  | 		   GFileCreateFlags create_flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *child; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							|  |  |  |   GFileOutputStream *outs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   child = g_file_get_child (parent, filename); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (child); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   error = NULL; | 
					
						
							|  |  |  |   outs = g_file_replace (child, NULL, FALSE, create_flags, NULL, &error); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (outs); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   error = NULL; | 
					
						
							| 
									
										
										
										
											2011-04-08 15:44:25 -04:00
										 |  |  |   g_output_stream_close (G_OUTPUT_STREAM (outs), NULL, &error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   g_object_unref (outs); | 
					
						
							|  |  |  |   return child; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-06 09:53:35 +00:00
										 |  |  | static GFile * | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | create_empty_dir (GFile * parent, const char *filename) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *child; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   child = g_file_get_child (parent, filename); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (child); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   error = NULL; | 
					
						
							|  |  |  |   res = g_file_make_directory (child, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   return child; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-06 09:53:35 +00:00
										 |  |  | static GFile * | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | create_symlink (GFile * parent, const char *filename, const char *points_to) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *child; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   child = g_file_get_child (parent, filename); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (child); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   error = NULL; | 
					
						
							|  |  |  |   res = g_file_make_symbolic_link (child, points_to, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   return child; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | test_create_structure (gconstpointer test_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *root; | 
					
						
							|  |  |  |   GFile *child; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							| 
									
										
										
										
											2019-10-30 15:11:36 +00:00
										 |  |  |   GError *error = NULL; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   GFileOutputStream *outs; | 
					
						
							|  |  |  |   GDataOutputStream *outds; | 
					
						
							| 
									
										
										
										
											2009-06-29 18:24:08 +02:00
										 |  |  |   guint i; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   struct StructureItem item; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (test_data); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   log ("\n  Going to create testing structure in '%s'...\n", | 
					
						
							|  |  |  |        (char *) test_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   root = g_file_new_for_commandline_arg ((char *) test_data); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /*  create root directory  */ | 
					
						
							| 
									
										
										
										
											2019-10-30 15:12:17 +00:00
										 |  |  |   g_file_make_directory (root, NULL, &error); | 
					
						
							|  |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /*  create any other items  */ | 
					
						
							|  |  |  |   for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       item = sample_struct[i]; | 
					
						
							|  |  |  |       if ((item.handle_special) | 
					
						
							|  |  |  | 	  || ((!posix_compat) | 
					
						
							|  |  |  | 	      && (item.file_type == G_FILE_TYPE_SYMBOLIC_LINK))) | 
					
						
							|  |  |  | 	continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       child = NULL; | 
					
						
							|  |  |  |       switch (item.file_type) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case G_FILE_TYPE_REGULAR: | 
					
						
							|  |  |  | 	  log ("    Creating file '%s'...\n", item.filename); | 
					
						
							|  |  |  | 	  child = create_empty_file (root, item.filename, item.create_flags); | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	case G_FILE_TYPE_DIRECTORY: | 
					
						
							|  |  |  | 	  log ("    Creating directory '%s'...\n", item.filename); | 
					
						
							|  |  |  | 	  child = create_empty_dir (root, item.filename); | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	case G_FILE_TYPE_SYMBOLIC_LINK: | 
					
						
							|  |  |  | 	  log ("    Creating symlink '%s' --> '%s'...\n", item.filename, | 
					
						
							|  |  |  | 	       item.link_to); | 
					
						
							|  |  |  | 	  child = create_symlink (root, item.filename, item.link_to); | 
					
						
							|  |  |  | 	  break; | 
					
						
							| 
									
										
										
										
											2009-06-29 18:24:08 +02:00
										 |  |  |         case G_FILE_TYPE_UNKNOWN: | 
					
						
							|  |  |  |         case G_FILE_TYPE_SPECIAL: | 
					
						
							|  |  |  |         case G_FILE_TYPE_SHORTCUT: | 
					
						
							|  |  |  |         case G_FILE_TYPE_MOUNTABLE: | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_nonnull (child); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if ((item.mode > 0) && (posix_compat)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  res = | 
					
						
							|  |  |  | 	    g_file_set_attribute_uint32 (child, G_FILE_ATTRIBUTE_UNIX_MODE, | 
					
						
							|  |  |  | 					 item.mode, | 
					
						
							|  |  |  | 					 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, | 
					
						
							|  |  |  | 					 NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	  g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	  g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-04 20:03:26 +01:00
										 |  |  |       if ((item.extra_flags & TEST_DOT_HIDDEN) == TEST_DOT_HIDDEN) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  gchar *dir, *path, *basename; | 
					
						
							|  |  |  | 	  FILE *f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  dir = g_path_get_dirname (item.filename); | 
					
						
							|  |  |  | 	  basename = g_path_get_basename (item.filename); | 
					
						
							|  |  |  | 	  path = g_build_filename (test_data, dir, ".hidden", NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  f = fopen (path, "a"); | 
					
						
							|  |  |  | 	  fprintf (f, "%s\n", basename); | 
					
						
							|  |  |  | 	  fclose (f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  g_free (dir); | 
					
						
							|  |  |  | 	  g_free (path); | 
					
						
							|  |  |  | 	  g_free (basename); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |       g_object_unref (child); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  create a pattern file  */ | 
					
						
							|  |  |  |   log ("    Creating pattern file..."); | 
					
						
							|  |  |  |   child = g_file_get_child (root, "pattern_file"); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (child); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   outs = | 
					
						
							|  |  |  |     g_file_replace (child, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (outs); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   outds = g_data_output_stream_new (G_OUTPUT_STREAM (outs)); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (outds); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   for (i = 0; i < PATTERN_FILE_SIZE; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:12:17 +00:00
										 |  |  |       g_data_output_stream_put_byte (outds, i % 256, NULL, &error); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |       g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-30 15:11:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:12:17 +00:00
										 |  |  |   g_output_stream_close (G_OUTPUT_STREAM (outs), NULL, &error); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   g_object_unref (outds); | 
					
						
							|  |  |  |   g_object_unref (outs); | 
					
						
							|  |  |  |   g_object_unref (child); | 
					
						
							|  |  |  |   log (" done.\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_object_unref (root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-06 09:53:35 +00:00
										 |  |  | static GFile * | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | file_exists (GFile * parent, const char *filename, gboolean * result) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *child; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (result) | 
					
						
							|  |  |  |     *result = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   child = g_file_get_child (parent, filename); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (child); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   res = g_file_query_exists (child, NULL); | 
					
						
							|  |  |  |   if (result) | 
					
						
							|  |  |  |     *result = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return child; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-06 09:53:35 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | test_attributes (struct StructureItem item, GFileInfo * info) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFileType ftype; | 
					
						
							|  |  |  |   guint32 mode; | 
					
						
							|  |  |  |   const char *name, *display_name, *edit_name, *copy_name, *symlink_target; | 
					
						
							|  |  |  |   gboolean utf8_valid; | 
					
						
							|  |  |  |   gboolean has_attr; | 
					
						
							|  |  |  |   gboolean is_symlink; | 
					
						
							| 
									
										
										
										
											2013-03-04 20:03:26 +01:00
										 |  |  |   gboolean is_hidden; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   gboolean can_read, can_write; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  standard::type  */ | 
					
						
							|  |  |  |   has_attr = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_TYPE); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (has_attr); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   ftype = g_file_info_get_file_type (info); | 
					
						
							|  |  |  |   g_assert_cmpint (ftype, !=, G_FILE_TYPE_UNKNOWN); | 
					
						
							|  |  |  |   g_assert_cmpint (ftype, ==, item.file_type); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  unix::mode  */ | 
					
						
							|  |  |  |   if ((item.mode > 0) && (posix_compat)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       mode = | 
					
						
							|  |  |  | 	g_file_info_get_attribute_uint32 (info, | 
					
						
							|  |  |  | 					  G_FILE_ATTRIBUTE_UNIX_MODE) & 0xFFF; | 
					
						
							|  |  |  |       g_assert_cmpint (mode, ==, item.mode); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  access::can-read  */ | 
					
						
							|  |  |  |   if (item.file_type != G_FILE_TYPE_SYMBOLIC_LINK) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       can_read = | 
					
						
							|  |  |  | 	g_file_info_get_attribute_boolean (info, | 
					
						
							|  |  |  | 					   G_FILE_ATTRIBUTE_ACCESS_CAN_READ); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_true (can_read); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  access::can-write  */ | 
					
						
							|  |  |  |   if ((write_test) && ((item.extra_flags & TEST_OVERWRITE) == TEST_OVERWRITE)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       can_write = | 
					
						
							|  |  |  | 	g_file_info_get_attribute_boolean (info, | 
					
						
							|  |  |  | 					   G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_true (can_write); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  standard::name  */ | 
					
						
							|  |  |  |   name = g_file_info_get_name (info); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (name); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /*  standard::display-name  */ | 
					
						
							|  |  |  |   display_name = g_file_info_get_display_name (info); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (display_name); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   utf8_valid = g_utf8_validate (display_name, -1, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (utf8_valid); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /*  standard::edit-name  */ | 
					
						
							|  |  |  |   edit_name = g_file_info_get_edit_name (info); | 
					
						
							|  |  |  |   if (edit_name) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       utf8_valid = g_utf8_validate (edit_name, -1, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_true (utf8_valid); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  standard::copy-name  */ | 
					
						
							|  |  |  |   copy_name = | 
					
						
							|  |  |  |     g_file_info_get_attribute_string (info, | 
					
						
							|  |  |  | 				      G_FILE_ATTRIBUTE_STANDARD_COPY_NAME); | 
					
						
							|  |  |  |   if (copy_name) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       utf8_valid = g_utf8_validate (copy_name, -1, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_true (utf8_valid); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  standard::is-symlink  */ | 
					
						
							|  |  |  |   if (posix_compat) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       is_symlink = g_file_info_get_is_symlink (info); | 
					
						
							|  |  |  |       g_assert_cmpint (is_symlink, ==, | 
					
						
							|  |  |  | 		       item.file_type == G_FILE_TYPE_SYMBOLIC_LINK); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  standard::symlink-target  */ | 
					
						
							|  |  |  |   if ((item.file_type == G_FILE_TYPE_SYMBOLIC_LINK) && (posix_compat)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       symlink_target = g_file_info_get_symlink_target (info); | 
					
						
							|  |  |  |       g_assert_cmpstr (symlink_target, ==, item.link_to); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-03-04 20:03:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /*  standard::is-hidden  */ | 
					
						
							|  |  |  |   if ((item.extra_flags & TEST_HIDDEN) == TEST_HIDDEN) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       is_hidden = | 
					
						
							|  |  |  | 	g_file_info_get_attribute_boolean (info, | 
					
						
							|  |  |  | 					   G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_true (is_hidden); | 
					
						
							| 
									
										
										
										
											2013-03-04 20:03:26 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-06-01 15:43:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* unix::is-mountpoint */ | 
					
						
							|  |  |  |   if (posix_compat) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       gboolean is_mountpoint = | 
					
						
							|  |  |  |         g_file_info_get_attribute_boolean (info, | 
					
						
							|  |  |  |                                       G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT); | 
					
						
							|  |  |  |       g_assert_false (is_mountpoint); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | test_initial_structure (gconstpointer test_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *root; | 
					
						
							|  |  |  |   GFile *child; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							|  |  |  |   GFileInputStream *ins; | 
					
						
							| 
									
										
										
										
											2009-06-29 18:24:08 +02:00
										 |  |  |   guint i; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   GFileInfo *info; | 
					
						
							|  |  |  |   guint32 size; | 
					
						
							|  |  |  |   guchar *buffer; | 
					
						
							|  |  |  |   gssize read, total_read; | 
					
						
							|  |  |  |   struct StructureItem item; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (test_data); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   log ("\n  Testing sample structure in '%s'...\n", (char *) test_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   root = g_file_new_for_commandline_arg ((char *) test_data); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   res = g_file_query_exists (root, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /*  test the structure  */ | 
					
						
							|  |  |  |   for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       item = sample_struct[i]; | 
					
						
							|  |  |  |       if (((!posix_compat) && (item.file_type == G_FILE_TYPE_SYMBOLIC_LINK)) | 
					
						
							|  |  |  | 	  || (item.handle_special)) | 
					
						
							|  |  |  | 	continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       log ("    Testing file '%s'...\n", item.filename); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       child = file_exists (root, item.filename, &res); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_nonnull (child); | 
					
						
							|  |  |  |       g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       error = NULL; | 
					
						
							|  |  |  |       info = | 
					
						
							|  |  |  | 	g_file_query_info (child, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, | 
					
						
							|  |  |  | 			   NULL, &error); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |       g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_nonnull (info); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       test_attributes (item, info); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       g_object_unref (child); | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  |       g_object_unref (info); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  read and test the pattern file  */ | 
					
						
							|  |  |  |   log ("    Testing pattern file...\n"); | 
					
						
							|  |  |  |   child = file_exists (root, "pattern_file", &res); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (child); | 
					
						
							|  |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   error = NULL; | 
					
						
							|  |  |  |   info = | 
					
						
							|  |  |  |     g_file_query_info (child, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, | 
					
						
							|  |  |  | 		       &error); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (info); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   size = g_file_info_get_size (info); | 
					
						
							|  |  |  |   g_assert_cmpint (size, ==, PATTERN_FILE_SIZE); | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  |   g_object_unref (info); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   error = NULL; | 
					
						
							|  |  |  |   ins = g_file_read (child, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (ins); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   buffer = g_malloc (PATTERN_FILE_SIZE); | 
					
						
							|  |  |  |   total_read = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   while (total_read < PATTERN_FILE_SIZE) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       error = NULL; | 
					
						
							|  |  |  |       read = | 
					
						
							|  |  |  | 	g_input_stream_read (G_INPUT_STREAM (ins), buffer + total_read, | 
					
						
							|  |  |  | 			     PATTERN_FILE_SIZE, NULL, &error); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |       g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |       total_read += read; | 
					
						
							| 
									
										
										
										
											2009-05-20 14:17:27 +02:00
										 |  |  |       log ("      read %"G_GSSIZE_FORMAT" bytes, total = %"G_GSSIZE_FORMAT" of %d.\n", | 
					
						
							|  |  |  | 	   read, total_read, PATTERN_FILE_SIZE); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   g_assert_cmpint (total_read, ==, PATTERN_FILE_SIZE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   error = NULL; | 
					
						
							|  |  |  |   res = g_input_stream_close (G_INPUT_STREAM (ins), NULL, &error); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; i < PATTERN_FILE_SIZE; i++) | 
					
						
							|  |  |  |     g_assert_cmpint (*(buffer + i), ==, i % 256); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_object_unref (ins); | 
					
						
							|  |  |  |   g_object_unref (child); | 
					
						
							|  |  |  |   g_free (buffer); | 
					
						
							|  |  |  |   g_object_unref (root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-06 09:53:35 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | traverse_recurse_dirs (GFile * parent, GFile * root) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							|  |  |  |   GFileEnumerator *enumerator; | 
					
						
							|  |  |  |   GFileInfo *info; | 
					
						
							|  |  |  |   GFile *descend; | 
					
						
							|  |  |  |   char *relative_path; | 
					
						
							| 
									
										
										
										
											2009-06-29 18:24:08 +02:00
										 |  |  |   guint i; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   gboolean found; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   error = NULL; | 
					
						
							|  |  |  |   enumerator = | 
					
						
							|  |  |  |     g_file_enumerate_children (parent, "*", | 
					
						
							|  |  |  | 			       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, | 
					
						
							|  |  |  | 			       &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (enumerator); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (g_file_enumerator_get_container (enumerator) == parent); | 
					
						
							| 
									
										
										
										
											2010-07-05 03:09:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   error = NULL; | 
					
						
							|  |  |  |   info = g_file_enumerator_next_file (enumerator, NULL, &error); | 
					
						
							|  |  |  |   while ((info) && (!error)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-12-12 04:49:28 -05:00
										 |  |  |       descend = g_file_enumerator_get_child (enumerator, info); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_nonnull (descend); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |       relative_path = g_file_get_relative_path (root, descend); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_nonnull (relative_path); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       found = FALSE; | 
					
						
							|  |  |  |       for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  if (strcmp (sample_struct[i].filename, relative_path) == 0) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      /*  test the attributes again  */ | 
					
						
							|  |  |  | 	      test_attributes (sample_struct[i], info); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	      found = TRUE; | 
					
						
							|  |  |  | 	      break; | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_true (found); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       log ("  Found file %s, relative to root: %s\n", | 
					
						
							|  |  |  | 	   g_file_info_get_display_name (info), relative_path); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) | 
					
						
							|  |  |  | 	traverse_recurse_dirs (descend, root); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       g_object_unref (descend); | 
					
						
							|  |  |  |       error = NULL; | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  |       g_object_unref (info); | 
					
						
							|  |  |  |       g_free (relative_path); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |       info = g_file_enumerator_next_file (enumerator, NULL, &error); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   error = NULL; | 
					
						
							|  |  |  |   res = g_file_enumerator_close (enumerator, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (g_file_enumerator_is_closed (enumerator)); | 
					
						
							| 
									
										
										
										
											2010-07-05 03:09:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   g_object_unref (enumerator); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | test_traverse_structure (gconstpointer test_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *root; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (test_data); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   log ("\n  Traversing through the sample structure in '%s'...\n", | 
					
						
							|  |  |  |        (char *) test_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   root = g_file_new_for_commandline_arg ((char *) test_data); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   res = g_file_query_exists (root, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   traverse_recurse_dirs (root, root); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_object_unref (root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | test_enumerate (gconstpointer test_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *root, *child; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							|  |  |  |   GFileEnumerator *enumerator; | 
					
						
							|  |  |  |   GFileInfo *info; | 
					
						
							| 
									
										
										
										
											2009-06-29 18:24:08 +02:00
										 |  |  |   guint i; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   struct StructureItem item; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (test_data); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   log ("\n  Test enumerate '%s'...\n", (char *) test_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   root = g_file_new_for_commandline_arg ((char *) test_data); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   res = g_file_query_exists (root, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       item = sample_struct[i]; | 
					
						
							|  |  |  |       if ((!posix_compat) && (item.file_type == G_FILE_TYPE_SYMBOLIC_LINK)) | 
					
						
							|  |  |  | 	continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (((item.extra_flags & TEST_NOT_EXISTS) == TEST_NOT_EXISTS) || | 
					
						
							|  |  |  | 	  (((item.extra_flags & TEST_NO_ACCESS) == TEST_NO_ACCESS) | 
					
						
							|  |  |  | 	   && posix_compat) | 
					
						
							|  |  |  | 	  || ((item.extra_flags & TEST_ENUMERATE_FILE) == | 
					
						
							|  |  |  | 	      TEST_ENUMERATE_FILE)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  log ("    Testing file '%s'\n", item.filename); | 
					
						
							|  |  |  | 	  child = g_file_get_child (root, item.filename); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	  g_assert_nonnull (child); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	  error = NULL; | 
					
						
							|  |  |  | 	  enumerator = | 
					
						
							|  |  |  | 	    g_file_enumerate_children (child, "*", | 
					
						
							|  |  |  | 				       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, | 
					
						
							|  |  |  | 				       NULL, &error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if ((item.extra_flags & TEST_NOT_EXISTS) == TEST_NOT_EXISTS) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_null (enumerator); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  if ((item.extra_flags & TEST_ENUMERATE_FILE) == TEST_ENUMERATE_FILE) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_null (enumerator); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  if ((item.extra_flags & TEST_NO_ACCESS) == TEST_NO_ACCESS) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_nonnull (enumerator); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	      error = NULL; | 
					
						
							|  |  |  | 	      info = g_file_enumerator_next_file (enumerator, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_null (info); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	      /*  no items should be found, no error should be logged  */ | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if (error) | 
					
						
							|  |  |  | 	    g_error_free (error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if (enumerator) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      error = NULL; | 
					
						
							|  |  |  | 	      res = g_file_enumerator_close (enumerator, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2010-07-05 03:09:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |               g_object_unref (enumerator); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  g_object_unref (child); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   g_object_unref (root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-06 09:53:35 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | do_copy_move (GFile * root, struct StructureItem item, const char *target_dir, | 
					
						
							|  |  |  | 	      enum StructureExtraFlags extra_flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *dst_dir, *src_file, *dst_file; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  | #ifdef G_OS_UNIX
 | 
					
						
							|  |  |  |   gboolean have_cap_dac_override = check_cap_dac_override (g_file_peek_path (root)); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   log ("    do_copy_move: '%s' --> '%s'\n", item.filename, target_dir); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   dst_dir = g_file_get_child (root, target_dir); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (dst_dir); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   src_file = g_file_get_child (root, item.filename); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (src_file); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   dst_file = g_file_get_child (dst_dir, item.filename); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (dst_file); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   error = NULL; | 
					
						
							|  |  |  |   if ((item.extra_flags & TEST_COPY) == TEST_COPY) | 
					
						
							|  |  |  |     res = | 
					
						
							|  |  |  |       g_file_copy (src_file, dst_file, | 
					
						
							|  |  |  | 		   G_FILE_COPY_NOFOLLOW_SYMLINKS | | 
					
						
							|  |  |  | 		   ((extra_flags == | 
					
						
							|  |  |  | 		     TEST_OVERWRITE) ? G_FILE_COPY_OVERWRITE : | 
					
						
							|  |  |  | 		    G_FILE_COPY_NONE), NULL, NULL, NULL, &error); | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     res = | 
					
						
							|  |  |  |       g_file_move (src_file, dst_file, G_FILE_COPY_NOFOLLOW_SYMLINKS, NULL, | 
					
						
							|  |  |  | 		   NULL, NULL, &error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (error) | 
					
						
							|  |  |  |     log ("       res = %d, error code %d = %s\n", res, error->code, | 
					
						
							|  |  |  | 	 error->message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  copying file/directory to itself (".")  */ | 
					
						
							|  |  |  |   if (((item.extra_flags & TEST_NOT_EXISTS) != TEST_NOT_EXISTS) && | 
					
						
							|  |  |  |       (extra_flags == TEST_ALREADY_EXISTS)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_false (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |       g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   /*  target file is a file, overwrite is not set  */ | 
					
						
							|  |  |  |   else if (((item.extra_flags & TEST_NOT_EXISTS) != TEST_NOT_EXISTS) && | 
					
						
							|  |  |  | 	   (extra_flags == TEST_TARGET_IS_FILE)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_false (res); | 
					
						
							| 
									
										
										
										
											2010-07-09 07:24:08 -04:00
										 |  |  |       g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   /*  source file is directory  */ | 
					
						
							|  |  |  |   else if ((item.extra_flags & TEST_COPY_ERROR_RECURSE) == | 
					
						
							|  |  |  | 	   TEST_COPY_ERROR_RECURSE) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_false (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |       g_assert_error (error, G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   /*  source or target path doesn't exist  */ | 
					
						
							|  |  |  |   else if (((item.extra_flags & TEST_NOT_EXISTS) == TEST_NOT_EXISTS) || | 
					
						
							|  |  |  | 	   (extra_flags == TEST_NOT_EXISTS)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_false (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |       g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   /*  source or target path permission denied  */ | 
					
						
							|  |  |  |   else if (((item.extra_flags & TEST_NO_ACCESS) == TEST_NO_ACCESS) || | 
					
						
							|  |  |  | 	   (extra_flags == TEST_NO_ACCESS)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-02-19 19:00:02 +01:00
										 |  |  |       /* This works for root, see bug #552912 */ | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  | #ifdef G_OS_UNIX
 | 
					
						
							|  |  |  |       if (have_cap_dac_override) | 
					
						
							| 
									
										
										
										
											2010-02-19 19:00:02 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  | 	  g_test_message ("Unable to exercise g_file_copy() or g_file_move() " | 
					
						
							|  |  |  | 	                  "failing with EACCES: we probably have " | 
					
						
							|  |  |  | 	                  "CAP_DAC_OVERRIDE"); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	  g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2010-02-19 19:00:02 +01:00
										 |  |  | 	  g_assert_no_error (error); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       else | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-02-19 19:00:02 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	  g_assert_false (res); | 
					
						
							| 
									
										
										
										
											2010-02-19 19:00:02 +01:00
										 |  |  | 	  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   /*  no error should be found, all exceptions defined above  */ | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |       g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (error) | 
					
						
							|  |  |  |     g_error_free (error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_object_unref (dst_dir); | 
					
						
							|  |  |  |   g_object_unref (src_file); | 
					
						
							|  |  |  |   g_object_unref (dst_file); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | test_copy_move (gconstpointer test_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *root; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							| 
									
										
										
										
											2009-06-29 18:24:08 +02:00
										 |  |  |   guint i; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   struct StructureItem item; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   log ("\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (test_data); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   root = g_file_new_for_commandline_arg ((char *) test_data); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   res = g_file_query_exists (root, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       item = sample_struct[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ((!posix_compat) && (item.file_type == G_FILE_TYPE_SYMBOLIC_LINK)) | 
					
						
							|  |  |  | 	continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (((item.extra_flags & TEST_COPY) == TEST_COPY) || | 
					
						
							|  |  |  | 	  ((item.extra_flags & TEST_MOVE) == TEST_MOVE)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  /*  test copy/move to a directory, expecting no errors if source files exist  */ | 
					
						
							|  |  |  | 	  do_copy_move (root, item, TEST_DIR_TARGET, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  /*  some files have been already moved so we can't count with them in the tests  */ | 
					
						
							|  |  |  | 	  if ((item.extra_flags & TEST_COPY) == TEST_COPY) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      /*  test overwrite for flagged files  */ | 
					
						
							|  |  |  | 	      if ((item.extra_flags & TEST_OVERWRITE) == TEST_OVERWRITE) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		  do_copy_move (root, item, TEST_DIR_TARGET, TEST_OVERWRITE); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	      /*  source = target, should return G_IO_ERROR_EXISTS  */ | 
					
						
							|  |  |  | 	      do_copy_move (root, item, ".", TEST_ALREADY_EXISTS); | 
					
						
							|  |  |  | 	      /*  target is file  */ | 
					
						
							|  |  |  | 	      do_copy_move (root, item, TEST_TARGET_FILE, | 
					
						
							|  |  |  | 			    TEST_TARGET_IS_FILE); | 
					
						
							|  |  |  | 	      /*  target path is invalid  */ | 
					
						
							|  |  |  | 	      do_copy_move (root, item, TEST_NAME_NOT_EXISTS, | 
					
						
							|  |  |  | 			    TEST_NOT_EXISTS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	      /*  tests on POSIX-compatible filesystems  */ | 
					
						
							|  |  |  | 	      if (posix_compat) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		  /*  target directory is not accessible (no execute flag)  */ | 
					
						
							|  |  |  | 		  do_copy_move (root, item, TEST_DIR_NO_ACCESS, | 
					
						
							|  |  |  | 				TEST_NO_ACCESS); | 
					
						
							|  |  |  | 		  /*  target directory is readonly  */ | 
					
						
							|  |  |  | 		  do_copy_move (root, item, TEST_DIR_NO_WRITE, | 
					
						
							|  |  |  | 				TEST_NO_ACCESS); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   g_object_unref (root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 15:43:27 +01:00
										 |  |  | /* Test that G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT is TRUE for / and for another
 | 
					
						
							|  |  |  |  * known mountpoint. The FALSE case is tested for many directories and files by | 
					
						
							|  |  |  |  * test_initial_structure(), via test_attributes(). | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | test_unix_is_mountpoint (gconstpointer data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const gchar *path = data; | 
					
						
							|  |  |  |   GFile *file = g_file_new_for_path (path); | 
					
						
							|  |  |  |   GFileInfo *info; | 
					
						
							|  |  |  |   gboolean is_mountpoint; | 
					
						
							|  |  |  |   GError *error = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   info = g_file_query_info (file, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT, | 
					
						
							|  |  |  |                             G_FILE_QUERY_INFO_NONE, NULL, &error); | 
					
						
							|  |  |  |   g_assert_no_error (error); | 
					
						
							|  |  |  |   g_assert_nonnull (info); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   is_mountpoint = | 
					
						
							|  |  |  |     g_file_info_get_attribute_boolean (info, | 
					
						
							|  |  |  |                                        G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT); | 
					
						
							|  |  |  |   g_assert_true (is_mountpoint); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_clear_object (&info); | 
					
						
							|  |  |  |   g_clear_object (&file); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | test_create (gconstpointer test_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *root, *child; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							| 
									
										
										
										
											2009-06-29 18:24:08 +02:00
										 |  |  |   guint i; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   struct StructureItem item; | 
					
						
							|  |  |  |   GFileOutputStream *os; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (test_data); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   log ("\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   root = g_file_new_for_commandline_arg ((char *) test_data); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   res = g_file_query_exists (root, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       item = sample_struct[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (((item.extra_flags & TEST_CREATE) == TEST_CREATE) || | 
					
						
							|  |  |  | 	  ((item.extra_flags & TEST_REPLACE) == TEST_REPLACE) || | 
					
						
							|  |  |  | 	  ((item.extra_flags & TEST_APPEND) == TEST_APPEND)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  log ("  test_create: '%s'\n", item.filename); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  child = g_file_get_child (root, item.filename); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	  g_assert_nonnull (child); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	  error = NULL; | 
					
						
							|  |  |  | 	  os = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if ((item.extra_flags & TEST_CREATE) == TEST_CREATE) | 
					
						
							|  |  |  | 	    os = g_file_create (child, item.create_flags, NULL, &error); | 
					
						
							|  |  |  | 	  else if ((item.extra_flags & TEST_REPLACE) == TEST_REPLACE) | 
					
						
							|  |  |  | 	    os = | 
					
						
							|  |  |  | 	      g_file_replace (child, NULL, TRUE, item.create_flags, NULL, | 
					
						
							|  |  |  | 			      &error); | 
					
						
							|  |  |  | 	  else if ((item.extra_flags & TEST_APPEND) == TEST_APPEND) | 
					
						
							|  |  |  | 	    os = g_file_append_to (child, item.create_flags, NULL, &error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if (error) | 
					
						
							|  |  |  | 	    log ("       error code %d = %s\n", error->code, error->message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if (((item.extra_flags & TEST_NOT_EXISTS) == 0) && | 
					
						
							|  |  |  | 	      ((item.extra_flags & TEST_CREATE) == TEST_CREATE)) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_null (os); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  else if (item.file_type == G_FILE_TYPE_DIRECTORY) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_null (os); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	      if ((item.extra_flags & TEST_CREATE) == TEST_CREATE) | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 		g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	      else | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 		g_assert_error (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  else | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_nonnull (os); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if (error) | 
					
						
							|  |  |  | 	    g_error_free (error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if (os) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      error = NULL; | 
					
						
							|  |  |  | 	      res = | 
					
						
							|  |  |  | 		g_output_stream_close (G_OUTPUT_STREAM (os), NULL, &error); | 
					
						
							|  |  |  | 	      if (error) | 
					
						
							|  |  |  | 		log ("         g_output_stream_close: error %d = %s\n", | 
					
						
							|  |  |  | 		     error->code, error->message); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  |               g_object_unref (os); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  g_object_unref (child); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   g_object_unref (root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | test_open (gconstpointer test_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *root, *child; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							| 
									
										
										
										
											2009-06-29 18:24:08 +02:00
										 |  |  |   guint i; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   struct StructureItem item; | 
					
						
							|  |  |  |   GFileInputStream *input_stream; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (test_data); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   log ("\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   root = g_file_new_for_commandline_arg ((char *) test_data); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   res = g_file_query_exists (root, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       item = sample_struct[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ((!posix_compat) && (item.file_type == G_FILE_TYPE_SYMBOLIC_LINK)) | 
					
						
							|  |  |  | 	continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ((item.extra_flags & TEST_OPEN) == TEST_OPEN) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  log ("  test_open: '%s'\n", item.filename); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  child = g_file_get_child (root, item.filename); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	  g_assert_nonnull (child); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	  error = NULL; | 
					
						
							|  |  |  | 	  input_stream = g_file_read (child, NULL, &error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if (((item.extra_flags & TEST_NOT_EXISTS) == TEST_NOT_EXISTS) || | 
					
						
							|  |  |  | 	      ((item.extra_flags & TEST_INVALID_SYMLINK) == | 
					
						
							|  |  |  | 	       TEST_INVALID_SYMLINK)) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_null (input_stream); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  else if (item.file_type == G_FILE_TYPE_DIRECTORY) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_null (input_stream); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  else | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_nonnull (input_stream); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if (error) | 
					
						
							|  |  |  | 	    g_error_free (error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if (input_stream) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      error = NULL; | 
					
						
							|  |  |  | 	      res = | 
					
						
							|  |  |  | 		g_input_stream_close (G_INPUT_STREAM (input_stream), NULL, | 
					
						
							|  |  |  | 				      &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  |               g_object_unref (input_stream); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  g_object_unref (child); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   g_object_unref (root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | test_delete (gconstpointer test_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *root; | 
					
						
							|  |  |  |   GFile *child; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							| 
									
										
										
										
											2009-06-29 18:24:08 +02:00
										 |  |  |   guint i; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   struct StructureItem item; | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  |   gchar *path; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (test_data); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   log ("\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   root = g_file_new_for_commandline_arg ((char *) test_data); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   res = g_file_query_exists (root, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; i < G_N_ELEMENTS (sample_struct); i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       item = sample_struct[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ((!posix_compat) && (item.file_type == G_FILE_TYPE_SYMBOLIC_LINK)) | 
					
						
							|  |  |  | 	continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (((item.extra_flags & TEST_DELETE_NORMAL) == TEST_DELETE_NORMAL) || | 
					
						
							|  |  |  | 	  ((item.extra_flags & TEST_DELETE_TRASH) == TEST_DELETE_TRASH)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	  child = file_exists (root, item.filename, &res); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	  g_assert_nonnull (child); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	  /*  we don't care about result here  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  |           path = g_file_get_path (child); | 
					
						
							|  |  |  | 	  log ("  Deleting %s, path = %s\n", item.filename, path); | 
					
						
							|  |  |  |           g_free (path); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	  error = NULL; | 
					
						
							|  |  |  | 	  if ((item.extra_flags & TEST_DELETE_NORMAL) == TEST_DELETE_NORMAL) | 
					
						
							|  |  |  | 	    res = g_file_delete (child, NULL, &error); | 
					
						
							|  |  |  | 	  else | 
					
						
							|  |  |  | 	    res = g_file_trash (child, NULL, &error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if ((item.extra_flags & TEST_DELETE_NON_EMPTY) == | 
					
						
							|  |  |  | 	      TEST_DELETE_NON_EMPTY) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_false (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_EMPTY); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  if ((item.extra_flags & TEST_DELETE_FAILURE) == TEST_DELETE_FAILURE) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_false (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	  if ((item.extra_flags & TEST_NOT_EXISTS) == TEST_NOT_EXISTS) | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  | 	      g_assert_false (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  | 	      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  if (error) | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      log ("      result = %d, error = %s\n", res, error->message); | 
					
						
							|  |  |  | 	      g_error_free (error); | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  g_object_unref (child); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   g_object_unref (root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  | static void | 
					
						
							|  |  |  | test_make_directory_with_parents (gconstpointer test_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *root, *child, *grandchild, *greatgrandchild; | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error = NULL; | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  | #ifdef G_OS_UNIX
 | 
					
						
							|  |  |  |   gboolean have_cap_dac_override = check_cap_dac_override (test_data); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (test_data); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   root = g_file_new_for_commandline_arg ((char *) test_data); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  |   res = g_file_query_exists (root, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   child = g_file_get_child (root, "a"); | 
					
						
							|  |  |  |   grandchild = g_file_get_child (child, "b"); | 
					
						
							|  |  |  |   greatgrandchild = g_file_get_child (grandchild, "c"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Check that we can successfully make directory hierarchies of
 | 
					
						
							|  |  |  |    * depth 1, 2, or 3 | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   res = g_file_make_directory_with_parents (child, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							|  |  |  |   res = g_file_query_exists (child, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   g_file_delete (child, NULL, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   res = g_file_make_directory_with_parents (grandchild, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							|  |  |  |   res = g_file_query_exists (grandchild, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   g_file_delete (grandchild, NULL, NULL); | 
					
						
							|  |  |  |   g_file_delete (child, NULL, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   res = g_file_make_directory_with_parents (greatgrandchild, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							|  |  |  |   res = g_file_query_exists (greatgrandchild, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   g_file_delete (greatgrandchild, NULL, NULL); | 
					
						
							|  |  |  |   g_file_delete (grandchild, NULL, NULL); | 
					
						
							|  |  |  |   g_file_delete (child, NULL, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Now test failure by trying to create a directory hierarchy
 | 
					
						
							|  |  |  |    * where a ancestor exists but is read-only | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* No obvious way to do this on Windows */ | 
					
						
							|  |  |  |   if (!posix_compat) | 
					
						
							|  |  |  |     goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  | #ifdef G_OS_UNIX
 | 
					
						
							|  |  |  |   /* Permissions are ignored if we have CAP_DAC_OVERRIDE or equivalent,
 | 
					
						
							|  |  |  |    * and in particular if we're root */ | 
					
						
							|  |  |  |   if (have_cap_dac_override) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       g_test_skip ("Unable to exercise g_file_make_directory_with_parents " | 
					
						
							|  |  |  |                    "failing with EACCES: we probably have " | 
					
						
							|  |  |  |                    "CAP_DAC_OVERRIDE"); | 
					
						
							|  |  |  |       goto out; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_file_make_directory (child, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   res = g_file_set_attribute_uint32 (child, | 
					
						
							|  |  |  |                                      G_FILE_ATTRIBUTE_UNIX_MODE, | 
					
						
							|  |  |  |                                      S_IRUSR + S_IXUSR, /* -r-x------ */ | 
					
						
							|  |  |  |                                      G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, | 
					
						
							|  |  |  |                                      NULL, NULL); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   res = g_file_make_directory_with_parents (grandchild, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_false (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  |   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED); | 
					
						
							|  |  |  |   g_clear_error (&error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   res = g_file_make_directory_with_parents (greatgrandchild, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_false (res); | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  |   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED); | 
					
						
							|  |  |  |   g_clear_error (&error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | out: | 
					
						
							|  |  |  |   g_object_unref (greatgrandchild); | 
					
						
							|  |  |  |   g_object_unref (grandchild); | 
					
						
							|  |  |  |   g_object_unref (child); | 
					
						
							|  |  |  |   g_object_unref (root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | cleanup_dir_recurse (GFile *parent, GFile *root) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   gboolean res; | 
					
						
							|  |  |  |   GError *error; | 
					
						
							|  |  |  |   GFileEnumerator *enumerator; | 
					
						
							|  |  |  |   GFileInfo *info; | 
					
						
							|  |  |  |   GFile *descend; | 
					
						
							|  |  |  |   char *relative_path; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   enumerator = | 
					
						
							|  |  |  |     g_file_enumerate_children (parent, "*", | 
					
						
							|  |  |  | 			       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  | 			       NULL); | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   if (! enumerator) | 
					
						
							|  |  |  | 	  return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   error = NULL; | 
					
						
							|  |  |  |   info = g_file_enumerator_next_file (enumerator, NULL, &error); | 
					
						
							|  |  |  |   while ((info) && (!error)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-12-12 04:49:28 -05:00
										 |  |  |       descend = g_file_enumerator_get_child (enumerator, info); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_nonnull (descend); | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |       relative_path = g_file_get_relative_path (root, descend); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_nonnull (relative_path); | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  |       g_free (relative_path); | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       log ("    deleting '%s'\n", g_file_info_get_display_name (info)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) | 
					
						
							|  |  |  |     	  cleanup_dir_recurse (descend, root); | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       error = NULL; | 
					
						
							|  |  |  |       res = g_file_delete (descend, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |       g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       g_object_unref (descend); | 
					
						
							|  |  |  |       error = NULL; | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  |       g_object_unref (info); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |       info = g_file_enumerator_next_file (enumerator, NULL, &error); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   error = NULL; | 
					
						
							|  |  |  |   res = g_file_enumerator_close (enumerator, NULL, &error); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_true (res); | 
					
						
							| 
									
										
										
										
											2008-09-27 01:43:43 +00:00
										 |  |  |   g_assert_no_error (error); | 
					
						
							| 
									
										
										
										
											2010-07-05 03:09:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   g_object_unref (enumerator); | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | prep_clean_structure (gconstpointer test_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GFile *root; | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (test_data); | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   log ("\n  Cleaning target testing structure in '%s'...\n", | 
					
						
							|  |  |  |        (char *) test_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   root = g_file_new_for_commandline_arg ((char *) test_data); | 
					
						
							| 
									
										
										
										
											2019-10-30 15:19:03 +00:00
										 |  |  |   g_assert_nonnull (root); | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   cleanup_dir_recurse (root, root); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-27 21:22:45 +00:00
										 |  |  |   g_file_delete (root, NULL, NULL); | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   g_object_unref (root); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | int | 
					
						
							|  |  |  | main (int argc, char *argv[]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   static gboolean only_create_struct; | 
					
						
							| 
									
										
										
										
											2009-06-29 18:24:08 +02:00
										 |  |  |   const char *target_path; | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   GError *error; | 
					
						
							|  |  |  |   GOptionContext *context; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static GOptionEntry cmd_entries[] = { | 
					
						
							|  |  |  |     {"read-write", 'w', 0, G_OPTION_ARG_NONE, &write_test, | 
					
						
							|  |  |  |      "Perform write tests (incl. structure creation)", NULL}, | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |     {"create-struct", 'c', 0, G_OPTION_ARG_NONE, &only_create_struct, | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |      "Only create testing structure (no tests)", NULL}, | 
					
						
							|  |  |  |     {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL}, | 
					
						
							|  |  |  |     {"posix", 'x', 0, G_OPTION_ARG_NONE, &posix_compat, | 
					
						
							|  |  |  |      "Test POSIX-specific features (unix permissions, symlinks)", NULL}, | 
					
						
							| 
									
										
										
										
											2021-05-13 20:16:46 +00:00
										 |  |  |     G_OPTION_ENTRY_NULL | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-19 19:00:02 +01:00
										 |  |  |   test_suite = FALSE; | 
					
						
							| 
									
										
										
										
											2008-02-12 10:06:01 +00:00
										 |  |  |   verbose = FALSE; | 
					
						
							|  |  |  |   write_test = FALSE; | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   only_create_struct = FALSE; | 
					
						
							| 
									
										
										
										
											2008-02-12 10:06:01 +00:00
										 |  |  |   target_path = NULL; | 
					
						
							|  |  |  |   posix_compat = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   /*  strip all gtester-specific args  */ | 
					
						
							|  |  |  |   g_test_init (&argc, &argv, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   /*  no extra parameters specified, assume we're executed from glib test suite  */  | 
					
						
							|  |  |  |   if (argc < 2) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-02-19 19:00:02 +01:00
										 |  |  | 	  test_suite = TRUE; | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  | 	  verbose = TRUE; | 
					
						
							|  |  |  | 	  write_test = TRUE; | 
					
						
							|  |  |  | 	  only_create_struct = FALSE; | 
					
						
							|  |  |  | 	  target_path = DEFAULT_TEST_DIR; | 
					
						
							|  |  |  | #ifdef G_PLATFORM_WIN32
 | 
					
						
							|  |  |  | 	  posix_compat = FALSE; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	  posix_compat = TRUE; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   /*  add trailing args  */ | 
					
						
							|  |  |  |   error = NULL; | 
					
						
							|  |  |  |   context = g_option_context_new ("target_path"); | 
					
						
							|  |  |  |   g_option_context_add_main_entries (context, cmd_entries, NULL); | 
					
						
							|  |  |  |   if (!g_option_context_parse (context, &argc, &argv, &error)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 17:03:00 +01:00
										 |  |  |       g_printerr ("option parsing failed: %s\n", error->message); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |       return g_test_run (); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   /*  remaining arg should is the target path; we don't care of the extra args here  */  | 
					
						
							|  |  |  |   if (argc >= 2) | 
					
						
							|  |  |  |     target_path = strdup (argv[1]); | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   if (! target_path)  | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 17:03:00 +01:00
										 |  |  |       g_printerr ("error: target path was not specified\n"); | 
					
						
							|  |  |  |       g_printerr ("%s", g_option_context_get_help (context, TRUE, NULL)); | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |       return g_test_run (); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-24 20:43:54 -04:00
										 |  |  |   g_option_context_free (context); | 
					
						
							| 
									
										
										
										
											2020-02-13 12:53:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   /*  Write test - clean target directory first  */ | 
					
						
							|  |  |  |   /*    this can be also considered as a test - enumerate + delete  */  | 
					
						
							|  |  |  |   if (write_test || only_create_struct) | 
					
						
							|  |  |  |     g_test_add_data_func ("/live-g-file/prep_clean_structure", target_path, | 
					
						
							|  |  |  |     	  	  prep_clean_structure); | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   /*  Write test - create new testing structure  */ | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   if (write_test || only_create_struct) | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     g_test_add_data_func ("/live-g-file/create_structure", target_path, | 
					
						
							|  |  |  | 			  test_create_structure); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  Read test - test the sample structure - expect defined attributes to be there  */ | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   if (!only_create_struct) | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     g_test_add_data_func ("/live-g-file/test_initial_structure", target_path, | 
					
						
							|  |  |  | 			  test_initial_structure); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  Read test - test traverse the structure - no special file should appear  */ | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   if (!only_create_struct) | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     g_test_add_data_func ("/live-g-file/test_traverse_structure", target_path, | 
					
						
							|  |  |  | 			  test_traverse_structure); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  Read test - enumerate  */ | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   if (!only_create_struct) | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     g_test_add_data_func ("/live-g-file/test_enumerate", target_path, | 
					
						
							|  |  |  | 			  test_enumerate); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  Read test - open (g_file_read())  */ | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   if (!only_create_struct) | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     g_test_add_data_func ("/live-g-file/test_open", target_path, test_open); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 15:43:27 +01:00
										 |  |  |   if (posix_compat) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       g_test_add_data_func ("/live-g-file/test_unix_is_mountpoint/sysroot", | 
					
						
							|  |  |  |                             "/", | 
					
						
							|  |  |  |                             test_unix_is_mountpoint); | 
					
						
							|  |  |  | #ifdef __linux__
 | 
					
						
							|  |  |  |       g_test_add_data_func ("/live-g-file/test_unix_is_mountpoint/proc", | 
					
						
							|  |  |  |                             "/proc", | 
					
						
							|  |  |  |                             test_unix_is_mountpoint); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   /*  Write test - create  */ | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   if (write_test && (!only_create_struct)) | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     g_test_add_data_func ("/live-g-file/test_create", target_path, | 
					
						
							|  |  |  | 			  test_create); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  Write test - copy, move  */ | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   if (write_test && (!only_create_struct)) | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     g_test_add_data_func ("/live-g-file/test_copy_move", target_path, | 
					
						
							|  |  |  | 			  test_copy_move); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*  Write test - delete, trash  */ | 
					
						
							| 
									
										
										
										
											2008-03-13 16:32:31 +00:00
										 |  |  |   if (write_test && (!only_create_struct)) | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |     g_test_add_data_func ("/live-g-file/test_delete", target_path, | 
					
						
							|  |  |  | 			  test_delete); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 12:57:43 -04:00
										 |  |  |   /*  Write test - make_directory_with_parents */ | 
					
						
							|  |  |  |   if (write_test && (!only_create_struct)) | 
					
						
							|  |  |  |     g_test_add_data_func ("/live-g-file/test_make_directory_with_parents", target_path, | 
					
						
							|  |  |  | 			  test_make_directory_with_parents); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-27 21:22:45 +00:00
										 |  |  |   if (write_test || only_create_struct) | 
					
						
							|  |  |  |     g_test_add_data_func ("/live-g-file/final_clean", target_path, | 
					
						
							|  |  |  |     	  	  prep_clean_structure); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  |   return g_test_run (); | 
					
						
							| 
									
										
										
										
											2008-05-27 21:22:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-06 13:52:07 +00:00
										 |  |  | } |