static void bookmark_file_changed_callback (NautilusFile *file, NautilusBookmark *bookmark) { GFile *location; g_assert (file == bookmark->details->file); DEBUG ("%s: file changed", nautilus_bookmark_get_name (bookmark)); location = nautilus_file_get_location (file); if (!g_file_equal (bookmark->details->location, location) && !nautilus_file_is_in_trash (file)) { DEBUG ("%s: file got moved", nautilus_bookmark_get_name (bookmark)); g_object_unref (bookmark->details->location); bookmark->details->location = g_object_ref (location); g_object_notify_by_pspec (G_OBJECT (bookmark), properties[PROP_LOCATION]); g_signal_emit (bookmark, signals[CONTENTS_CHANGED], 0); } g_object_unref (location); if (nautilus_file_is_gone (file) || nautilus_file_is_in_trash (file)) { /* The file we were monitoring has been trashed, deleted, * or moved in a way that we didn't notice. We should make * a spanking new NautilusFile object for this * location so if a new file appears in this place * we will notice. However, we can't immediately do so * because creating a new NautilusFile directly as a result * of noticing a file goes away may trigger i/o on that file * again, noticeing it is gone, leading to a loop. * So, the new NautilusFile is created when the bookmark * is used again. However, this is not really a problem, as * we don't want to change the icon or anything about the * bookmark just because its not there anymore. */ DEBUG ("%s: trashed", nautilus_bookmark_get_name (bookmark)); nautilus_bookmark_disconnect_file (bookmark); } else { bookmark_set_name_from_ready_file (bookmark, file); } }
gboolean nautilus_is_desktop_directory (GFile *dir) { if (!desktop_dir_changed_callback_installed) { eel_preferences_add_callback (NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR, desktop_dir_changed_callback, NULL); desktop_dir_changed_callback_installed = TRUE; } if (desktop_dir == NULL) { update_desktop_dir (); } return g_file_equal (dir, desktop_dir); }
static void nemo_window_update_split_view_actions_sensitivity (NemoWindow *window) { GtkActionGroup *action_group; GtkAction *action; gboolean have_multiple_panes; gboolean next_pane_is_in_same_location; GFile *active_pane_location; GFile *next_pane_location; NemoWindowPane *next_pane; NemoWindowSlot *active_slot; active_slot = nemo_window_get_active_slot (window); action_group = nemo_window_get_main_action_group (window); /* collect information */ have_multiple_panes = nemo_window_split_view_showing (window); if (active_slot != NULL) { active_pane_location = nemo_window_slot_get_location (active_slot); } else { active_pane_location = NULL; } next_pane = nemo_window_get_next_pane (window); if (next_pane && next_pane->active_slot) { next_pane_location = nemo_window_slot_get_location (next_pane->active_slot); next_pane_is_in_same_location = (active_pane_location && next_pane_location && g_file_equal (active_pane_location, next_pane_location)); } else { next_pane_location = NULL; next_pane_is_in_same_location = FALSE; } /* switch to next pane */ action = gtk_action_group_get_action (action_group, "SplitViewNextPane"); gtk_action_set_sensitive (action, have_multiple_panes); /* same location */ action = gtk_action_group_get_action (action_group, "SplitViewSameLocation"); gtk_action_set_sensitive (action, have_multiple_panes && !next_pane_is_in_same_location); /* clean up */ g_clear_object (&active_pane_location); g_clear_object (&next_pane_location); }
void gimp_icons_set_icon_theme (GFile *path) { gchar *icon_theme_name; GFile *search_path; g_return_if_fail (path == NULL || G_IS_FILE (path)); if (path) path = g_object_ref (path); else path = gimp_data_directory_file ("icons", GIMP_DEFAULT_ICON_THEME, NULL); search_path = g_file_get_parent (path); icon_theme_name = g_file_get_basename (path); if (gimp_icons_sanity_check (search_path, "hicolor") && gimp_icons_sanity_check (search_path, icon_theme_name)) { if (icon_theme_path) { /* this is an icon theme change */ gimp_icons_change_icon_theme (search_path); if (! g_file_equal (icon_theme_path, path)) { g_object_unref (icon_theme_path); icon_theme_path = g_object_ref (path); } g_object_set (gtk_settings_get_for_screen (gdk_screen_get_default ()), "gtk-icon-theme-name", icon_theme_name, NULL); } else { /* this is the first call upon initialization */ icon_theme_path = g_object_ref (path); } } g_free (icon_theme_name); g_object_unref (search_path); g_object_unref (path); }
gboolean nautilus_is_home_directory_file (GFile *dir, const char *filename) { char *dirname; static GFile *home_dir_dir = NULL; static char *home_dir_filename = NULL; if (home_dir_dir == NULL) { dirname = g_path_get_dirname (g_get_home_dir ()); home_dir_dir = g_file_new_for_path (dirname); g_free (dirname); home_dir_filename = g_path_get_basename (g_get_home_dir ()); } return (g_file_equal (dir, home_dir_dir) && strcmp (filename, home_dir_filename) == 0); }
static void xdg_dir_changed (NautilusFile *file, XdgDirEntry *dir) { GFile *location, *dir_location; char *path; location = nautilus_file_get_location (file); dir_location = g_file_new_for_path (dir->path); if (!g_file_equal (location, dir_location)) { path = g_file_get_path (location); if (path) { char *argv[5]; int i; g_free (dir->path); dir->path = path; i = 0; argv[i++] = "xdg-user-dirs-update"; argv[i++] = "--set"; argv[i++] = dir->type; argv[i++] = dir->path; argv[i++] = NULL; /* We do this sync, to avoid possible race-conditions if multiple dirs change at the same time. Its blocking the main thread, but these updates should be very rare and very fast. */ g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL, NULL, NULL); schedule_user_dirs_changed (); desktop_dir_changed (); } } g_object_unref (location); g_object_unref (dir_location); }
static void collect_directories_by_container (gpointer key, gpointer value, gpointer callback_data) { NautilusDirectory *directory; CollectData *collect_data; GFile *location; location = (GFile *) key; directory = NAUTILUS_DIRECTORY (value); collect_data = (CollectData *) callback_data; if (g_file_has_prefix (location, collect_data->container) || g_file_equal (collect_data->container, location)) { nautilus_directory_ref (directory); collect_data->directories = g_list_prepend (collect_data->directories, directory); } }
gboolean caja_is_desktop_directory (GFile *dir) { if (!desktop_dir_changed_callback_installed) { g_signal_connect_swapped (caja_preferences, "changed::" CAJA_PREFERENCES_DESKTOP_IS_HOME_DIR, G_CALLBACK(desktop_dir_changed_callback), NULL); desktop_dir_changed_callback_installed = TRUE; } if (desktop_dir == NULL) { update_desktop_dir (); } return g_file_equal (dir, desktop_dir); }
static void show_completed_file (GFile *hit, gboolean is_dir, const char *arg) { char *path, *cwd, *display, *t; GFile *cwd_f; GFile *home; if (g_file_is_native (hit)) { cwd = g_get_current_dir (); cwd_f = g_file_new_for_path (cwd); g_free (cwd); home = g_file_new_for_path (g_get_home_dir ()); if ((g_file_has_prefix (hit, home) || g_file_equal (hit, home)) && arg[0] == '~') { t = g_file_get_relative_path (home, hit); path = g_strconcat ("~", (t != NULL) ? "/": "", t, NULL); g_free (t); } else if (g_file_has_prefix (hit, cwd_f) && !g_path_is_absolute (arg)) path = g_file_get_relative_path (cwd_f, hit); else path = g_file_get_path (hit); g_object_unref (cwd_f); g_object_unref (home); display = shell_quote (path); g_free (path); } else display = g_file_get_uri (hit); g_print ("%s%s\n", display, (is_dir)?"/":""); g_free (display); }
gboolean nautilus_is_desktop_directory_file (GFile *dir, const char *file) { if (!desktop_dir_changed_callback_installed) { eel_preferences_add_callback (NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR, desktop_dir_changed_callback, NULL); desktop_dir_changed_callback_installed = TRUE; } if (desktop_dir == NULL) { update_desktop_dir (); } return (g_file_equal (dir, desktop_dir_dir) && strcmp (file, desktop_dir_filename) == 0); }
static gint project_item_equal_func (GFile *key, GObject *item) { g_assert (G_IS_FILE (key)); g_assert (IDE_IS_PROJECT_ITEM (item)); if (IDE_IS_PROJECT_FILE (item)) { GFile *file; file = ide_project_file_get_file (IDE_PROJECT_FILE (item)); g_assert (G_IS_FILE (file)); return g_file_equal (key, file); } return FALSE; }
gint gimp_file_compare (GFile *file1, GFile *file2) { if (g_file_equal (file1, file2)) { return 0; } else { gchar *uri1 = g_file_get_uri (file1); gchar *uri2 = g_file_get_uri (file2); gint result = strcmp (uri1, uri2); g_free (uri1); g_free (uri2); return result; } }
static void save_current_file (SaveData *save_data) { GthImageSaveFile *file; if (save_data->current == NULL) { save_completed (save_data); return; } file = save_data->current->data; _g_file_write_async (file->file, file->buffer, file->buffer_size, (g_file_equal (save_data->data->file_data->file, file->file) ? save_data->data->replace : TRUE), G_PRIORITY_DEFAULT, save_data->data->cancellable, file_saved_cb, save_data); }
PRIVATE void _remove_monitor_directory(GFile* f) { int wd = -1; GList* _keys = g_hash_table_get_keys(_monitor_table); GList* keys = _keys; while (keys != NULL) { GFile* test = g_hash_table_lookup(_monitor_table, keys->data); if (test != NULL && g_file_equal(f, test)) { wd = GPOINTER_TO_INT(keys->data); break; } keys = g_list_next(keys); } g_list_free(_keys); if (wd != -1) { inotify_rm_watch(_inotify_fd, wd); g_hash_table_remove(_monitor_table, GINT_TO_POINTER(wd)); } }
gboolean nautilus_file_selection_equal (GList *selection_a, GList *selection_b) { GList *al, *bl; gboolean selection_matches; if (selection_a == NULL || selection_b == NULL) { return (selection_a == selection_b); } if (g_list_length (selection_a) != g_list_length (selection_b)) { return FALSE; } selection_matches = TRUE; for (al = selection_a; al; al = al->next) { GFile *a_location = nautilus_file_get_location (NAUTILUS_FILE (al->data)); gboolean found = FALSE; for (bl = selection_b; bl; bl = bl->next) { GFile *b_location = nautilus_file_get_location (NAUTILUS_FILE (bl->data)); found = g_file_equal (b_location, a_location); g_object_unref (b_location); if (found) { break; } } selection_matches = found; g_object_unref (a_location); if (!selection_matches) { break; } } return selection_matches; }
static gboolean compare_to_file (gconstpointer a, gconstpointer b) { GFile *file = (GFile *)a; GObject *item = (GObject *)b; /* * Our key (the GFile) is always @a. * The potential match (maybe a GbProjectFile) is @b. * @b may also be NULL. */ g_assert (G_IS_FILE (file)); g_assert (!item || G_IS_OBJECT (item)); if (GB_IS_PROJECT_FILE (item)) return g_file_equal (file, gb_project_file_get_file (GB_PROJECT_FILE (item))); return FALSE; }
/** * ide_project_files_find_file: * @self: (in): A #IdeProjectFiles. * @file: A #GFile. * * Tries to locate an #IdeProjectFile matching the given file. * If @file is the working directory, @self is returned. * * Returns: (transfer none) (nullable): An #IdeProjectItem or %NULL. */ IdeProjectItem * ide_project_files_find_file (IdeProjectFiles *self, GFile *file) { IdeProjectItem *item; IdeContext *context; IdeVcs *vcs; GFile *workdir; gchar **parts; gchar *path; gsize i; g_return_val_if_fail (IDE_IS_PROJECT_FILES (self), NULL); g_return_val_if_fail (G_IS_FILE (file), NULL); item = IDE_PROJECT_ITEM (self); context = ide_object_get_context (IDE_OBJECT (self)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); if (g_file_equal (workdir, file)) return IDE_PROJECT_ITEM (self); path = g_file_get_relative_path (workdir, file); if (path == NULL) return NULL; parts = g_strsplit (path, G_DIR_SEPARATOR_S, 0); for (i = 0; parts [i]; i++) { if (!(item = ide_project_files_find_child (item, parts [i]))) break; } g_strfreev (parts); g_free (path); return item; }
static void update_remove_button (CcBackgroundPanel *panel, CcBackgroundItem *item) { CcBackgroundPanelPrivate *priv; const char *uri; char *cache_path; GFile *bg, *cache, *parent; gboolean sensitive = FALSE; priv = panel->priv; if (priv->current_source != SOURCE_PICTURES) goto bail; uri = cc_background_item_get_uri (item); if (uri == NULL) goto bail; bg = g_file_new_for_uri (uri); parent = g_file_get_parent (bg); if (parent == NULL) { g_object_unref (bg); goto bail; } cache_path = bg_pictures_source_get_cache_path (); cache = g_file_new_for_path (cache_path); g_free (cache_path); if (g_file_equal (parent, cache)) sensitive = TRUE; g_object_unref (parent); g_object_unref (cache); bail: gtk_widget_set_sensitive (WID ("remove_button"), sensitive); }
void logview_prefs_store_log (LogviewPrefs *prefs, GFile *file) { gchar **stored_logs; GFile *stored; gboolean found = FALSE; gint idx, old_size; g_assert (LOGVIEW_IS_PREFS (prefs)); g_assert (G_IS_FILE (file)); stored_logs = logview_prefs_get_stored_logfiles (prefs); for (idx = 0; stored_logs[idx] != NULL; idx++) { stored = g_file_parse_name (stored_logs[idx]); if (g_file_equal (file, stored)) { found = TRUE; } g_object_unref (stored); if (found) { break; } } if (!found) { old_size = g_strv_length (stored_logs); stored_logs = g_realloc (stored_logs, (old_size + 2) * sizeof (gchar *)); stored_logs[old_size] = g_file_get_parse_name (file); stored_logs[old_size + 1] = NULL; g_settings_set_strv (prefs->priv->logview_prefs, PREF_LOGFILES, (const gchar **) stored_logs); } g_strfreev (stored_logs); }
static NautilusWindowSlot * get_window_slot_for_location (NautilusApplication *application, GFile *location) { NautilusWindowSlot *slot; GList *l, *sl; slot = NULL; if (g_file_query_file_type (location, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY) { location = g_file_get_parent (location); } else { g_object_ref (location); } for (l = gtk_application_get_windows (GTK_APPLICATION (application)); l; l = l->next) { NautilusWindow *win = NAUTILUS_WINDOW (l->data); if (NAUTILUS_IS_DESKTOP_WINDOW (win)) continue; for (sl = nautilus_window_get_slots (win); sl; sl = sl->next) { NautilusWindowSlot *current = NAUTILUS_WINDOW_SLOT (sl->data); GFile *slot_location = nautilus_window_slot_get_location (current); if (g_file_equal (slot_location, location)) { slot = current; break; } } if (slot) { break; } } g_object_unref (location); return slot; }
static gchar * get_tracker_volume_name (const gchar *uri, const gchar *datasource) { gchar *source_name = NULL; GVolumeMonitor *volume_monitor; GList *mounts, *mount; GFile *file; if (uri != NULL && *uri != '\0') { volume_monitor = g_volume_monitor_get (); mounts = g_volume_monitor_get_mounts (volume_monitor); file = g_file_new_for_uri (uri); mount = mounts; while (mount != NULL) { GFile *m_file = g_mount_get_root (G_MOUNT (mount->data)); if (g_file_equal (m_file, file)) { gchar *m_name = g_mount_get_name (G_MOUNT (mount->data)); g_object_unref (G_OBJECT (m_file)); source_name = g_strdup_printf (_("Removable - %s"), m_name); g_free (m_name); break; } g_object_unref (G_OBJECT (m_file)); mount = mount->next; } g_list_free_full (mounts, g_object_unref); g_object_unref (G_OBJECT (file)); g_object_unref (G_OBJECT (volume_monitor)); } else { source_name = g_strdup (_("Local files")); } return source_name; }
static void cancel_tasks (TrackerController *controller, const gchar *subject, GFile *file) { TrackerControllerPrivate *priv; GList *elem; priv = controller->priv; for (elem = priv->ongoing_tasks; elem; elem = elem->next) { WritebackData *data = elem->data; if (g_strcmp0 (subject, data->subject) == 0) { g_message ("Cancelling not yet processed task ('%s')", data->subject); g_cancellable_cancel (data->cancellable); } if (file) { guint i; for (i = 0; i < data->results->len; i++) { GStrv row = g_ptr_array_index (data->results, i); if (row[0] != NULL) { GFile *task_file; task_file = g_file_new_for_uri (row[0]); if (g_file_equal (task_file, file) || g_file_has_prefix (task_file, file)) { /* Mount path contains some file being processed */ g_message ("Cancelling task ('%s')", row[0]); g_cancellable_cancel (data->cancellable); } g_object_unref (task_file); } } } } }
static int bookmark_list_get_uri_index (GList *list, GFile *location) { NemoBookmark *bookmark; GList *l; GFile *tmp; int i; g_return_val_if_fail (location != NULL, -1); for (i = 0, l = list; l != NULL; i++, l = l->next) { bookmark = NEMO_BOOKMARK (l->data); tmp = nemo_bookmark_get_location (bookmark); if (g_file_equal (location, tmp)) { g_object_unref (tmp); return i; } g_object_unref (tmp); } return -1; }
static gboolean switch_tracker_get_mapping (GValue *value, GVariant *variant, gpointer user_data) { Place *place = user_data; const gchar **locations; GFile *location; gint idx; gboolean found; found = FALSE; locations = g_variant_get_strv (variant, NULL); for (idx = 0; locations[idx] != NULL; idx++) { location = g_file_new_for_path (path_from_tracker_dir(locations[idx])); if ((found = g_file_equal (location, place->location))) break; } g_value_set_boolean (value, found); return TRUE; }
/* This is based on nautilus_compute_title_for_uri() and * nautilus_file_get_display_name_nocopy() */ char * shell_util_get_label_for_uri (const char *text_uri) { GFile *file; char *label; GFile *root; char *root_display; /* Here's what we do: * + x-nautilus-search: URI * + check if the URI is a mount * + if file: URI: * - check for known file: URI * - check for description of the GFile * - use display name of the GFile * + else: * - check for description of the GFile * - if the URI is a root: "root displayname" * - else: "root displayname: displayname" */ label = NULL; //FIXME: see nautilus_query_to_readable_string() to have a nice name if (g_str_has_prefix (text_uri, "x-nautilus-search:")) return g_strdup (_("Search")); file = g_file_new_for_uri (text_uri); label = shell_util_get_file_display_name_if_mount (file); if (label) { g_object_unref (file); return label; } if (g_str_has_prefix (text_uri, "file:")) { label = shell_util_get_file_display_for_common_files (file); if (!label) label = shell_util_get_file_description (file); if (!label) label = shell_util_get_file_display_name (file, TRUE); g_object_unref (file); return label; } label = shell_util_get_file_description (file); if (label) { g_object_unref (file); return label; } root = shell_util_get_gfile_root (file); root_display = shell_util_get_file_description (root); if (!root_display) root_display = shell_util_get_file_display_name (root, FALSE); if (!root_display) /* can happen with URI schemes non supported by gvfs */ root_display = g_file_get_uri_scheme (root); if (g_file_equal (file, root)) label = root_display; else { char *displayname; displayname = shell_util_get_file_display_name (file, TRUE); /* Translators: the first string is the name of a gvfs * method, and the second string is a path. For * example, "Trash: some-directory". It means that the * directory called "some-directory" is in the trash. */ label = g_strdup_printf (_("%1$s: %2$s"), root_display, displayname); g_free (root_display); g_free (displayname); } g_object_unref (root); g_object_unref (file); return label; }
/** * _gimp_color_profile_store_history_add: * @store: a #GimpColorProfileStore * @file: file of the profile to add (or %NULL) * @label: label to use for the profile (or %NULL) * @iter: a #GtkTreeIter * * Return value: %TRUE if the iter is valid and pointing to the item * * Since: 2.4 **/ gboolean _gimp_color_profile_store_history_add (GimpColorProfileStore *store, GFile *file, const gchar *label, GtkTreeIter *iter) { GtkTreeModel *model; gboolean iter_valid; gint max = -1; g_return_val_if_fail (GIMP_IS_COLOR_PROFILE_STORE (store), FALSE); g_return_val_if_fail (iter != NULL, FALSE); model = GTK_TREE_MODEL (store); for (iter_valid = gtk_tree_model_get_iter_first (model, iter); iter_valid; iter_valid = gtk_tree_model_iter_next (model, iter)) { gint type; gint index; GFile *this; gtk_tree_model_get (model, iter, GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type, GIMP_COLOR_PROFILE_STORE_INDEX, &index, -1); if (type != GIMP_COLOR_PROFILE_STORE_ITEM_FILE) continue; if (index > max) max = index; /* check if we found a filename match */ gtk_tree_model_get (model, iter, GIMP_COLOR_PROFILE_STORE_FILE, &this, -1); if ((this && file && g_file_equal (this, file)) || (! this && ! file)) { /* update the label */ if (label && *label) gtk_list_store_set (GTK_LIST_STORE (store), iter, GIMP_COLOR_PROFILE_STORE_LABEL, label, -1); if (this) g_object_unref (this); return TRUE; } if (this) g_object_unref (this); } if (! file) return FALSE; if (label && *label) { iter_valid = gimp_color_profile_store_history_insert (store, iter, file, label, ++max); } else { const gchar *utf8 = gimp_file_get_utf8_name (file); gchar *basename = g_path_get_basename (utf8); iter_valid = gimp_color_profile_store_history_insert (store, iter, file, basename, ++max); g_free (basename); } return iter_valid; }
gboolean ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError **error) { GOptionContext *context; glnx_unref_object OstreeRepo *repo = NULL; gboolean ret = FALSE; gboolean skip_commit = FALSE; g_autoptr(GFile) object_to_commit = NULL; g_autofree char *parent = NULL; g_autofree char *commit_checksum = NULL; g_autoptr(GFile) root = NULL; g_autoptr(GVariant) metadata = NULL; g_autoptr(GVariant) detached_metadata = NULL; glnx_unref_object OstreeMutableTree *mtree = NULL; g_autofree char *tree_type = NULL; g_autoptr(GHashTable) mode_adds = NULL; OstreeRepoCommitModifierFlags flags = 0; OstreeRepoCommitModifier *modifier = NULL; OstreeRepoTransactionStats stats; context = g_option_context_new ("[PATH] - Commit a new revision"); if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) goto out; if (opt_statoverride_file) { if (!parse_statoverride_file (&mode_adds, cancellable, error)) goto out; } if (opt_metadata_strings) { if (!parse_keyvalue_strings (opt_metadata_strings, &metadata, error)) goto out; } if (opt_detached_metadata_strings) { if (!parse_keyvalue_strings (opt_detached_metadata_strings, &detached_metadata, error)) goto out; } if (!opt_branch) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "A branch must be specified with --branch"); goto out; } if (opt_no_xattrs) flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS; if (opt_generate_sizes) flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES; if (opt_disable_fsync) ostree_repo_set_disable_fsync (repo, TRUE); if (flags != 0 || opt_owner_uid >= 0 || opt_owner_gid >= 0 || opt_statoverride_file != NULL || opt_no_xattrs) { modifier = ostree_repo_commit_modifier_new (flags, commit_filter, mode_adds, NULL); } if (!ostree_repo_resolve_rev (repo, opt_branch, TRUE, &parent, error)) goto out; if (!opt_subject && !opt_body) { if (!commit_editor (repo, opt_branch, &opt_subject, &opt_body, cancellable, error)) goto out; } if (!opt_subject) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "A subject must be specified with --subject"); goto out; } if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error)) goto out; if (opt_link_checkout_speedup && !ostree_repo_scan_hardlinks (repo, cancellable, error)) goto out; mtree = ostree_mutable_tree_new (); if (argc <= 1 && (opt_trees == NULL || opt_trees[0] == NULL)) { char *current_dir = g_get_current_dir (); object_to_commit = g_file_new_for_path (current_dir); g_free (current_dir); if (!ostree_repo_write_directory_to_mtree (repo, object_to_commit, mtree, modifier, cancellable, error)) goto out; } else if (opt_trees != NULL) { const char *const*tree_iter; const char *tree; const char *eq; for (tree_iter = (const char *const*)opt_trees; *tree_iter; tree_iter++) { tree = *tree_iter; eq = strchr (tree, '='); if (!eq) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Missing type in tree specification '%s'", tree); goto out; } g_free (tree_type); tree_type = g_strndup (tree, eq - tree); tree = eq + 1; g_clear_object (&object_to_commit); if (strcmp (tree_type, "dir") == 0) { object_to_commit = g_file_new_for_path (tree); if (!ostree_repo_write_directory_to_mtree (repo, object_to_commit, mtree, modifier, cancellable, error)) goto out; } else if (strcmp (tree_type, "tar") == 0) { object_to_commit = g_file_new_for_path (tree); if (!ostree_repo_write_archive_to_mtree (repo, object_to_commit, mtree, modifier, opt_tar_autocreate_parents, cancellable, error)) goto out; } else if (strcmp (tree_type, "ref") == 0) { if (!ostree_repo_read_commit (repo, tree, &object_to_commit, NULL, cancellable, error)) goto out; if (!ostree_repo_write_directory_to_mtree (repo, object_to_commit, mtree, modifier, cancellable, error)) goto out; } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid tree type specification '%s'", tree_type); goto out; } } } else { g_assert (argc > 1); object_to_commit = g_file_new_for_path (argv[1]); if (!ostree_repo_write_directory_to_mtree (repo, object_to_commit, mtree, modifier, cancellable, error)) goto out; } if (mode_adds && g_hash_table_size (mode_adds) > 0) { GHashTableIter hash_iter; gpointer key, value; g_hash_table_iter_init (&hash_iter, mode_adds); while (g_hash_table_iter_next (&hash_iter, &key, &value)) { g_printerr ("Unmatched statoverride path: %s\n", (char*)key); } g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unmatched statoverride paths"); goto out; } if (!ostree_repo_write_mtree (repo, mtree, &root, cancellable, error)) goto out; if (opt_skip_if_unchanged && parent) { g_autoptr(GFile) parent_root; if (!ostree_repo_read_commit (repo, parent, &parent_root, NULL, cancellable, error)) goto out; if (g_file_equal (root, parent_root)) skip_commit = TRUE; } if (!skip_commit) { gboolean update_summary; if (!ostree_repo_write_commit (repo, parent, opt_subject, opt_body, metadata, OSTREE_REPO_FILE (root), &commit_checksum, cancellable, error)) goto out; if (detached_metadata) { if (!ostree_repo_write_commit_detached_metadata (repo, commit_checksum, detached_metadata, cancellable, error)) goto out; } if (opt_key_ids) { char **iter; for (iter = opt_key_ids; iter && *iter; iter++) { const char *keyid = *iter; if (!ostree_repo_sign_commit (repo, commit_checksum, keyid, opt_gpg_homedir, cancellable, error)) goto out; } } ostree_repo_transaction_set_ref (repo, NULL, opt_branch, commit_checksum); if (!ostree_repo_commit_transaction (repo, &stats, cancellable, error)) goto out; /* The default for this option is FALSE, even for archive-z2 repos, * because ostree supports multiple processes committing to the same * repo (but different refs) concurrently, and in fact gnome-continuous * actually does this. In that context it's best to update the summary * explicitly instead of automatically here. */ if (!ot_keyfile_get_boolean_with_default (ostree_repo_get_config (repo), "core", "commit-update-summary", FALSE, &update_summary, error)) goto out; if (update_summary && !ostree_repo_regenerate_summary (repo, NULL, cancellable, error)) goto out; } else { commit_checksum = g_strdup (parent); } if (opt_table_output) { g_print ("Commit: %s\n", commit_checksum); g_print ("Metadata Total: %u\n", stats.metadata_objects_total); g_print ("Metadata Written: %u\n", stats.metadata_objects_written); g_print ("Content Total: %u\n", stats.content_objects_total); g_print ("Content Written: %u\n", stats.content_objects_written); g_print ("Content Bytes Written: %" G_GUINT64_FORMAT "\n", stats.content_bytes_written); } else { g_print ("%s\n", commit_checksum); } ret = TRUE; out: if (repo) ostree_repo_abort_transaction (repo, cancellable, NULL); if (context) g_option_context_free (context); if (modifier) ostree_repo_commit_modifier_unref (modifier); return ret; }
void watcher_event(GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { GFile *parent, *top, *tmp; gboolean depth = 1; watcher_t *watcher; watcher_event_t *event; if (!user_data) return; watcher = (watcher_t *) user_data; parent = g_file_new_for_path(watcher->path); event = (watcher_event_t *) g_new0(watcher_event_t, 1); event->watcher = watcher; event->file = g_file_get_path(file); event->rfile = g_file_get_relative_path(parent, file); if (!event->rfile) event->rfile = g_strdup(""); if (watcher->recursive) { for (top = g_file_dup(file), depth = 1; !g_file_equal(top, parent) && !g_file_has_parent(top, parent); top = tmp, depth++) { tmp = g_file_get_parent(top); g_object_unref(top); } g_object_unref(top); LOG_DEBUG("%s: file depth to watcher path is '%d'", watcher->name, depth); } g_object_unref(parent); LOG_DEBUG("%s: %s (event_type=%d, file=%s)", watcher->name, N_("watcher event received"), event_type, event->file); switch (event_type) { case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: { event->event = g_strdup(CONFIG_KEY_WATCHER_EVENT_CHANGING); break; } case G_FILE_MONITOR_EVENT_CHANGED: { event->event = g_strdup(CONFIG_KEY_WATCHER_EVENT_CHANGED); break; } case G_FILE_MONITOR_EVENT_CREATED: { event->event = g_strdup(CONFIG_KEY_WATCHER_EVENT_CREATED); break; } case G_FILE_MONITOR_EVENT_DELETED: { event->event = g_strdup(CONFIG_KEY_WATCHER_EVENT_DELETED); break; } case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED: { event->event = g_strdup(CONFIG_KEY_WATCHER_EVENT_ATTRIBUTECHANGED); break; } default: { LOG_DEBUG("%s: %s (event_type=%d)", watcher->name, N_("unknown event"), event_type); g_free(event->file); g_free(event->rfile); g_free(event); return; break; } } if ((event_type == G_FILE_MONITOR_EVENT_DELETED) && watcher->recursive && (g_strcmp0(event->file, watcher->path) != 0)) { watcher_remove_monitor_for_recursive_path(watcher, event->file); } if (!watcher_event_test(watcher, event)) { LOG_DEBUG("%s: %s (event=%s, file=%s)", watcher->name, N_("event ignored"), event->event, event->file); g_free(event->event); g_free(event->file); g_free(event->rfile); g_free(event); return; } if (event_type == G_FILE_MONITOR_EVENT_CREATED && watcher->recursive && g_file_test(event->file, G_FILE_TEST_IS_DIR) && (g_strcmp0(event->file, watcher->path) != 0)) { watcher_add_monitor_for_recursive_path(watcher, event->file, depth); } watcher_event_fired(watcher, event); g_free(event->event); g_free(event->file); g_free(event->rfile); g_free(event); }
static gboolean drop_urilist (PanelWidget *panel, PanelObjectPackType pack_type, int pack_index, char *urilist) { char **uris; GFile *home; GFile *trash; GFile *computer; GFile *network; gboolean success; int i; uris = g_uri_list_extract_uris (urilist); home = g_file_new_for_path (g_get_home_dir ()); trash = g_file_new_for_uri ("trash://"); computer = g_file_new_for_uri ("computer://"); network = g_file_new_for_uri ("network://"); success = TRUE; for (i = 0; uris[i]; i++) { GFile *file; GFileInfo *info; const char *uri; uri = uris[i]; if (g_ascii_strncasecmp (uri, "http:", strlen ("http:")) == 0 || g_ascii_strncasecmp (uri, "https:", strlen ("https:")) == 0 || g_ascii_strncasecmp (uri, "ftp:", strlen ("ftp:")) == 0 || g_ascii_strncasecmp (uri, "gopher:", strlen ("gopher:")) == 0 || g_ascii_strncasecmp (uri, "ghelp:", strlen ("ghelp:")) == 0 || g_ascii_strncasecmp (uri, "man:", strlen ("man:")) == 0 || g_ascii_strncasecmp (uri, "info:", strlen ("info:")) == 0) { /* FIXME: probably do this only on link, * in fact, on link always set up a link, * on copy do all the other stuff. Or something. */ if ( ! drop_url (panel, pack_type, pack_index, uri)) success = FALSE; continue; } if (g_ascii_strncasecmp (uri, "x-nautilus-desktop:", strlen ("x-nautilus-desktop:")) == 0) { success = drop_nautilus_desktop_uri (panel, pack_type, pack_index, uri); continue; } file = g_file_new_for_uri (uri); if (g_file_equal (home, file)) { success = drop_nautilus_desktop_uri (panel, pack_type, pack_index, "x-nautilus-desktop:///home"); g_object_unref (file); continue; } else if (g_file_equal (trash, file)) { success = drop_nautilus_desktop_uri (panel, pack_type, pack_index, "x-nautilus-desktop:///trash"); g_object_unref (file); continue; } else if (g_file_equal (computer, file)) { success = drop_nautilus_desktop_uri (panel, pack_type, pack_index, "x-nautilus-desktop:///computer"); g_object_unref (file); continue; } else if (g_file_equal (network, file)) { success = drop_nautilus_desktop_uri (panel, pack_type, pack_index, "x-nautilus-desktop:///network"); g_object_unref (file); continue; } info = g_file_query_info (file, "standard::type," "standard::content-type," "access::can-execute", G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info) { const char *mime; GFileType type; gboolean can_exec; mime = g_file_info_get_content_type (info); type = g_file_info_get_file_type (info); can_exec = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE); if (mime && g_str_has_prefix (mime, "image")) { if (!set_background_image_from_uri (panel->toplevel, uri)) success = FALSE; } else if (mime && (!strcmp (mime, "application/x-gnome-app-info") || !strcmp (mime, "application/x-desktop") || !strcmp (mime, "application/x-kde-app-info"))) { if (panel_layout_is_writable ()) panel_launcher_create (panel->toplevel, pack_type, pack_index, uri); else success = FALSE; } else if (type != G_FILE_TYPE_DIRECTORY && can_exec) { char *filename; filename = g_file_get_path (file); if (panel_layout_is_writable ()) /* executable and local, so add a * launcher with it */ ask_about_launcher (filename, panel, pack_type); else success = FALSE; g_free (filename); } else { if (!drop_uri (panel, pack_type, pack_index, uri, PANEL_ICON_UNKNOWN)) success = FALSE; } } else { if (!drop_uri (panel, pack_type, pack_index, uri, PANEL_ICON_UNKNOWN)) success = FALSE; } g_object_unref (info); g_object_unref (file); } g_object_unref (home); g_object_unref (trash); g_object_unref (computer); g_object_unref (network); g_strfreev (uris); return success; }
gboolean ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; GOptionContext *context; glnx_unref_object OstreeSysroot *sysroot = NULL; glnx_unref_object OstreeSysrootUpgrader *upgrader = NULL; g_autofree char *origin_remote = NULL; g_autofree char *origin_ref = NULL; g_autofree char *origin_refspec = NULL; g_autofree char *new_revision = NULL; g_autoptr(GFile) deployment_path = NULL; g_autoptr(GFile) deployment_origin_path = NULL; glnx_unref_object OstreeDeployment *merge_deployment = NULL; glnx_unref_object OstreeDeployment *new_deployment = NULL; GSConsole *console = NULL; gboolean in_status_line = FALSE; glnx_unref_object OstreeAsyncProgress *progress = NULL; gboolean changed; OstreeSysrootUpgraderPullFlags upgraderpullflags = 0; context = g_option_context_new ("Construct new tree from current origin and deploy it, if it changed"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, &sysroot, cancellable, error)) goto out; if (!ostree_sysroot_load (sysroot, cancellable, error)) goto out; upgrader = ostree_sysroot_upgrader_new_for_os (sysroot, opt_osname, cancellable, error); if (!upgrader) goto out; console = gs_console_get (); if (console) { gs_console_begin_status_line (console, "", NULL, NULL); in_status_line = TRUE; progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, console); } if (opt_allow_downgrade) upgraderpullflags |= OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER; if (!ostree_sysroot_upgrader_pull (upgrader, 0, upgraderpullflags, progress, &changed, cancellable, error)) goto out; if (in_status_line) { gs_console_end_status_line (console, NULL, NULL); in_status_line = FALSE; } if (!changed) { g_print ("No update available.\n"); } else { g_autoptr(GFile) real_sysroot = g_file_new_for_path ("/"); if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error)) goto out; if (opt_reboot && g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot)) { gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT, cancellable, error, "systemctl", "reboot", NULL); } } ret = TRUE; out: if (in_status_line) gs_console_end_status_line (console, NULL, NULL); if (context) g_option_context_free (context); return ret; }