| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | /*
 | 
					
						
							|  |  |  |  |  * Copyright 2015 Red Hat, Inc. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-05-18 09:12:45 +01:00
										 |  |  |  |  * SPDX-License-Identifier: LGPL-2.1-or-later | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							| 
									
										
										
										
											2017-05-27 18:21:30 +02:00
										 |  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * This library 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.  See the GNU | 
					
						
							|  |  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  |  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Author: Matthias Clasen <mclasen@redhat.com> | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include "config.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include <gio/gio.h>
 | 
					
						
							|  |  |  |  | #include <gi18n.h>
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  | #ifdef G_OS_UNIX
 | 
					
						
							|  |  |  |  | #include <gio/gunixmounts.h>
 | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  | #include "gio-tool.h"
 | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | static gboolean writable = FALSE; | 
					
						
							|  |  |  |  | static gboolean filesystem = FALSE; | 
					
						
							| 
									
										
										
										
											2022-01-19 16:58:53 +01:00
										 |  |  |  | static char *global_attributes = NULL; | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | static gboolean nofollow_symlinks = FALSE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static const GOptionEntry entries[] = { | 
					
						
							|  |  |  |  |   { "query-writable", 'w', 0, G_OPTION_ARG_NONE, &writable, N_("List writable attributes"), NULL }, | 
					
						
							|  |  |  |  |   { "filesystem", 'f', 0, G_OPTION_ARG_NONE, &filesystem, N_("Get file system info"), NULL }, | 
					
						
							| 
									
										
										
										
											2022-01-19 16:58:53 +01:00
										 |  |  |  |   { "attributes", 'a', 0, G_OPTION_ARG_STRING, &global_attributes, N_("The attributes to get"), N_("ATTRIBUTES") }, | 
					
						
							| 
									
										
										
										
											2016-09-30 05:47:15 +02:00
										 |  |  |  |   { "nofollow-symlinks", 'n', 0, G_OPTION_ARG_NONE, &nofollow_symlinks, N_("Don’t follow symbolic links"), NULL }, | 
					
						
							| 
									
										
										
										
											2021-04-28 23:26:34 +02:00
										 |  |  |  |   G_OPTION_ENTRY_NULL | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static char * | 
					
						
							|  |  |  |  | escape_string (const char *in) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GString *str; | 
					
						
							|  |  |  |  |   static char *hex_digits = "0123456789abcdef"; | 
					
						
							|  |  |  |  |   unsigned char c; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   str = g_string_new (""); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   while ((c = *in++) != 0) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       if (c >= 32 && c <= 126 && c != '\\') | 
					
						
							|  |  |  |  |         g_string_append_c (str, c); | 
					
						
							|  |  |  |  |       else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           g_string_append (str, "\\x"); | 
					
						
							|  |  |  |  |           g_string_append_c (str, hex_digits[(c >> 4) & 0xf]); | 
					
						
							|  |  |  |  |           g_string_append_c (str, hex_digits[c & 0xf]); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return g_string_free (str, FALSE); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-24 15:44:16 -05:00
										 |  |  |  | static char * | 
					
						
							|  |  |  |  | flatten_string (const char *in) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GString *str; | 
					
						
							|  |  |  |  |   unsigned char c; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   str = g_string_new (""); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   while ((c = *in++) != 0) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       switch (c) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |         case '\n': | 
					
						
							|  |  |  |  |           g_string_append (str, " ↵ "); | 
					
						
							|  |  |  |  |           break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         default: | 
					
						
							|  |  |  |  |           g_string_append_c (str, c); | 
					
						
							|  |  |  |  |           break; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return g_string_free (str, FALSE); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | show_attributes (GFileInfo *info) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   char **attributes; | 
					
						
							| 
									
										
										
										
											2022-07-24 15:44:16 -05:00
										 |  |  |  |   char *s, *flatten; | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |   int i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   attributes = g_file_info_list_attributes (info, NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_print (_("attributes:\n")); | 
					
						
							|  |  |  |  |   for (i = 0; attributes[i] != NULL; i++) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       /* list the icons in order rather than displaying "GThemedIcon:0x8df7200" */ | 
					
						
							|  |  |  |  |       if (strcmp (attributes[i], "standard::icon") == 0 || | 
					
						
							|  |  |  |  |           strcmp (attributes[i], "standard::symbolic-icon") == 0) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           GIcon *icon; | 
					
						
							|  |  |  |  |           int j; | 
					
						
							|  |  |  |  |           const char * const *names = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |           if (strcmp (attributes[i], "standard::symbolic-icon") == 0) | 
					
						
							|  |  |  |  |             icon = g_file_info_get_symbolic_icon (info); | 
					
						
							|  |  |  |  |           else | 
					
						
							|  |  |  |  |             icon = g_file_info_get_icon (info); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |           /* only look up names if GThemedIcon */ | 
					
						
							|  |  |  |  |           if (G_IS_THEMED_ICON(icon)) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |               names = g_themed_icon_get_names (G_THEMED_ICON (icon)); | 
					
						
							|  |  |  |  |               g_print ("  %s: ", attributes[i]); | 
					
						
							|  |  |  |  |               for (j = 0; names[j] != NULL; j++) | 
					
						
							|  |  |  |  |                 g_print ("%s%s", names[j], (names[j+1] == NULL)?"":", "); | 
					
						
							|  |  |  |  |               g_print ("\n"); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |           else | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |               s = g_file_info_get_attribute_as_string (info, attributes[i]); | 
					
						
							|  |  |  |  |               g_print ("  %s: %s\n", attributes[i], s); | 
					
						
							|  |  |  |  |               g_free (s); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |       else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           s = g_file_info_get_attribute_as_string (info, attributes[i]); | 
					
						
							| 
									
										
										
										
											2022-07-24 15:44:16 -05:00
										 |  |  |  |           flatten = flatten_string (s); | 
					
						
							|  |  |  |  |           g_print ("  %s: %s\n", attributes[i], flatten); | 
					
						
							|  |  |  |  |           g_free (flatten); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |           g_free (s); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   g_strfreev (attributes); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | show_info (GFile *file, GFileInfo *info) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   const char *name, *type; | 
					
						
							| 
									
										
										
										
											2022-07-24 15:44:16 -05:00
										 |  |  |  |   char *escaped, *uri, *flatten; | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |   goffset size; | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  |   const char *path; | 
					
						
							|  |  |  |  | #ifdef G_OS_UNIX
 | 
					
						
							|  |  |  |  |   GUnixMountEntry *entry; | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-21 10:29:29 +00:00
										 |  |  |  |   name = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME) ? | 
					
						
							|  |  |  |  |          g_file_info_get_display_name (info) : NULL; | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |   if (name) | 
					
						
							| 
									
										
										
										
											2022-07-24 15:44:16 -05:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       flatten = flatten_string (name); | 
					
						
							| 
									
										
										
										
											2023-08-12 20:01:36 +01:00
										 |  |  |  |       /* Translators: This is a noun and represents and attribute of a file */ | 
					
						
							| 
									
										
										
										
											2022-07-24 15:44:16 -05:00
										 |  |  |  |       g_print (_("display name: %s\n"), flatten); | 
					
						
							|  |  |  |  |       g_free (flatten); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-21 10:29:29 +00:00
										 |  |  |  |   name = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) ? | 
					
						
							|  |  |  |  |          g_file_info_get_edit_name (info) : NULL; | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |   if (name) | 
					
						
							| 
									
										
										
										
											2022-07-24 15:44:16 -05:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       flatten = flatten_string (name); | 
					
						
							| 
									
										
										
										
											2023-08-12 20:01:36 +01:00
										 |  |  |  |       /* Translators: This is a noun and represents and attribute of a file */ | 
					
						
							| 
									
										
										
										
											2023-03-21 11:31:00 +00:00
										 |  |  |  |       g_print (_("edit name: %s\n"), flatten); | 
					
						
							| 
									
										
										
										
											2022-07-24 15:44:16 -05:00
										 |  |  |  |       g_free (flatten); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-01 17:01:50 +00:00
										 |  |  |  |   name = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_NAME) ? | 
					
						
							|  |  |  |  |          g_file_info_get_name (info) : NULL; | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |   if (name) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       escaped = escape_string (name); | 
					
						
							|  |  |  |  |       g_print (_("name: %s\n"), escaped); | 
					
						
							|  |  |  |  |       g_free (escaped); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_TYPE)) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       type = file_type_to_string (g_file_info_get_file_type (info)); | 
					
						
							|  |  |  |  |       g_print (_("type: %s\n"), type); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       size = g_file_info_get_size (info); | 
					
						
							|  |  |  |  |       g_print (_("size: ")); | 
					
						
							|  |  |  |  |       g_print (" %"G_GUINT64_FORMAT"\n", (guint64)size); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-08 10:28:35 +00:00
										 |  |  |  |   if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) && | 
					
						
							|  |  |  |  |       g_file_info_get_is_hidden (info)) | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |     g_print (_("hidden\n")); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   uri = g_file_get_uri (file); | 
					
						
							|  |  |  |  |   g_print (_("uri: %s\n"), uri); | 
					
						
							|  |  |  |  |   g_free (uri); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  |   path = g_file_peek_path (file); | 
					
						
							|  |  |  |  |   if (path) | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-24 15:44:16 -05:00
										 |  |  |  |       flatten = flatten_string (path); | 
					
						
							|  |  |  |  |       g_print (_("local path: %s\n"), flatten); | 
					
						
							|  |  |  |  |       free (flatten); | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | #ifdef G_OS_UNIX
 | 
					
						
							| 
									
										
										
										
											2024-10-18 10:31:12 +01:00
										 |  |  |  |       entry = g_unix_mount_entry_at (path, NULL); | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  |       if (entry == NULL) | 
					
						
							| 
									
										
										
										
											2024-10-18 10:31:12 +01:00
										 |  |  |  |         entry = g_unix_mount_entry_for (path, NULL); | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  |       if (entry != NULL) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           gchar *device; | 
					
						
							| 
									
										
										
										
											2020-02-03 11:50:32 +01:00
										 |  |  |  |           const gchar *root; | 
					
						
							|  |  |  |  |           gchar *root_string = NULL; | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  |           gchar *mount; | 
					
						
							|  |  |  |  |           gchar *fs; | 
					
						
							| 
									
										
										
										
											2020-12-10 13:22:45 +01:00
										 |  |  |  |           const gchar *options; | 
					
						
							|  |  |  |  |           gchar *options_string = NULL; | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-18 10:31:12 +01:00
										 |  |  |  |           device = g_strescape (g_unix_mount_entry_get_device_path (entry), NULL); | 
					
						
							|  |  |  |  |           root = g_unix_mount_entry_get_root_path (entry); | 
					
						
							| 
									
										
										
										
											2020-02-03 11:50:32 +01:00
										 |  |  |  |           if (root != NULL && g_strcmp0 (root, "/") != 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |               escaped = g_strescape (root, NULL); | 
					
						
							|  |  |  |  |               root_string = g_strconcat ("[", escaped, "]", NULL); | 
					
						
							|  |  |  |  |               g_free (escaped); | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-10-18 10:31:12 +01:00
										 |  |  |  |           mount = g_strescape (g_unix_mount_entry_get_mount_path (entry), NULL); | 
					
						
							|  |  |  |  |           fs = g_strescape (g_unix_mount_entry_get_fs_type (entry), NULL); | 
					
						
							| 
									
										
										
										
											2020-12-10 13:22:45 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-18 10:31:12 +01:00
										 |  |  |  |           options = g_unix_mount_entry_get_options (entry); | 
					
						
							| 
									
										
										
										
											2020-12-10 13:22:45 +01:00
										 |  |  |  |           if (options != NULL) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |               options_string = g_strescape (options, NULL); | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 11:50:32 +01:00
										 |  |  |  |           g_print (_("unix mount: %s%s %s %s %s\n"), device, | 
					
						
							| 
									
										
										
										
											2020-12-10 13:22:45 +01:00
										 |  |  |  |                    root_string ? root_string : "", mount, fs, | 
					
						
							|  |  |  |  |                    options_string ? options_string : ""); | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |           g_free (device); | 
					
						
							| 
									
										
										
										
											2020-02-03 11:50:32 +01:00
										 |  |  |  |           g_free (root_string); | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  |           g_free (mount); | 
					
						
							|  |  |  |  |           g_free (fs); | 
					
						
							| 
									
										
										
										
											2020-12-10 13:22:45 +01:00
										 |  |  |  |           g_free (options_string); | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-18 10:31:12 +01:00
										 |  |  |  |           g_unix_mount_entry_free (entry); | 
					
						
							| 
									
										
										
										
											2019-01-08 13:43:18 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |   show_attributes (info); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static gboolean | 
					
						
							|  |  |  |  | query_info (GFile *file) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFileQueryInfoFlags flags; | 
					
						
							|  |  |  |  |   GFileInfo *info; | 
					
						
							|  |  |  |  |   GError *error; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (file == NULL) | 
					
						
							|  |  |  |  |     return FALSE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-19 16:58:53 +01:00
										 |  |  |  |   if (global_attributes == NULL) | 
					
						
							|  |  |  |  |     global_attributes = "*"; | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   flags = 0; | 
					
						
							|  |  |  |  |   if (nofollow_symlinks) | 
					
						
							|  |  |  |  |     flags |= G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   error = NULL; | 
					
						
							|  |  |  |  |   if (filesystem) | 
					
						
							| 
									
										
										
										
											2022-01-19 16:58:53 +01:00
										 |  |  |  |     info = g_file_query_filesystem_info (file, global_attributes, NULL, &error); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |   else | 
					
						
							| 
									
										
										
										
											2022-01-19 16:58:53 +01:00
										 |  |  |  |     info = g_file_query_info (file, global_attributes, flags, NULL, &error); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (info == NULL) | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-12-16 14:32:29 +01:00
										 |  |  |  |       print_file_error (file, error->message); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |       g_error_free (error); | 
					
						
							|  |  |  |  |       return FALSE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (filesystem) | 
					
						
							|  |  |  |  |     show_attributes (info); | 
					
						
							|  |  |  |  |   else | 
					
						
							|  |  |  |  |     show_info (file, info); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_object_unref (info); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return TRUE; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static gboolean | 
					
						
							|  |  |  |  | get_writable_info (GFile *file) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFileAttributeInfoList *list; | 
					
						
							|  |  |  |  |   GError *error; | 
					
						
							|  |  |  |  |   int i; | 
					
						
							|  |  |  |  |   char *flags; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (file == NULL) | 
					
						
							|  |  |  |  |     return FALSE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   error = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   list = g_file_query_settable_attributes (file, NULL, &error); | 
					
						
							|  |  |  |  |   if (list == NULL) | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-12-16 14:32:29 +01:00
										 |  |  |  |       print_file_error (file, error->message); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |       g_error_free (error); | 
					
						
							|  |  |  |  |       return FALSE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-16 14:36:53 +01:00
										 |  |  |  |   if (list->n_infos > 0) | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-12-16 14:36:53 +01:00
										 |  |  |  |       g_print (_("Settable attributes:\n")); | 
					
						
							|  |  |  |  |       for (i = 0; i < list->n_infos; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           flags = attribute_flags_to_string (list->infos[i].flags); | 
					
						
							|  |  |  |  |           g_print (" %s (%s%s%s)\n", | 
					
						
							|  |  |  |  |                    list->infos[i].name, | 
					
						
							|  |  |  |  |                    attribute_type_to_string (list->infos[i].type), | 
					
						
							|  |  |  |  |                    (*flags != 0)?", ":"", flags); | 
					
						
							|  |  |  |  |           g_free (flags); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_file_attribute_info_list_unref (list); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   list = g_file_query_writable_namespaces (file, NULL, &error); | 
					
						
							|  |  |  |  |   if (list == NULL) | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-12-16 14:32:29 +01:00
										 |  |  |  |       print_file_error (file, error->message); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |       g_error_free (error); | 
					
						
							|  |  |  |  |       return FALSE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (list->n_infos > 0) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       g_print (_("Writable attribute namespaces:\n")); | 
					
						
							|  |  |  |  |       for (i = 0; i < list->n_infos; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           flags = attribute_flags_to_string (list->infos[i].flags); | 
					
						
							|  |  |  |  |           g_print (" %s (%s%s%s)\n", | 
					
						
							|  |  |  |  |                    list->infos[i].name, | 
					
						
							|  |  |  |  |                    attribute_type_to_string (list->infos[i].type), | 
					
						
							|  |  |  |  |                    (*flags != 0)?", ":"", flags); | 
					
						
							| 
									
										
										
										
											2016-12-16 14:35:55 +01:00
										 |  |  |  |           g_free (flags); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_file_attribute_info_list_unref (list); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return TRUE; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | int | 
					
						
							|  |  |  |  | handle_info (int argc, char *argv[], gboolean do_help) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GOptionContext *context; | 
					
						
							|  |  |  |  |   gchar *param; | 
					
						
							|  |  |  |  |   GError *error = NULL; | 
					
						
							|  |  |  |  |   gboolean res; | 
					
						
							|  |  |  |  |   gint i; | 
					
						
							|  |  |  |  |   GFile *file; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_set_prgname ("gio info"); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   /* Translators: commandline placeholder */ | 
					
						
							| 
									
										
										
										
											2018-05-25 16:59:30 +02:00
										 |  |  |  |   param = g_strdup_printf ("%s…", _("LOCATION")); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |   context = g_option_context_new (param); | 
					
						
							|  |  |  |  |   g_free (param); | 
					
						
							|  |  |  |  |   g_option_context_set_help_enabled (context, FALSE); | 
					
						
							|  |  |  |  |   g_option_context_set_summary (context, | 
					
						
							|  |  |  |  |       _("Show information about locations.")); | 
					
						
							|  |  |  |  |   g_option_context_set_description (context, | 
					
						
							|  |  |  |  |       _("gio info is similar to the traditional ls utility, but using GIO\n" | 
					
						
							|  |  |  |  |         "locations instead of local files: for example, you can use something\n" | 
					
						
							|  |  |  |  |         "like smb://server/resource/file.txt as location. File attributes can\n" | 
					
						
							|  |  |  |  |         "be specified with their GIO name, e.g. standard::icon, or just by\n" | 
					
						
							| 
									
										
										
										
											2016-09-30 05:47:15 +02:00
										 |  |  |  |         "namespace, e.g. unix, or by “*”, which matches all attributes")); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (do_help) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       show_help (context, NULL); | 
					
						
							| 
									
										
										
										
											2016-12-19 12:11:13 +01:00
										 |  |  |  |       g_option_context_free (context); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |       return 0; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (!g_option_context_parse (context, &argc, &argv, &error)) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       show_help (context, error->message); | 
					
						
							|  |  |  |  |       g_error_free (error); | 
					
						
							| 
									
										
										
										
											2016-12-19 12:11:13 +01:00
										 |  |  |  |       g_option_context_free (context); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |       return 1; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (argc < 2) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       show_help (context, _("No locations given")); | 
					
						
							| 
									
										
										
										
											2016-12-19 12:11:13 +01:00
										 |  |  |  |       g_option_context_free (context); | 
					
						
							| 
									
										
										
										
											2015-05-25 13:29:02 -04:00
										 |  |  |  |       return 1; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_option_context_free (context); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   res = TRUE; | 
					
						
							|  |  |  |  |   for (i = 1; i < argc; i++) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       file = g_file_new_for_commandline_arg (argv[i]); | 
					
						
							|  |  |  |  |       if (writable) | 
					
						
							|  |  |  |  |         res &= get_writable_info (file); | 
					
						
							|  |  |  |  |       else | 
					
						
							|  |  |  |  |         res &= query_info (file); | 
					
						
							|  |  |  |  |       g_object_unref (file); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return res ? 0 : 2; | 
					
						
							|  |  |  |  | } |