gboolean apply_patch (const gchar *path, GFile *source_dir, guint strip_components, GError **error) { g_autoptr(GFile) patchfile = NULL; g_autofree char *patch_path = NULL; g_autofree char *strip_components_str = NULL; gboolean use_git = FALSE; patchfile = g_file_resolve_relative_path (source_dir, path); if (patchfile == NULL) return FALSE; strip_components_str = g_strdup_printf ("-p%u", strip_components); patch_path = g_file_get_path (patchfile); if (!patch (source_dir, use_git, patch_path, error, strip_components_str, NULL)) return FALSE; return TRUE; }
static gchar * ide_compile_commands_resolve (IdeCompileCommands *self, const CompileInfo *info, const gchar *path) { g_autoptr(GFile) file = NULL; g_assert (IDE_IS_COMPILE_COMMANDS (self)); g_assert (info != NULL); if (path == NULL) return NULL; if (g_path_is_absolute (path)) return g_strdup (path); file = g_file_resolve_relative_path (info->directory, path); if (file != NULL) return g_file_get_path (file); return NULL; }
/** * rb_uri_append_path: * @uri: the URI to append to * @path: the path fragment to append * * Creates a new URI consisting of @path appended to @uri. * * Return value: new URI, must be freed by caller */ char* rb_uri_append_path (const char *uri, const char *path) { GFile *file; GFile *relfile; char *result; /* all paths we get are relative, so skip * leading slashes. */ while (path[0] == '/') { path++; } file = g_file_new_for_uri (uri); relfile = g_file_resolve_relative_path (file, path); result = g_file_get_uri (relfile); g_object_unref (relfile); g_object_unref (file); return result; }
static GList * _get_trash_dirs_for_mount (GMount *mount) { GFile *root; GFile *trash; char *relpath; GList *list; root = g_mount_get_root (mount); if (root == NULL) return NULL; list = NULL; if (g_file_is_native (root)) { relpath = g_strdup_printf (".Trash/%d", getuid ()); trash = g_file_resolve_relative_path (root, relpath); g_free (relpath); list = g_list_prepend (list, g_file_get_child (trash, "files")); list = g_list_prepend (list, g_file_get_child (trash, "info")); g_object_unref (trash); relpath = g_strdup_printf (".Trash-%d", getuid ()); trash = g_file_get_child (root, relpath); g_free (relpath); list = g_list_prepend (list, g_file_get_child (trash, "files")); list = g_list_prepend (list, g_file_get_child (trash, "info")); g_object_unref (trash); } g_object_unref (root); return list; }
/* Return build path from a source directory */ static GFile * build_file_from_directory (BasicAutotoolsPlugin *plugin, GFile *directory) { GFile *build_file; if ((plugin->project_root_dir == NULL) || (plugin->project_build_dir == NULL)) { /* No change if there is no project or no build directory */ build_file = g_object_ref (directory); } else if (g_file_has_prefix (directory, plugin->project_build_dir) || g_file_equal (directory, plugin->project_build_dir)) { /* No change, already in build directory */ build_file = g_object_ref (directory); } else if (g_file_equal (directory, plugin->project_root_dir)) { /* Use build directory instead of source directory */ build_file = g_object_ref (plugin->project_build_dir); } else if (g_file_has_prefix (directory, plugin->project_root_dir)) { /* Get corresponding file in build directory */ gchar *relative; relative = g_file_get_relative_path (plugin->project_root_dir, directory); build_file = g_file_resolve_relative_path (plugin->project_build_dir, relative); g_free (relative); } else { /* File outside the project directory */ build_file = g_object_ref (directory); } return build_file; }
static GFile * get_source_file (BuilderSourceFile *self, BuilderContext *context, gboolean *is_local, gboolean *is_inline, GError **error) { GFile *base_dir = builder_context_get_base_dir (context); if (self->url != NULL && self->url[0] != 0) { *is_local = FALSE; return get_download_location (self, is_inline, context, error); } if (self->path != NULL && self->path[0] != 0) { *is_local = TRUE; return g_file_resolve_relative_path (base_dir, self->path); } g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "source file path or url not specified"); return NULL; }
static char * get_url (BuilderSourceGit *self, BuilderContext *context, GError **error) { g_autofree char *scheme = NULL; if (self->url == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "URL not specified"); return NULL; } scheme = g_uri_parse_scheme (self->url); if (scheme == NULL) { g_autoptr(GFile) repo = g_file_resolve_relative_path (builder_context_get_base_dir (context), self->url); return g_file_get_uri (repo); } return g_strdup (self->url); }
static gboolean resolve_refspec (OstreeRepo *self, const char *remote, const char *ref, gboolean allow_noent, char **out_rev, GError **error) { gboolean ret = FALSE; __attribute__((unused)) GCancellable *cancellable = NULL; GError *temp_error = NULL; g_autofree char *ret_rev = NULL; g_autoptr(GFile) child = NULL; g_return_val_if_fail (ref != NULL, FALSE); /* We intentionally don't allow a ref that looks like a checksum */ if (ostree_validate_checksum_string (ref, NULL)) { ret_rev = g_strdup (ref); } else if (remote != NULL) { child = ot_gfile_resolve_path_printf (self->remote_heads_dir, "%s/%s", remote, ref); if (!g_file_query_exists (child, NULL)) g_clear_object (&child); } else { child = g_file_resolve_relative_path (self->local_heads_dir, ref); if (!g_file_query_exists (child, NULL)) { g_clear_object (&child); child = g_file_resolve_relative_path (self->remote_heads_dir, ref); if (!g_file_query_exists (child, NULL)) { g_clear_object (&child); if (!find_ref_in_remotes (self, ref, &child, error)) goto out; } } } if (child) { if ((ret_rev = gs_file_load_contents_utf8 (child, NULL, &temp_error)) == NULL) { g_propagate_error (error, temp_error); g_prefix_error (error, "Couldn't open ref '%s': ", gs_file_get_path_cached (child)); goto out; } g_strchomp (ret_rev); if (!ostree_validate_checksum_string (ret_rev, error)) goto out; } else { if (!resolve_refspec_fallback (self, remote, ref, allow_noent, &ret_rev, cancellable, error)) goto out; } ot_transfer_out_value (out_rev, &ret_rev); ret = TRUE; out: return ret; }
/** * ostree_repo_list_refs: * @self: Repo * @refspec_prefix: (allow-none): Only list refs which match this prefix * @out_all_refs: (out) (element-type utf8 utf8): Mapping from ref to checksum * @cancellable: Cancellable * @error: Error * * If @refspec_prefix is %NULL, list all local and remote refspecs, * with their current values in @out_all_refs. Otherwise, only list * refspecs which have @refspec_prefix as a prefix. */ gboolean ostree_repo_list_refs (OstreeRepo *self, const char *refspec_prefix, GHashTable **out_all_refs, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(GHashTable) ret_all_refs = NULL; g_autofree char *remote = NULL; g_autofree char *ref_prefix = NULL; ret_all_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); if (refspec_prefix) { g_autoptr(GFile) dir = NULL; g_autoptr(GFile) child = NULL; g_autoptr(GFileInfo) info = NULL; if (!ostree_parse_refspec (refspec_prefix, &remote, &ref_prefix, error)) goto out; if (remote) dir = g_file_get_child (self->remote_heads_dir, remote); else dir = g_object_ref (self->local_heads_dir); child = g_file_resolve_relative_path (dir, ref_prefix); if (!ot_gfile_query_info_allow_noent (child, OSTREE_GIO_FAST_QUERYINFO, 0, &info, cancellable, error)) goto out; if (info) { if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { if (!enumerate_refs_recurse (self, remote, child, child, ret_all_refs, cancellable, error)) goto out; } else { if (!add_ref_to_set (remote, dir, child, ret_all_refs, cancellable, error)) goto out; } } } else { g_autoptr(GFileEnumerator) remote_enumerator = NULL; if (!enumerate_refs_recurse (self, NULL, self->local_heads_dir, self->local_heads_dir, ret_all_refs, cancellable, error)) goto out; remote_enumerator = g_file_enumerate_children (self->remote_heads_dir, OSTREE_GIO_FAST_QUERYINFO, 0, cancellable, error); while (TRUE) { GFileInfo *info; GFile *child; const char *name; if (!gs_file_enumerator_iterate (remote_enumerator, &info, &child, cancellable, error)) goto out; if (!info) break; name = g_file_info_get_name (info); if (!enumerate_refs_recurse (self, name, child, child, ret_all_refs, cancellable, error)) goto out; } } ret = TRUE; ot_transfer_out_value (out_all_refs, &ret_all_refs); out: return ret; }
gboolean rejilla_image_format_get_cue_size (gchar *uri, guint64 *blocks, guint64 *size_img, GCancellable *cancel, GError **error) { GFile *file; gchar *line; gint64 cue_size = 0; GFileInputStream *input; GDataInputStream *stream; file = g_file_new_for_uri (uri); input = g_file_read (file, cancel, error); if (!input) { g_object_unref (file); return FALSE; } stream = g_data_input_stream_new (G_INPUT_STREAM (input)); g_object_unref (input); while ((line = g_data_input_stream_read_line (stream, NULL, cancel, error))) { const gchar *ptr; if ((ptr = strstr (line, "FILE"))) { GFileInfo *info; gchar *file_path; GFile *file_img = NULL; ptr += 4; /* get the path (NOTE: if ptr is NULL file_path as well) */ ptr = rejilla_image_format_read_path (ptr, &file_path); if (!ptr) { g_object_unref (stream); g_object_unref (file); g_free (line); return FALSE; } /* check if the path is relative, if so then add the root path */ if (file_path && !g_path_is_absolute (file_path)) { GFile *parent; parent = g_file_get_parent (file); file_img = g_file_resolve_relative_path (parent, file_path); g_object_unref (parent); } else if (file_path) { gchar *img_uri; gchar *scheme; scheme = g_file_get_uri_scheme (file); img_uri = g_strconcat (scheme, "://", file_path, NULL); g_free (scheme); file_img = g_file_new_for_commandline_arg (img_uri); g_free (img_uri); } g_free (file_path); /* NOTE: follow symlink if any */ info = g_file_query_info (file_img, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, error); g_object_unref (file_img); if (!info) { g_free (line); g_object_unref (file); g_object_unref (stream); return FALSE; } cue_size += g_file_info_get_size (info); g_object_unref (info); } else if ((ptr = strstr (line, "PREGAP"))) { ptr += 6; if (isspace (*ptr)) { gint64 size_pregap; ptr ++; ptr = rejilla_image_format_get_MSF_address (ptr, &size_pregap); if (ptr) cue_size += size_pregap * 2352; } } else if ((ptr = strstr (line, "POSTGAP"))) { ptr += 7; if (isspace (*ptr)) { gint64 size_postgap; ptr ++; ptr = rejilla_image_format_get_MSF_address (ptr, &size_postgap); if (ptr) cue_size += size_postgap * 2352; } } g_free (line); } g_object_unref (stream); g_object_unref (file); if (size_img) *size_img = cue_size; if (blocks) *blocks = REJILLA_BYTES_TO_SECTORS (cue_size, 2352); return TRUE; }
static gboolean migrate_locale_dir (GFile *source_dir, GFile *separate_dir, const char *subdir, GError **error) { g_autoptr(GFileEnumerator) dir_enum = NULL; GFileInfo *next; GError *temp_error = NULL; dir_enum = g_file_enumerate_children (source_dir, "standard::name,standard::type", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (!dir_enum) return TRUE; while ((next = g_file_enumerator_next_file (dir_enum, NULL, &temp_error))) { g_autoptr(GFileInfo) child_info = next; g_autoptr(GFile) locale_subdir = NULL; if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY) { g_autoptr(GFile) child = NULL; const char *name = g_file_info_get_name (child_info); g_autofree char *language = g_strdup (name); g_autofree char *relative = NULL; g_autofree char *target = NULL; char *c; c = strchr (language, '@'); if (c != NULL) *c = 0; c = strchr (language, '_'); if (c != NULL) *c = 0; c = strchr (language, '.'); if (c != NULL) *c = 0; /* We ship english and C locales always */ if (strcmp (language, "C") == 0 || strcmp (language, "en") == 0) continue; child = g_file_get_child (source_dir, g_file_info_get_name (child_info)); relative = g_build_filename (language, subdir, name, NULL); locale_subdir = g_file_resolve_relative_path (separate_dir, relative); if (!flatpak_mkdir_p (locale_subdir, NULL, error)) return FALSE; if (!flatpak_cp_a (child, locale_subdir, FLATPAK_CP_FLAGS_MERGE | FLATPAK_CP_FLAGS_MOVE, NULL, error)) return FALSE; target = g_build_filename ("../../share/runtime/locale", relative, NULL); if (!g_file_make_symbolic_link (child, target, NULL, error)) return FALSE; } } if (temp_error != NULL) { g_propagate_error (error, temp_error); return FALSE; } return TRUE; }
/* Prepare a root filesystem, taking mainly the contents of /usr from yumroot */ static gboolean create_rootfs_from_yumroot_content (GFile *targetroot, GFile *yumroot, JsonObject *treefile, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; glnx_fd_close int src_rootfs_fd = -1; glnx_fd_close int target_root_dfd = -1; gs_unref_object GFile *kernel_path = NULL; gs_unref_object GFile *initramfs_path = NULL; gs_unref_hashtable GHashTable *preserve_groups_set = NULL; gboolean container = FALSE; if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (yumroot), TRUE, &src_rootfs_fd, error)) goto out; if (!_rpmostree_jsonutil_object_get_optional_boolean_member (treefile, "container", &container, error)) goto out; g_print ("Preparing kernel\n"); if (!container && !do_kernel_prep (yumroot, treefile, cancellable, error)) goto out; g_print ("Initializing rootfs\n"); if (!init_rootfs (targetroot, cancellable, error)) goto out; if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (targetroot), TRUE, &target_root_dfd, error)) goto out; g_print ("Migrating /etc/passwd to /usr/lib/\n"); if (!rpmostree_passwd_migrate_except_root (yumroot, RPM_OSTREE_PASSWD_MIGRATE_PASSWD, NULL, cancellable, error)) goto out; if (json_object_has_member (treefile, "etc-group-members")) { JsonArray *etc_group_members = json_object_get_array_member (treefile, "etc-group-members"); preserve_groups_set = _rpmostree_jsonutil_jsarray_strings_to_set (etc_group_members); } g_print ("Migrating /etc/group to /usr/lib/\n"); if (!rpmostree_passwd_migrate_except_root (yumroot, RPM_OSTREE_PASSWD_MIGRATE_GROUP, preserve_groups_set, cancellable, error)) goto out; /* NSS configuration to look at the new files */ { gs_unref_object GFile *yumroot_etc = g_file_resolve_relative_path (yumroot, "etc"); if (!replace_nsswitch (yumroot_etc, cancellable, error)) goto out; } /* We take /usr from the yum content */ g_print ("Moving /usr to target\n"); { gs_unref_object GFile *usr = g_file_get_child (yumroot, "usr"); if (!move_to_dir (usr, targetroot, cancellable, error)) goto out; } /* Except /usr/local -> ../var/usrlocal */ g_print ("Linking /usr/local -> ../var/usrlocal\n"); { gs_unref_object GFile *target_usrlocal = g_file_resolve_relative_path (targetroot, "usr/local"); if (!gs_shutil_rm_rf (target_usrlocal, cancellable, error)) goto out; if (!g_file_make_symbolic_link (target_usrlocal, "../var/usrlocal", cancellable, error)) goto out; } /* And now we take the contents of /etc and put them in /usr/etc */ g_print ("Moving /etc to /usr/etc\n"); { gs_unref_object GFile *yumroot_etc = g_file_get_child (yumroot, "etc"); gs_unref_object GFile *target_usretc = g_file_resolve_relative_path (targetroot, "usr/etc"); if (!gs_file_rename (yumroot_etc, target_usretc, cancellable, error)) goto out; } if (!migrate_rpm_and_yumdb (targetroot, yumroot, cancellable, error)) goto out; if (!convert_var_to_tmpfiles_d (src_rootfs_fd, target_root_dfd, cancellable, error)) goto out; /* Move boot, but rename the kernel/initramfs to have a checksum */ if (!container) { gs_unref_object GFile *yumroot_boot = g_file_get_child (yumroot, "boot"); gs_unref_object GFile *target_boot = g_file_get_child (targetroot, "boot"); gs_unref_object GFile *target_usrlib = g_file_resolve_relative_path (targetroot, "usr/lib"); gs_unref_object GFile *target_usrlib_ostree_boot = g_file_resolve_relative_path (target_usrlib, "ostree-boot"); RpmOstreePostprocessBootLocation boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH; const char *boot_location_str = NULL; g_print ("Moving /boot\n"); if (!_rpmostree_jsonutil_object_get_optional_string_member (treefile, "boot_location", &boot_location_str, error)) goto out; if (boot_location_str != NULL) { if (strcmp (boot_location_str, "legacy") == 0) boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_LEGACY; else if (strcmp (boot_location_str, "both") == 0) boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH; else if (strcmp (boot_location_str, "new") == 0) boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_NEW; else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid boot location '%s'", boot_location_str); goto out; } } if (!gs_file_ensure_directory (target_usrlib, TRUE, cancellable, error)) goto out; switch (boot_location) { case RPMOSTREE_POSTPROCESS_BOOT_LOCATION_LEGACY: { g_print ("Using boot location: legacy\n"); if (!gs_file_rename (yumroot_boot, target_boot, cancellable, error)) goto out; } break; case RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH: { g_print ("Using boot location: both\n"); if (!gs_file_rename (yumroot_boot, target_boot, cancellable, error)) goto out; /* Hardlink the existing content, only a little ugly as * we'll end up sha256'ing it twice, but oh well. */ if (!gs_shutil_cp_al_or_fallback (target_boot, target_usrlib_ostree_boot, cancellable, error)) goto out; } break; case RPMOSTREE_POSTPROCESS_BOOT_LOCATION_NEW: { g_print ("Using boot location: new\n"); if (!gs_file_rename (yumroot_boot, target_usrlib_ostree_boot, cancellable, error)) goto out; } break; } } /* Also carry along toplevel compat links */ g_print ("Copying toplevel compat symlinks\n"); { guint i; const char *toplevel_links[] = { "lib", "lib64", "lib32", "bin", "sbin" }; for (i = 0; i < G_N_ELEMENTS (toplevel_links); i++) { gs_unref_object GFile *srcpath = g_file_get_child (yumroot, toplevel_links[i]); if (g_file_query_file_type (srcpath, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_SYMBOLIC_LINK) { if (!move_to_dir (srcpath, targetroot, cancellable, error)) goto out; } } } g_print ("Adding tmpfiles-ostree-integration.conf\n"); { gs_unref_object GFile *src_pkglibdir = g_file_new_for_path (PKGLIBDIR); gs_unref_object GFile *src_tmpfilesd = g_file_get_child (src_pkglibdir, "tmpfiles-ostree-integration.conf"); gs_unref_object GFile *target_tmpfilesd = g_file_resolve_relative_path (targetroot, "usr/lib/tmpfiles.d/tmpfiles-ostree-integration.conf"); gs_unref_object GFile *target_tmpfilesd_parent = g_file_get_parent (target_tmpfilesd); if (!gs_file_ensure_directory (target_tmpfilesd_parent, TRUE, cancellable, error)) goto out; if (!g_file_copy (src_tmpfilesd, target_tmpfilesd, 0, cancellable, NULL, NULL, error)) goto out; } ret = TRUE; out: return ret; }
static gboolean list_all_boot_directories (OstreeSysroot *self, GPtrArray **out_bootdirs, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gs_unref_object GFileEnumerator *dir_enum = NULL; gs_unref_object GFile *boot_ostree = NULL; gs_unref_ptrarray GPtrArray *ret_bootdirs = NULL; GError *temp_error = NULL; boot_ostree = g_file_resolve_relative_path (self->path, "boot/ostree"); ret_bootdirs = g_ptr_array_new_with_free_func (g_object_unref); dir_enum = g_file_enumerate_children (boot_ostree, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, &temp_error); if (!dir_enum) { if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_clear_error (&temp_error); goto done; } else { g_propagate_error (error, temp_error); goto out; } } while (TRUE) { GFileInfo *file_info = NULL; GFile *child = NULL; const char *name; if (!gs_file_enumerator_iterate (dir_enum, &file_info, &child, NULL, error)) goto out; if (file_info == NULL) break; if (g_file_info_get_file_type (file_info) != G_FILE_TYPE_DIRECTORY) continue; /* Only look at directories ending in -CHECKSUM; nothing else * should be in here, but let's be conservative. */ name = g_file_info_get_name (file_info); if (!parse_bootdir_name (name, NULL, NULL)) continue; g_ptr_array_add (ret_bootdirs, g_object_ref (child)); } done: ret = TRUE; ot_transfer_out_value (out_bootdirs, &ret_bootdirs); out: return ret; }
static gboolean handle_remove_files_from_package (GFile *yumroot, RpmOstreeRefSack *refsack, JsonArray *removespec, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *pkg = json_array_get_string_element (removespec, 0); guint i, j, npackages; guint len = json_array_get_length (removespec); HyPackage hypkg; _cleanup_hyquery_ HyQuery query = NULL; _cleanup_hypackagelist_ HyPackageList pkglist = NULL; query = hy_query_create (refsack->sack); hy_query_filter (query, HY_PKG_NAME, HY_EQ, pkg); pkglist = hy_query_run (query); npackages = hy_packagelist_count (pkglist); if (npackages == 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to find package '%s' specified in remove-files-from", pkg); goto out; } for (j = 0; j < npackages; j++) { _cleanup_hystringarray_ HyStringArray pkg_files = NULL; hypkg = hy_packagelist_get (pkglist, 0); pkg_files = hy_package_get_files (hypkg); for (i = 1; i < len; i++) { const char *remove_regex_pattern = json_array_get_string_element (removespec, i); GRegex *regex; char **strviter; regex = g_regex_new (remove_regex_pattern, G_REGEX_JAVASCRIPT_COMPAT, 0, error); if (!regex) goto out; for (strviter = pkg_files; strviter && strviter[0]; strviter++) { const char *file = *strviter; if (g_regex_match (regex, file, 0, NULL)) { gs_unref_object GFile *child = NULL; if (file[0] == '/') file++; child = g_file_resolve_relative_path (yumroot, file); g_print ("Deleting: %s\n", file); if (!gs_shutil_rm_rf (child, cancellable, error)) goto out; } } } } ret = TRUE; out: return ret; }
static gboolean save_playlist (RBGenericPlayerPlaylistSource *source) { TotemPlParser *parser; TotemPlParserType playlist_type; RhythmDBQueryModel *query_model; char *name; char *temp_path; GError *error = NULL; RBGenericPlayerPlaylistSourcePrivate *priv = GET_PRIVATE (source); GFile *file; gboolean result; SavePlaylistData data; priv->save_playlist_id = 0; playlist_type = rb_generic_player_source_get_playlist_format (priv->player_source); g_object_get (source, "name", &name, "base-query-model", &query_model, NULL); /* if we don't already have a name for this playlist, make one now */ if (priv->playlist_path == NULL) { char *playlist_dir; char *mount_uri; char *filename; const char *ext; GFile *dir; GFile *playlist; ext = playlist_format_extension (playlist_type); if (name == NULL || name[0] == '\0') { /* now what? */ filename = g_strdup_printf ("unnamed%s", ext); } else { filename = g_strdup_printf ("%s%s", name, ext); } playlist_dir = rb_generic_player_source_get_playlist_path (priv->player_source); mount_uri = rb_generic_player_source_get_mount_path (priv->player_source); dir = g_file_new_for_uri (mount_uri); if (playlist_dir != NULL) { GFile *pdir; pdir = g_file_resolve_relative_path (dir, playlist_dir); g_object_unref (dir); dir = pdir; } playlist = g_file_resolve_relative_path (dir, filename); priv->playlist_path = g_file_get_path (playlist); g_free (mount_uri); g_free (playlist_dir); g_object_unref (dir); } temp_path = g_strdup_printf ("%s%06X", priv->playlist_path, g_random_int_range (0, 0xFFFFFF)); file = g_file_new_for_path (temp_path); parser = totem_pl_parser_new (); data.source = source; data.playlist_type = playlist_type; #if TOTEM_PL_PARSER_CHECK_VERSION(2,29,1) data.playlist = totem_pl_playlist_new (); gtk_tree_model_foreach (GTK_TREE_MODEL (query_model), (GtkTreeModelForeachFunc) save_playlist_foreach, &data); if (rb_debug_matches ("totem_pl_parser_save", "totem-pl-parser.c")) { g_object_set (parser, "debug", TRUE, NULL); } result = totem_pl_parser_save (parser, data.playlist, file, name, playlist_type, &error); g_object_unref (data.playlist); data.playlist = NULL; #else if (rb_debug_matches ("totem_pl_parser_write_with_title", "totem-pl-parser.c")) { g_object_set (parser, "debug", TRUE, NULL); } result = totem_pl_parser_write_with_title (parser, GTK_TREE_MODEL (query_model), (TotemPlParserIterFunc) save_playlist_entry, temp_path, name, playlist_type, &data, &error); #endif if (result == FALSE) { /* XXX report this more usefully */ g_warning ("Playlist save failed: %s", error ? error->message : "<no error>"); } else { GFile *dest; dest = g_file_new_for_path (priv->playlist_path); g_file_move (file, dest, G_FILE_COPY_OVERWRITE | G_FILE_COPY_NO_FALLBACK_FOR_MOVE, NULL, NULL, NULL, &error); if (error != NULL) { /* XXX report this more usefully */ g_warning ("moving %s => %s failed: %s", temp_path, priv->playlist_path, error->message); } g_object_unref (dest); } g_clear_error (&error); g_free (name); g_free (temp_path); g_object_unref (query_model); g_object_unref (parser); g_object_unref (file); return FALSE; }
static gboolean visit_enumerator (FilesCtx *ctx, GFile *parent, GFileEnumerator *enumerator, GError **err) { GFileEnumerator *children; gboolean ret = TRUE; GFileInfo *info; FileInfo *finfo; GFile *file = NULL; for (;;) { if (!seahorse_tool_progress_check ()) { ret = FALSE; break; } info = g_file_enumerator_next_file (enumerator, NULL, err); if (!info) { if (err && *err) ret = FALSE; break; } file = g_file_resolve_relative_path (parent, g_file_info_get_name (info)); g_return_val_if_fail (file, FALSE); /* Enumerate child directories */ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { children = g_file_enumerate_children (file, FILE_ATTRIBUTES, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, err); if (!enumerator) { ret = FALSE; break; } ret = visit_enumerator (ctx, file, children, err); if (!ret) break; /* A file, add it */ } else { finfo = g_new0 (FileInfo, 1); finfo->info = info; finfo->file = file; finfo->uri = g_file_get_uri (file); g_object_ref (info); g_object_ref (file); ctx->total += g_file_info_get_size (info); ctx->finfos = g_list_append (ctx->finfos, finfo); } g_object_unref (file); file = NULL; } if (file != NULL) g_object_unref (file); g_object_unref (enumerator); return ret; }
bool PluginPackage::load() { if (m_isLoaded) { m_loadCount++; return true; } GOwnPtr<gchar> finalPath(g_strdup(m_path.utf8().data())); while (g_file_test(finalPath.get(), G_FILE_TEST_IS_SYMLINK)) { GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(finalPath.get())); GRefPtr<GFile> dir = adoptGRef(g_file_get_parent(file.get())); GOwnPtr<gchar> linkPath(g_file_read_link(finalPath.get(), 0)); GRefPtr<GFile> resolvedFile = adoptGRef(g_file_resolve_relative_path(dir.get(), linkPath.get())); finalPath.set(g_file_get_path(resolvedFile.get())); } // No joke. If there is a netscape component in the path, go back // to the symlink, as flash breaks otherwise. // See http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/plugins/plugin_list_posix.cc GOwnPtr<gchar> baseName(g_path_get_basename(finalPath.get())); if (!g_strcmp0(baseName.get(), "libflashplayer.so") && g_strstr_len(finalPath.get(), -1, "/netscape/")) finalPath.set(g_strdup(m_path.utf8().data())); m_module = g_module_open(finalPath.get(), G_MODULE_BIND_LOCAL); if (!m_module) { LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error()); return false; } if (moduleMixesGtkSymbols(m_module)) { LOG(Plugins, "Ignoring module '%s' to avoid mixing GTK+ 2 and GTK+ 3 symbols.\n", m_path.utf8().data()); return false; } m_isLoaded = true; if (!g_strcmp0(baseName.get(), "libflashplayer.so")) { // Flash plugin can produce X errors that are handled by the GDK X error handler, which // exits the process. Since we don't want to crash due to flash bugs, we install a // custom error handler to show a warning when a X error happens without aborting. XSetErrorHandler(webkitgtkXError); } NP_InitializeFuncPtr NP_Initialize = 0; m_NPP_Shutdown = 0; NPError npErr; g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize); g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown); if (!NP_Initialize || !m_NPP_Shutdown) goto abort; memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); m_pluginFuncs.size = sizeof(m_pluginFuncs); initializeBrowserFuncs(); npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs); if (npErr != NPERR_NO_ERROR) goto abort; m_loadCount++; return true; abort: unloadWithoutShutdown(); return false; }
static gboolean step_check_uris (FilesCtx *ctx, const gchar **uris, GError **err) { GFile *file, *base; GFileInfo *info; gchar *t, *path; gboolean ret = TRUE; FileInfo *finfo; const gchar **k; GFileType type; g_assert (err && !*err); t = g_get_current_dir (); base = g_file_new_for_path (t); g_free (t); for (k = uris; *k; k++) { if (!seahorse_tool_progress_check ()) { ret = FALSE; break; } t = g_uri_parse_scheme (*k); if (t) file = g_file_new_for_uri (*k); else file = g_file_resolve_relative_path (base, *k); g_free (t); g_return_val_if_fail (file != NULL, FALSE); /* Find out if file can be accessed locally? */ path = g_file_get_path (file); if (!path) ctx->remote = TRUE; g_free (path); info = g_file_query_info (file, FILE_ATTRIBUTES, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, err); if (!info) { ret = FALSE; g_object_unref (file); break; } type = g_file_info_get_file_type (info); /* Only handle simple types */ if (type == G_FILE_TYPE_REGULAR || type == G_FILE_TYPE_UNKNOWN || type == G_FILE_TYPE_DIRECTORY) { finfo = g_new0 (FileInfo, 1); finfo->file = file; g_object_ref (file); finfo->info = info; g_object_ref (info); finfo->uri = g_file_get_uri (file); ctx->total += g_file_info_get_size (info); ctx->finfos = g_list_prepend (ctx->finfos, finfo); } g_object_unref (file); g_object_unref (info); } g_object_unref (base); ctx->finfos = g_list_reverse (ctx->finfos); return ret; }
char * rb_uri_resolve_symlink (const char *uri, GError **error) { GFile *file = NULL; GFileInfo *file_info = NULL; int link_count = 0; char *result = NULL; const char *attr = G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET; GError *l_error = NULL; file = g_file_new_for_uri (uri); while (link_count < MAX_LINK_LEVEL) { GFile *parent; GFile *new_file; char *target; /* look for a symlink target */ file_info = g_file_query_info (file, attr, G_FILE_QUERY_INFO_NONE, NULL, &l_error); if (l_error != NULL) { /* argh */ result = g_file_get_uri (file); rb_debug ("error querying %s: %s", result, l_error->message); g_free (result); result = NULL; break; } else if (g_file_info_has_attribute (file_info, attr) == FALSE) { /* no symlink, so return the path */ result = g_file_get_uri (file); if (link_count > 0) { rb_debug ("resolved symlinks: %s -> %s", uri, result); } break; } /* resolve it and try again */ new_file = NULL; parent = g_file_get_parent (file); if (parent == NULL) { /* dang */ break; } target = g_file_info_get_attribute_as_string (file_info, attr); new_file = g_file_resolve_relative_path (parent, target); g_free (target); g_object_unref (parent); g_object_unref (file_info); file_info = NULL; g_object_unref (file); file = new_file; if (file == NULL) { /* dang */ break; } link_count++; } if (file != NULL) { g_object_unref (file); } if (file_info != NULL) { g_object_unref (file_info); } if (result == NULL && error == NULL) { rb_debug ("too many symlinks while resolving %s", uri); l_error = g_error_new (G_IO_ERROR, G_IO_ERROR_TOO_MANY_LINKS, _("Too many symlinks")); } if (l_error != NULL) { g_propagate_error (error, l_error); } return result; }
static void _cairo_render_background (CairoRenderer *renderer, PinPointPoint *point) { char *full_path = NULL; const char *file; if (point == NULL) return; file = point->bg; if (point->bg_type != PP_BG_COLOR && renderer->path && file) { char *dir = g_path_get_dirname (renderer->path); full_path = g_build_filename (dir, file, NULL); g_free (dir); file = full_path; } if (point->stage_color) { ClutterColor color; clutter_color_from_string (&color, point->stage_color); cairo_set_source_rgba (renderer->ctx, color.red / 255.f, color.green / 255.f, color.blue / 255.f, color.alpha / 255.f); cairo_paint (renderer->ctx); } switch (point->bg_type) { case PP_BG_NONE: break; case PP_BG_COLOR: { ClutterColor color; clutter_color_from_string (&color, point->bg); cairo_set_source_rgba (renderer->ctx, color.red / 255.f, color.green / 255.f, color.blue / 255.f, color.alpha / 255.f); cairo_paint (renderer->ctx); } break; case PP_BG_IMAGE: { cairo_surface_t *surface; float bg_x, bg_y, bg_width, bg_height, bg_scale_x, bg_scale_y; surface = _cairo_get_surface (renderer, file); if (surface == NULL) break; bg_width = cairo_image_surface_get_width (surface); bg_height = cairo_image_surface_get_height (surface); pp_get_background_position_scale (point, renderer->width, renderer->height, bg_width, bg_height, &bg_x, &bg_y, &bg_scale_x, &bg_scale_y); cairo_save (renderer->ctx); cairo_translate (renderer->ctx, bg_x, bg_y); cairo_scale (renderer->ctx, bg_scale_x, bg_scale_y); cairo_set_source_surface (renderer->ctx, surface, 0., 0.); cairo_paint (renderer->ctx); cairo_restore (renderer->ctx); } break; case PP_BG_VIDEO: { #ifdef USE_CLUTTER_GST GdkPixbuf *pixbuf; cairo_surface_t *surface; float bg_x, bg_y, bg_width, bg_height, bg_scale_x, bg_scale_y; GCancellable* cancellable = g_cancellable_new (); GFile *abs_file; gchar *abs_path; abs_file = g_file_resolve_relative_path (pp_basedir, point->bg); abs_path = g_file_get_path (abs_file); g_object_unref (abs_file); pixbuf = gst_video_thumbnailer_get_shot (abs_path, cancellable); g_free (abs_path); if (pixbuf == NULL) { g_warning ("Could not create video thumbmail for %s", point->bg); break; } surface = _cairo_new_surface_from_pixbuf (pixbuf); g_hash_table_insert (renderer->surfaces, g_strdup (file), surface); bg_width = cairo_image_surface_get_width (surface); bg_height = cairo_image_surface_get_height (surface); pp_get_background_position_scale (point, renderer->width, A4_LS_HEIGHT, bg_width, bg_height, &bg_x, &bg_y, &bg_scale_x, &bg_scale_y); cairo_save (renderer->ctx); cairo_translate (renderer->ctx, bg_x, bg_y); cairo_scale (renderer->ctx, bg_scale_x, bg_scale_y); cairo_set_source_surface (renderer->ctx, surface, 0., 0.); cairo_paint (renderer->ctx); cairo_restore (renderer->ctx); #endif break; } case PP_BG_SVG: #ifdef HAVE_RSVG { RsvgHandle *svg = _cairo_get_svg (renderer, file); RsvgDimensionData dim; float bg_x, bg_y, bg_scale_x, bg_scale_y; if (svg == NULL) break; rsvg_handle_get_dimensions (svg, &dim); pp_get_background_position_scale (point, renderer->width, renderer->height, dim.width, dim.height, &bg_x, &bg_y, &bg_scale_x, &bg_scale_y); cairo_save (renderer->ctx); cairo_translate (renderer->ctx, bg_x, bg_y); cairo_scale (renderer->ctx, bg_scale_x, bg_scale_y); rsvg_handle_render_cairo (svg, renderer->ctx); cairo_restore (renderer->ctx); } #endif break; case PP_BG_CAMERA: /* silently ignore camera backgrounds */ break; default: g_assert_not_reached(); } g_free (full_path); }
static gboolean copy_extensions (FlatpakDeploy *src_deploy, const char *default_branch, char *src_extensions[], GFile *top_dir, GCancellable *cancellable, GError **error) { g_autoptr(GKeyFile) metakey = flatpak_deploy_get_metadata (src_deploy); GList *extensions = NULL, *l; int i; /* We leak this on failure, as we have no autoptr for deep lists.. */ extensions = flatpak_list_extensions (metakey, opt_arch, default_branch); for (i = 0; src_extensions[i] != NULL; i++) { const char *requested_extension = src_extensions[i]; gboolean found = FALSE; for (l = extensions; l != NULL; l = l->next) { FlatpakExtension *ext = l->data; if (strcmp (ext->installed_id, requested_extension) == 0 || strcmp (ext->id, requested_extension) == 0) { g_autoptr(GFile) target = g_file_resolve_relative_path (top_dir, ext->directory); g_autoptr(GFile) target_parent = g_file_get_parent (target); g_autoptr(GFile) ext_deploy_files = g_file_new_for_path (ext->files_path); if (!ext->is_unmaintained) { g_autoptr(FlatpakDir) src_dir = NULL; g_autoptr(GFile) deploy = NULL; g_autoptr(GVariant) deploy_data = NULL; const char **subpaths; deploy = flatpak_find_deploy_dir_for_ref (ext->ref, &src_dir, cancellable, error); if (deploy == NULL) return FALSE; deploy_data = flatpak_dir_get_deploy_data (src_dir, ext->ref, cancellable, error); if (deploy_data == NULL) return FALSE; subpaths = flatpak_deploy_data_get_subpaths (deploy_data); if (subpaths[0] != NULL) return flatpak_fail (error, _("Requested extension %s is only partially installed"), ext->installed_id); } if (!flatpak_mkdir_p (target_parent, cancellable, error)) return FALSE; /* An extension overrides whatever is there before, so we clean up first */ if (!flatpak_rm_rf (target, cancellable, error)) return FALSE; if (!flatpak_cp_a (ext_deploy_files, target, FLATPAK_CP_FLAGS_NO_CHOWN, cancellable, error)) return FALSE; found = TRUE; } } if (!found) { g_list_free_full (extensions, (GDestroyNotify) flatpak_extension_free); return flatpak_fail (error, _("Requested extension %s not installed"), requested_extension); } } g_list_free_full (extensions, (GDestroyNotify) flatpak_extension_free); return TRUE; }
static gboolean do_kernel_prep (GFile *yumroot, JsonObject *treefile, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gs_unref_object GFile *bootdir = g_file_get_child (yumroot, "boot"); gs_unref_object GFile *kernel_path = NULL; gs_unref_object GFile *initramfs_path = NULL; const char *boot_checksum_str = NULL; GChecksum *boot_checksum = NULL; g_autofree char *kver = NULL; if (!find_kernel_and_initramfs_in_bootdir (bootdir, &kernel_path, &initramfs_path, cancellable, error)) goto out; if (kernel_path == NULL) { gs_unref_object GFile *mod_dir = g_file_resolve_relative_path (yumroot, "usr/lib/modules"); gs_unref_object GFile *modversion_dir = NULL; if (!find_ensure_one_subdirectory (mod_dir, &modversion_dir, cancellable, error)) goto out; if (modversion_dir) { kver = g_file_get_basename (modversion_dir); if (!find_kernel_and_initramfs_in_bootdir (modversion_dir, &kernel_path, &initramfs_path, cancellable, error)) goto out; } } if (kernel_path == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to find kernel (vmlinuz) in /boot or /usr/lib/modules"); goto out; } if (initramfs_path) { g_print ("Removing RPM-generated '%s'\n", gs_file_get_path_cached (initramfs_path)); if (!gs_shutil_rm_rf (initramfs_path, cancellable, error)) goto out; } if (!kver) { const char *kname = gs_file_get_basename_cached (kernel_path); const char *kver_p; kver_p = strchr (kname, '-'); g_assert (kver_p); kver = g_strdup (kver_p + 1); } /* OSTree needs to own this */ { gs_unref_object GFile *loaderdir = g_file_get_child (bootdir, "loader"); if (!gs_shutil_rm_rf (loaderdir, cancellable, error)) goto out; } { char *child_argv[] = { "depmod", (char*)kver, NULL }; if (!run_sync_in_root (yumroot, "depmod", child_argv, error)) goto out; } /* Ensure the /etc/machine-id file is present and empty. Apparently systemd doesn't work when the file is missing (as of systemd-219-9.fc22) but it is correctly populated if the file is there. */ g_print ("Creating empty machine-id\n"); { const char *hardcoded_machine_id = ""; gs_unref_object GFile *machineid_path = g_file_resolve_relative_path (yumroot, "etc/machine-id"); if (!g_file_replace_contents (machineid_path, hardcoded_machine_id, strlen (hardcoded_machine_id), NULL, FALSE, 0, NULL, cancellable, error)) goto out; } { gboolean reproducible; gs_unref_ptrarray GPtrArray *dracut_argv = g_ptr_array_new (); if (!dracut_supports_reproducible (yumroot, &reproducible, cancellable, error)) goto out; g_ptr_array_add (dracut_argv, "dracut"); g_ptr_array_add (dracut_argv, "-v"); if (reproducible) { g_ptr_array_add (dracut_argv, "--reproducible"); g_ptr_array_add (dracut_argv, "--gzip"); } g_ptr_array_add (dracut_argv, "--tmpdir=/tmp"); g_ptr_array_add (dracut_argv, "-f"); g_ptr_array_add (dracut_argv, "/var/tmp/initramfs.img"); g_ptr_array_add (dracut_argv, (char*)kver); if (json_object_has_member (treefile, "initramfs-args")) { guint i, len; JsonArray *initramfs_args; initramfs_args = json_object_get_array_member (treefile, "initramfs-args"); len = json_array_get_length (initramfs_args); for (i = 0; i < len; i++) { const char *arg = _rpmostree_jsonutil_array_require_string_element (initramfs_args, i, error); if (!arg) goto out; g_ptr_array_add (dracut_argv, (char*)arg); } } g_ptr_array_add (dracut_argv, NULL); if (!run_sync_in_root (yumroot, "dracut", (char**)dracut_argv->pdata, error)) goto out; } initramfs_path = g_file_resolve_relative_path (yumroot, "var/tmp/initramfs.img"); if (!g_file_query_exists (initramfs_path, NULL)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Dracut failed to generate '%s'", gs_file_get_path_cached (initramfs_path)); goto out; } { gs_free char *initramfs_name = g_strconcat ("initramfs-", kver, ".img", NULL); gs_unref_object GFile *initramfs_dest = g_file_get_child (bootdir, initramfs_name); if (!gs_file_rename (initramfs_path, initramfs_dest, cancellable, error)) goto out; /* Transfer ownership */ g_object_unref (initramfs_path); initramfs_path = initramfs_dest; initramfs_dest = NULL; } boot_checksum = g_checksum_new (G_CHECKSUM_SHA256); if (!_rpmostree_util_update_checksum_from_file (boot_checksum, kernel_path, cancellable, error)) goto out; if (!_rpmostree_util_update_checksum_from_file (boot_checksum, initramfs_path, cancellable, error)) goto out; boot_checksum_str = g_checksum_get_string (boot_checksum); { gs_free char *new_kernel_name = g_strconcat (gs_file_get_basename_cached (kernel_path), "-", boot_checksum_str, NULL); gs_unref_object GFile *new_kernel_path = g_file_get_child (bootdir, new_kernel_name); gs_free char *new_initramfs_name = g_strconcat (gs_file_get_basename_cached (initramfs_path), "-", boot_checksum_str, NULL); gs_unref_object GFile *new_initramfs_path = g_file_get_child (bootdir, new_initramfs_name); if (!gs_file_rename (kernel_path, new_kernel_path, cancellable, error)) goto out; if (!gs_file_rename (initramfs_path, new_initramfs_path, cancellable, error)) goto out; } ret = TRUE; out: if (boot_checksum) g_checksum_free (boot_checksum); return ret; }
/* See "man 5 passwd" We just make sure the name and uid/gid match, and that none are missing. don't care about GECOS/dir/shell. */ static gboolean rpmostree_check_passwd_groups (gboolean passwd, OstreeRepo *repo, GFile *yumroot, GFile *treefile_dirpath, JsonObject *treedata, const char *previous_commit, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *direct = NULL; const char *chk_type = "previous"; const char *commit_filepath = passwd ? "usr/lib/passwd" : "usr/lib/group"; const char *json_conf_name = passwd ? "check-passwd" : "check-groups"; const char *json_conf_ign = passwd ? "ignore-removed-users" : "ignore-removed-groups"; g_autoptr(GFile) old_path = NULL; g_autoptr(GFile) new_path = g_file_resolve_relative_path (yumroot, commit_filepath); g_autoptr(GPtrArray) ignore_removed_ents = NULL; gboolean ignore_all_removed = FALSE; g_autofree char *old_contents = NULL; g_autofree char *new_contents = NULL; g_autoptr(GPtrArray) old_ents = NULL; g_autoptr(GPtrArray) new_ents = NULL; unsigned int oiter = 0; unsigned int niter = 0; if (json_object_has_member (treedata, json_conf_name)) { JsonObject *chk = json_object_get_object_member (treedata,json_conf_name); if (!chk) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s is not an object", json_conf_name); goto out; } chk_type = _rpmostree_jsonutil_object_require_string_member (chk, "type", error); if (!chk_type) goto out; if (g_str_equal (chk_type, "none")) { ret = TRUE; goto out; } else if (g_str_equal (chk_type, "file")) { direct = _rpmostree_jsonutil_object_require_string_member (chk, "filename", error); if (!direct) goto out; } else if (g_str_equal (chk_type, "data")) { JsonNode *ents_node = json_object_get_member (chk, "entries"); JsonObject *ents_obj = NULL; GList *ents; GList *iter; if (!ents_node) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No entries member for data in %s", json_conf_name); goto out; } ents_obj = json_node_get_object (ents_node); if (passwd) old_ents = g_ptr_array_new_with_free_func (conv_passwd_ent_free); else old_ents = g_ptr_array_new_with_free_func (conv_group_ent_free); ents = json_object_get_members (ents_obj); for (iter = ents; iter; iter = iter->next) if (passwd) { const char *name = iter->data; JsonNode *val = json_object_get_member (ents_obj, name); JsonNodeType child_type = json_node_get_node_type (val); gint64 uid = 0; gint64 gid = 0; struct conv_passwd_ent *convent = g_new (struct conv_passwd_ent, 1); if (child_type != JSON_NODE_ARRAY) { if (!_rpmostree_jsonutil_object_require_int_member (ents_obj, name, &uid, error)) goto out; gid = uid; } else { JsonArray *child_array = json_node_get_array (val); guint len = json_array_get_length (child_array); if (!len || (len > 2)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Array %s is only for uid and gid. Has length %u", name, len); goto out; } if (!_rpmostree_jsonutil_array_require_int_element (child_array, 0, &uid, error)) goto out; if (len == 1) gid = uid; else if (!_rpmostree_jsonutil_array_require_int_element (child_array, 1, &gid, error)) goto out; } convent->name = g_strdup (name); convent->uid = uid; convent->gid = gid; g_ptr_array_add (old_ents, convent); } else { const char *name = iter->data; gint64 gid = 0; struct conv_group_ent *convent = g_new (struct conv_group_ent, 1); if (!_rpmostree_jsonutil_object_require_int_member (ents_obj, name, &gid, error)) goto out; convent->name = g_strdup (name); convent->gid = gid; g_ptr_array_add (old_ents, convent); } }
static gboolean rewrite_delta (OstreeRepo *src_repo, const char *src_commit, OstreeRepo *dst_repo, const char *dst_commit, GVariant *dst_commitv, const char *from, GError **error) { g_autoptr(GFile) src_delta_file = NULL; g_autoptr(GFile) dst_delta_file = NULL; g_autofree char *src_detached_key = _ostree_get_relative_static_delta_path (from, src_commit, "commitmeta"); g_autofree char *dst_detached_key = _ostree_get_relative_static_delta_path (from, dst_commit, "commitmeta"); g_autofree char *src_delta_dir = _ostree_get_relative_static_delta_path (from, src_commit, NULL); g_autofree char *dst_delta_dir = _ostree_get_relative_static_delta_path (from, dst_commit, NULL); g_autofree char *src_superblock_path = _ostree_get_relative_static_delta_path (from, src_commit, "superblock"); g_autofree char *dst_superblock_path = _ostree_get_relative_static_delta_path (from, dst_commit, "superblock"); GMappedFile *mfile = NULL; g_auto(GVariantBuilder) superblock_builder = FLATPAK_VARIANT_BUILDER_INITIALIZER; g_autoptr(GVariant) src_superblock = NULL; g_autoptr(GVariant) dst_superblock = NULL; g_autoptr(GBytes) bytes = NULL; g_autoptr(GVariant) dst_detached = NULL; g_autoptr(GVariant) src_metadata = NULL; g_autoptr(GVariant) src_recurse = NULL; g_autoptr(GVariant) src_parts = NULL; g_auto(GVariantDict) dst_metadata_dict = FLATPAK_VARIANT_DICT_INITIALIZER; int i; src_delta_file = g_file_resolve_relative_path (ostree_repo_get_path (src_repo), src_superblock_path); mfile = g_mapped_file_new (flatpak_file_get_path_cached (src_delta_file), FALSE, NULL); if (mfile == NULL) return TRUE; /* No superblock, not an error */ bytes = g_mapped_file_get_bytes (mfile); g_mapped_file_unref (mfile); src_superblock = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE (OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT), bytes, FALSE)); src_metadata = g_variant_get_child_value (src_superblock, 0); src_recurse = g_variant_get_child_value (src_superblock, 5); src_parts = g_variant_get_child_value (src_superblock, 6); if (g_variant_n_children (src_recurse) != 0) return flatpak_fail (error, "Recursive deltas not supported, ignoring"); g_variant_builder_init (&superblock_builder, G_VARIANT_TYPE (OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT)); g_variant_dict_init (&dst_metadata_dict, src_metadata); g_variant_dict_remove (&dst_metadata_dict, src_detached_key); if (ostree_repo_read_commit_detached_metadata (dst_repo, dst_commit, &dst_detached, NULL, NULL) && dst_detached != NULL) g_variant_dict_insert_value (&dst_metadata_dict, dst_detached_key, dst_detached); g_variant_builder_add_value (&superblock_builder, g_variant_dict_end (&dst_metadata_dict)); g_variant_builder_add_value (&superblock_builder, g_variant_get_child_value (src_superblock, 1)); /* timestamp */ g_variant_builder_add_value (&superblock_builder, from ? ostree_checksum_to_bytes_v (from) : new_bytearray ((guchar *) "", 0)); g_variant_builder_add_value (&superblock_builder, ostree_checksum_to_bytes_v (dst_commit)); g_variant_builder_add_value (&superblock_builder, dst_commitv); g_variant_builder_add_value (&superblock_builder, src_recurse); g_variant_builder_add_value (&superblock_builder, src_parts); g_variant_builder_add_value (&superblock_builder, g_variant_get_child_value (src_superblock, 7)); /* fallback */ dst_superblock = g_variant_ref_sink (g_variant_builder_end (&superblock_builder)); if (!glnx_shutil_mkdir_p_at (ostree_repo_get_dfd (dst_repo), dst_delta_dir, 0755, NULL, error)) return FALSE; for (i = 0; i < g_variant_n_children (src_parts); i++) { g_autofree char *src_part_path = g_strdup_printf ("%s/%d", src_delta_dir, i); g_autofree char *dst_part_path = g_strdup_printf ("%s/%d", dst_delta_dir, i); if (!glnx_file_copy_at (ostree_repo_get_dfd (src_repo), src_part_path, NULL, ostree_repo_get_dfd (dst_repo), dst_part_path, GLNX_FILE_COPY_OVERWRITE | GLNX_FILE_COPY_NOXATTRS, NULL, error)) return FALSE; } dst_delta_file = g_file_resolve_relative_path (ostree_repo_get_path (dst_repo), dst_superblock_path); if (!flatpak_variant_save (dst_delta_file, dst_superblock, NULL, error)) return FALSE; return TRUE; }
gboolean rpmostree_treefile_postprocessing (GFile *yumroot, GFile *context_directory, GBytes *serialized_treefile, JsonObject *treefile, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; guint i, len; JsonArray *units = NULL; JsonArray *remove = NULL; const char *default_target = NULL; const char *postprocess_script = NULL; if (json_object_has_member (treefile, "units")) units = json_object_get_array_member (treefile, "units"); if (units) len = json_array_get_length (units); else len = 0; { gs_unref_object GFile *multiuser_wants_dir = g_file_resolve_relative_path (yumroot, "etc/systemd/system/multi-user.target.wants"); if (!gs_file_ensure_directory (multiuser_wants_dir, TRUE, cancellable, error)) goto out; for (i = 0; i < len; i++) { const char *unitname = _rpmostree_jsonutil_array_require_string_element (units, i, error); gs_unref_object GFile *unit_link_target = NULL; gs_free char *symlink_target = NULL; if (!unitname) goto out; symlink_target = g_strconcat ("/usr/lib/systemd/system/", unitname, NULL); unit_link_target = g_file_get_child (multiuser_wants_dir, unitname); if (g_file_query_file_type (unit_link_target, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_SYMBOLIC_LINK) continue; g_print ("Adding %s to multi-user.target.wants\n", unitname); if (!g_file_make_symbolic_link (unit_link_target, symlink_target, cancellable, error)) goto out; } } { gs_unref_object GFile *target_treefile_dir_path = g_file_resolve_relative_path (yumroot, "usr/share/rpm-ostree"); gs_unref_object GFile *target_treefile_path = g_file_get_child (target_treefile_dir_path, "treefile.json"); const guint8 *buf; gsize len; if (!gs_file_ensure_directory (target_treefile_dir_path, TRUE, cancellable, error)) goto out; g_print ("Writing '%s'\n", gs_file_get_path_cached (target_treefile_path)); buf = g_bytes_get_data (serialized_treefile, &len); if (!g_file_replace_contents (target_treefile_path, (char*)buf, len, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, cancellable, error)) goto out; } if (!_rpmostree_jsonutil_object_get_optional_string_member (treefile, "default_target", &default_target, error)) goto out; if (default_target != NULL) { gs_unref_object GFile *default_target_path = g_file_resolve_relative_path (yumroot, "etc/systemd/system/default.target"); gs_free char *dest_default_target_path = g_strconcat ("/usr/lib/systemd/system/", default_target, NULL); (void) gs_file_unlink (default_target_path, NULL, NULL); if (!g_file_make_symbolic_link (default_target_path, dest_default_target_path, cancellable, error)) goto out; } if (json_object_has_member (treefile, "remove-files")) { remove = json_object_get_array_member (treefile, "remove-files"); len = json_array_get_length (remove); } else len = 0; for (i = 0; i < len; i++) { const char *val = _rpmostree_jsonutil_array_require_string_element (remove, i, error); gs_unref_object GFile *child = NULL; if (!val) return FALSE; if (g_path_is_absolute (val)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "'remove' elements must be relative"); goto out; } child = g_file_resolve_relative_path (yumroot, val); if (g_file_query_exists (child, NULL)) { g_print ("Removing '%s'\n", val); if (!gs_shutil_rm_rf (child, cancellable, error)) goto out; } else { g_printerr ("warning: Targeted path for remove-files does not exist: %s\n", gs_file_get_path_cached (child)); } } if (json_object_has_member (treefile, "remove-from-packages")) { g_autoptr(RpmOstreeRefSack) refsack = NULL; _cleanup_hypackagelist_ HyPackageList pkglist = NULL; guint i; remove = json_object_get_array_member (treefile, "remove-from-packages"); len = json_array_get_length (remove); if (!rpmostree_get_pkglist_for_root (AT_FDCWD, gs_file_get_path_cached (yumroot), &refsack, &pkglist, cancellable, error)) { g_prefix_error (error, "Reading package set: "); goto out; } for (i = 0; i < len; i++) { JsonArray *elt = json_array_get_array_element (remove, i); if (!handle_remove_files_from_package (yumroot, refsack, elt, cancellable, error)) goto out; } } if (!_rpmostree_jsonutil_object_get_optional_string_member (treefile, "postprocess-script", &postprocess_script, error)) goto out; if (postprocess_script) { const char *yumroot_path = gs_file_get_path_cached (yumroot); gs_unref_object GFile *src = g_file_resolve_relative_path (context_directory, postprocess_script); const char *bn = gs_file_get_basename_cached (src); gs_free char *binpath = g_strconcat ("/usr/bin/rpmostree-postprocess-", bn, NULL); gs_free char *destpath = g_strconcat (yumroot_path, binpath, NULL); gs_unref_object GFile *dest = g_file_new_for_path (destpath); /* Clone all the things */ if (!g_file_copy (src, dest, 0, cancellable, NULL, NULL, error)) { g_prefix_error (error, "Copying postprocess-script '%s' into target: ", bn); goto out; } g_print ("Executing postprocessing script '%s'\n", bn); { char *child_argv[] = { binpath, NULL }; if (!run_sync_in_root (yumroot, binpath, child_argv, error)) { g_prefix_error (error, "While executing postprocessing script '%s': ", bn); goto out; } } g_print ("Finished postprocessing script '%s'\n", bn); } ret = TRUE; out: return ret; }
static gboolean rejilla_image_format_get_DATAFILE_info (const gchar *ptr, GFile *parent, gint64 *size_file, GError **error) { gchar *path = NULL; GFileInfo *info; GFile *file; /* get the path. NOTE: no need to check if it's relative since that's * just to skip it. */ ptr = rejilla_image_format_read_path (ptr, &path); if (!ptr) return FALSE; /* skip white spaces */ while (isspace (*ptr)) ptr++; if (ptr [0] == '\0' || (ptr [0] == '/' && ptr [1] == '/')) goto stat_end; if (!rejilla_image_format_get_MSF_address (ptr, size_file)) { g_free (path); return FALSE; } g_free (path); return TRUE; stat_end: /* check if the path is relative, if so then add the root path */ if (path && !g_path_is_absolute (path)) file = g_file_resolve_relative_path (parent, path); else if (path) { gchar *img_uri; gchar *scheme; scheme = g_file_get_uri_scheme (parent); img_uri = g_strconcat (scheme, "://", path, NULL); g_free (scheme); file = g_file_new_for_commandline_arg (img_uri); g_free (img_uri); } g_free (path); /* NOTE: follow symlink if any */ info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, error); g_object_unref (file); if (!info) return FALSE; if (size_file) *size_file = REJILLA_BYTES_TO_SECTORS (g_file_info_get_size (info), 2352); g_object_unref (info); return TRUE; }
static gboolean migrate_rpm_and_yumdb (GFile *targetroot, GFile *yumroot, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gs_unref_object GFile *usrbin_rpm = g_file_resolve_relative_path (targetroot, "usr/bin/rpm"); gs_unref_object GFile *legacyrpm_path = g_file_resolve_relative_path (yumroot, "var/lib/rpm"); gs_unref_object GFile *newrpm_path = g_file_resolve_relative_path (targetroot, "usr/share/rpm"); gs_unref_object GFile *src_yum_rpmdb_indexes = g_file_resolve_relative_path (yumroot, "var/lib/yum"); gs_unref_object GFile *target_yum_rpmdb_indexes = g_file_resolve_relative_path (targetroot, "usr/share/yumdb"); gs_unref_object GFile *yumroot_yumlib = g_file_get_child (yumroot, "var/lib/yum"); gs_unref_object GFileEnumerator *direnum = NULL; direnum = g_file_enumerate_children (legacyrpm_path, "standard::name", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!direnum) goto out; while (TRUE) { const char *name; GFileInfo *file_info; GFile *child; if (!gs_file_enumerator_iterate (direnum, &file_info, &child, cancellable, error)) goto out; if (!file_info) break; name = g_file_info_get_name (file_info); if (g_str_has_prefix (name, "__db.") || strcmp (name, ".dbenv.lock") == 0 || strcmp (name, ".rpm.lock") == 0) { if (!gs_file_unlink (child, cancellable, error)) goto out; } } (void) g_file_enumerator_close (direnum, cancellable, error); g_print ("Placing RPM db in /usr/share/rpm\n"); if (!gs_file_rename (legacyrpm_path, newrpm_path, cancellable, error)) goto out; /* Remove /var/lib/yum; we don't want it here. */ if (!gs_shutil_rm_rf (yumroot_yumlib, cancellable, error)) goto out; ret = TRUE; out: return ret; }
static gboolean rejilla_image_format_get_FILE_info (const gchar *ptr, GFile *parent, gint64 *size_img, GError **error) { gchar *path = NULL; gint64 start = 0; GFileInfo *info; GFile *file = NULL; gchar *tmp; /* get the path and skip it */ ptr = rejilla_image_format_read_path (ptr, &path); if (!ptr) return FALSE; /* skip white spaces */ while (isspace (*ptr)) ptr++; /* skip a possible #.... (offset in bytes) */ tmp = g_utf8_strchr (ptr, -1, '#'); if (tmp) { tmp ++; while (isdigit (*tmp)) tmp ++; while (isspace (*tmp)) tmp++; ptr = tmp; } /* get the start */ ptr = rejilla_image_format_get_MSF_address (ptr, &start); if (!ptr) { g_free (path); return FALSE; } /* skip white spaces */ while (isspace (*ptr)) ptr++; if (ptr [0] == '\0' || (ptr [0] == '/' && ptr [1] == '/')) goto stat_end; /* get the size */ if (!rejilla_image_format_get_MSF_address (ptr, size_img)) { g_free (path); return FALSE; } g_free (path); return TRUE; stat_end: /* check if the path is relative, if so then add the root path */ if (path && !g_path_is_absolute (path)) file = g_file_resolve_relative_path (parent, path); else if (path) { gchar *img_uri; gchar *scheme; scheme = g_file_get_uri_scheme (parent); img_uri = g_strconcat (scheme, "://", path, NULL); g_free (scheme); file = g_file_new_for_commandline_arg (img_uri); g_free (img_uri); } else return FALSE; g_free (path); /* NOTE: follow symlink if any */ info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, error); g_object_unref (file); if (!info) return FALSE; if (size_img) *size_img = REJILLA_BYTES_TO_SECTORS (g_file_info_get_size (info), 2352) - start; g_object_unref (info); return TRUE; }
bool PluginPackage::load() { if (m_isLoaded) { m_loadCount++; return true; } GOwnPtr<gchar> finalPath(g_strdup(m_path.utf8().data())); while (g_file_test(finalPath.get(), G_FILE_TEST_IS_SYMLINK)) { GOwnPtr<GFile> file(g_file_new_for_path(finalPath.get())); GOwnPtr<GFile> dir(g_file_get_parent(file.get())); GOwnPtr<gchar> linkPath(g_file_read_link(finalPath.get(), 0)); GOwnPtr<GFile> resolvedFile(g_file_resolve_relative_path(dir.get(), linkPath.get())); finalPath.set(g_file_get_path(resolvedFile.get())); } // No joke. If there is a netscape component in the path, go back // to the symlink, as flash breaks otherwise. // See http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/plugins/plugin_list_posix.cc GOwnPtr<gchar> baseName(g_path_get_basename(finalPath.get())); if (!g_strcmp0(baseName.get(), "libflashplayer.so") && g_strstr_len(finalPath.get(), -1, "/netscape/")) finalPath.set(g_strdup(m_path.utf8().data())); m_module = g_module_open(finalPath.get(), G_MODULE_BIND_LOCAL); if (!m_module) { LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error()); return false; } m_isLoaded = true; NP_InitializeFuncPtr NP_Initialize = 0; m_NPP_Shutdown = 0; NPError npErr; g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize); g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown); if (!NP_Initialize || !m_NPP_Shutdown) goto abort; memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); m_pluginFuncs.size = sizeof(m_pluginFuncs); initializeBrowserFuncs(); #if defined(XP_UNIX) npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs); #else npErr = NP_Initialize(&m_browserFuncs); #endif if (npErr != NPERR_NO_ERROR) goto abort; m_loadCount++; return true; abort: unloadWithoutShutdown(); return false; }
static gboolean migrate_rpm_and_yumdb (GFile *targetroot, GFile *yumroot, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gs_unref_object GFile *usrbin_rpm = g_file_resolve_relative_path (targetroot, "usr/bin/rpm"); gs_unref_object GFile *legacyrpm_path = g_file_resolve_relative_path (yumroot, "var/lib/rpm"); gs_unref_object GFile *newrpm_path = g_file_resolve_relative_path (targetroot, "usr/share/rpm"); gs_unref_object GFile *src_yum_rpmdb_indexes = g_file_resolve_relative_path (yumroot, "var/lib/yum"); gs_unref_object GFile *target_yum_rpmdb_indexes = g_file_resolve_relative_path (targetroot, "usr/share/yumdb"); gs_unref_object GFile *yumroot_yumlib = g_file_get_child (yumroot, "var/lib/yum"); gs_unref_object GFileEnumerator *direnum = NULL; direnum = g_file_enumerate_children (legacyrpm_path, "standard::name", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!direnum) goto out; while (TRUE) { const char *name; GFileInfo *file_info; GFile *child; if (!gs_file_enumerator_iterate (direnum, &file_info, &child, cancellable, error)) goto out; if (!file_info) break; name = g_file_info_get_name (file_info); if (g_str_has_prefix (name, "__db.") || strcmp (name, ".dbenv.lock") == 0 || strcmp (name, ".rpm.lock") == 0) { if (!gs_file_unlink (child, cancellable, error)) goto out; } } (void) g_file_enumerator_close (direnum, cancellable, error); g_print ("Placing RPM db in /usr/share/rpm\n"); if (!gs_file_rename (legacyrpm_path, newrpm_path, cancellable, error)) goto out; /* Move the yum database to usr/share/yumdb; disabled for now due * to bad conflict with OSTree's current * one-http-request-per-file. */ #if 0 if (g_file_query_exists (src_yum_rpmdb_indexes, NULL)) { g_print ("Moving %s to %s\n", gs_file_get_path_cached (src_yum_rpmdb_indexes), gs_file_get_path_cached (target_yum_rpmdb_indexes)); if (!gs_file_rename (src_yum_rpmdb_indexes, target_yum_rpmdb_indexes, cancellable, error)) goto out; if (!clean_yumdb_extraneous_files (target_yum_rpmdb_indexes, cancellable, error)) goto out; } #endif /* Remove /var/lib/yum; we don't want it here. */ if (!gs_shutil_rm_rf (yumroot_yumlib, cancellable, error)) goto out; ret = TRUE; out: return ret; }