static void
test_copy_one_file (void)
{
    g_autoptr (GFile) root = NULL;
    g_autoptr (GFile) first_dir = NULL;
    g_autoptr (GFile) second_dir = NULL;
    g_autoptr (GFile) file = NULL;
    g_autoptr (GFile) result_file = NULL;
    g_autolist (GFile) files = NULL;

    create_one_file ("copy");

    root = g_file_new_for_path (g_get_tmp_dir ());
    g_assert_true (root != NULL);

    first_dir = g_file_get_child (root, "copy_first_dir");
    g_assert_true (first_dir != NULL);

    file = g_file_get_child (first_dir, "copy_first_dir_child");
    g_assert_true (file != NULL);
    files = g_list_prepend (files, g_object_ref (file));

    second_dir = g_file_get_child (root, "copy_second_dir");
    g_assert_true (second_dir != NULL);

    nautilus_file_operations_copy_sync (files,
                                        second_dir);

    result_file = g_file_get_child (second_dir, "copy_first_dir_child");
    g_assert_true (g_file_query_exists (result_file, NULL));
    g_assert_true (g_file_query_exists (file, NULL));

    empty_directory_by_prefix (root, "copy");
}
static void
ide_autotools_build_system_discover_file_worker (GTask        *task,
                                                 gpointer      source_object,
                                                 gpointer      task_data,
                                                 GCancellable *cancellable)
{
  GFile *file = task_data;
  GFile *parent;

  g_assert (G_IS_TASK (task));
  g_assert (G_IS_FILE (file));
  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));

  if (is_configure (file) && g_file_query_exists (file, cancellable))
    {
      g_task_return_pointer (task, g_object_ref (file), g_object_unref);
      return;
    }

  parent = g_object_ref (file);

  while (parent != NULL)
    {
      GFile *child;
      GFile *tmp;

      child = g_file_get_child (parent, "configure.ac");
      if (g_file_query_exists (child, cancellable))
        {
          g_task_return_pointer (task, g_object_ref (child), g_object_unref);
          g_clear_object (&child);
          g_clear_object (&parent);
          return;
        }

      child = g_file_get_child (parent, "configure.in");
      if (g_file_query_exists (child, cancellable))
        {
          g_task_return_pointer (task, g_object_ref (child), g_object_unref);
          g_clear_object (&child);
          g_clear_object (&parent);
          return;
        }

      g_clear_object (&child);

      tmp = parent;
      parent = g_file_get_parent (parent);
      g_clear_object (&tmp);
    }

  g_clear_object (&parent);

  g_task_return_new_error (task,
                           G_IO_ERROR,
                           G_IO_ERROR_NOT_FOUND,
                           _("Failed to locate configure.ac"));
}
Пример #3
0
gboolean
directory_has_makefile_am (BasicAutotoolsPlugin *bb_plugin,  GFile *dir)
{
	GFile *file;
	gboolean exists;

	/* We need configure.ac or configure.in too */
	if (bb_plugin->project_root_dir == NULL) return FALSE;

	exists = TRUE;
	file = g_file_get_child (bb_plugin->project_root_dir,  "configure.ac");
	if (!g_file_query_exists (file, NULL))
	{
		g_object_unref (file);
		file =  g_file_get_child (bb_plugin->project_root_dir,  "configure.in");
		if (!g_file_query_exists (file, NULL))
		{
			exists = FALSE;
		}
	}
	g_object_unref (file);

	/* Check for Makefile.am or GNUmakefile.am */
	if (g_file_has_prefix (dir, bb_plugin->project_build_dir))
	{
		/* Check for Makefile.am in source directory not build directory */
		gchar *relative;
		GFile *src_dir;

		relative = g_file_get_relative_path (bb_plugin->project_build_dir, dir);
		src_dir = g_file_get_child (bb_plugin->project_root_dir, relative);
		file = g_file_get_child (src_dir,  "Makefile.am");
		g_object_unref (src_dir);
		g_free (relative);
	}
	else if (g_file_equal (dir, bb_plugin->project_build_dir))
	{
		file = g_file_get_child (bb_plugin->project_root_dir,  "Makefile.am");
	}
	else
	{
		file = g_file_get_child (dir,  "Makefile.am");
	}

	if (!g_file_query_exists (file, NULL))
	{
		g_object_unref (file);
		file =  g_file_get_child (dir, "GNUmakefile.am");
		if (!g_file_query_exists (file, NULL))
		{
			exists = FALSE;
		}
	}
	g_object_unref (file);

	return exists;
}
static char *
rb_find_user_file (const char *dir,
		   const char *name,
		   GError **error)
{
	GError *temp_err = NULL;
	char *srcpath;
	char *destpath;
	GFile *src;
	GFile *dest;
	char *use_path;

	/* if the file exists in the target dir, return the path */
	destpath = g_build_filename (dir, name, NULL);
	dest = g_file_new_for_path (destpath);
	if (g_file_query_exists (dest, NULL) == TRUE) {
		g_object_unref (dest);
		rb_debug ("found user dir path for '%s': %s", name, destpath);
		return destpath;
	}

	/* doesn't exist in the target dir, so try to move it from the .gnome2 dir */
	srcpath = g_build_filename (rb_dot_dir (), name, NULL);
	src = g_file_new_for_path (srcpath);

	if (g_file_query_exists (src, NULL)) {
		g_file_move (src, dest, G_FILE_COPY_NONE, NULL, NULL, NULL, &temp_err);
		if (temp_err != NULL) {
			rb_debug ("failed to move user file '%s' from .gnome2 dir, returning .gnome2 path %s: %s",
				  name, srcpath, temp_err->message);

			use_path = g_file_get_path (src);
			g_set_error (error,
				     temp_err->domain,
				     temp_err->code,
				     _("Unable to move %s to %s: %s"),
				     srcpath, destpath, temp_err->message);
			g_error_free (temp_err);
		} else {
			rb_debug ("moved user file '%s' from .gnome2 dir, returning user dir path %s",
				  name, destpath);
			use_path = g_file_get_path (dest);
		}
	} else {
		rb_debug ("no existing file for '%s', returning user dir path %s", name, destpath);
		use_path = g_file_get_path (dest);
	}

	g_free (srcpath);
	g_free (destpath);

	g_object_unref (src);
	g_object_unref (dest);

	return use_path;
}
Пример #5
0
/**
 * ostree_sysroot_ensure_initialized:
 * @self: Sysroot
 * @cancellable: Cancellable
 * @error: Error
 *
 * Ensure that @self is set up as a valid rootfs, by creating
 * /ostree/repo, among other things.
 */
gboolean
ostree_sysroot_ensure_initialized (OstreeSysroot  *self,
                                   GCancellable   *cancellable,
                                   GError        **error)
{
  gboolean ret = FALSE;
  g_autoptr(GFile) dir = NULL;
  g_autoptr(GFile) ostree_dir = NULL;
  g_autoptr(GFile) repo_dir = NULL;

  ostree_dir = g_file_get_child (self->path, "ostree");
  repo_dir = g_file_get_child (ostree_dir, "repo");
  if (!gs_file_ensure_directory (repo_dir, TRUE, cancellable, error))
    goto out;

  g_clear_object (&dir);
  dir = g_file_get_child (ostree_dir, "deploy");
  if (!gs_file_ensure_directory (dir, TRUE, cancellable, error))
    goto out;

  g_clear_object (&dir);
  dir = ot_gfile_get_child_build_path (ostree_dir, "repo", "objects", NULL);
  if (!g_file_query_exists (dir, NULL))
    {
      glnx_unref_object OstreeRepo *repo = ostree_repo_new (repo_dir);
      if (!ostree_repo_create (repo, OSTREE_REPO_MODE_BARE,
                               cancellable, error))
        goto out;
    }

  ret = TRUE;
 out:
  return ret;
}
Пример #6
0
static void
add_recent_project_row (GtkListBox *recent_project_box, GtkRecentData *recent_project)
{
	GtkBuilder *builder;
	GFile *file;
	GtkWidget *recent_row;
	GtkLabel *project_label, *path_label;
	GError *error;

	error = NULL;
	builder = gtk_builder_new ();
	if (!gtk_builder_add_from_resource (builder, "/org/gnome/anjuta/ui/starter.ui", &error))
	{
		DEBUG_PRINT ("Could not load starter.ui! %s", error->message);
		g_error_free (error);
	}
	else
	{
		file = g_file_new_for_uri (gtk_recent_info_get_uri (recent_project));
		if (g_file_query_exists (file, NULL))
		{
			recent_row = GTK_WIDGET (gtk_builder_get_object (builder, RECENT_ROW));
			project_label = GTK_WIDGET (gtk_builder_get_object (builder, PROJECT_LABEL));
			path_label = GTK_WIDGET (gtk_builder_get_object (builder, PATH_LABEL));
			gtk_label_set_text (project_label, gtk_recent_info_get_display_name(recent_project));
			gtk_label_set_text (path_label, g_file_get_path(file));
			g_object_set_data_full (G_OBJECT (recent_row), URI_KEY, g_file_get_uri(file), g_free);
			gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (recent_row)), recent_row);
			gtk_list_box_insert (recent_project_box, recent_row, -1);
		}
		g_object_unref (file);

	}
	g_object_unref (builder);
}
Пример #7
0
/*
 *
 * XAArchive* lsq_open_archive(gchar *path)
 *
 */
LSQArchive *
lsq_open_archive (
        GFile *file,
        GError **error
    )
{
    LSQArchive *archive = NULL; /*lsq_opened_archive_get_archive(path); */

    g_return_val_if_fail( G_IS_FILE( file ), NULL );

    if ( FALSE == g_file_query_exists( file, NULL ) )
    {
        return NULL;
    }

    if ( NULL == archive )
    {
        archive = lsq_archive_new( file, NULL, error );
        if ( NULL != archive )
        {
            /* FIXME: Shouldn't this be part of lsq_archive_new? */
            lsq_opened_archive_list = g_slist_prepend( lsq_opened_archive_list, archive );
        }
    }

    return archive;
}
Пример #8
0
/*
 * XAArchive* lsq_new_archive(gchar *path, LSQArchiveType type, gboolean overwrite)
 *
 */
LSQArchive *
lsq_new_archive (
        GFile *file,
        const gchar *mime_type,
        gboolean overwrite,
        GError **error
    )
{
    LSQArchive *archive;

    g_return_val_if_fail( G_IS_FILE( file ), NULL );

    if ( TRUE == overwrite )
    {
        g_file_trash( file, NULL, NULL );
    }

    if ( TRUE == g_file_query_exists( file, NULL ) )
    {
        return NULL;
    }

    archive = lsq_archive_new( file, mime_type, error );

    return archive;
}
Пример #9
0
/**
 * pk_offline_auth_invalidate:
 * @error: A #GError or %NULL
 *
 * Invalidates the offline operation. This is normally done when the package
 * cache has been refreshed, or a package listed in the prepared transaction
 * is manually installed or removed.
 *
 * Return value: %TRUE for success, else %FALSE and @error set
 *
 * Since: 0.9.6
 **/
gboolean
pk_offline_auth_invalidate (GError **error)
{
	_cleanup_error_free_ GError *error_local = NULL;
	_cleanup_object_unref_ GFile *file = NULL;

	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	/* cancel the pending update */
	if (!pk_offline_auth_cancel (error))
		return FALSE;

	/* delete the prepared file */
	file = g_file_new_for_path (PK_OFFLINE_PREPARED_FILENAME);
	if (g_file_query_exists (file, NULL) &&
	    !g_file_delete (file, NULL, &error_local)) {
		g_set_error (error,
			     PK_OFFLINE_ERROR,
			     PK_OFFLINE_ERROR_FAILED,
			     "Cannot delete %s: %s",
			     PK_OFFLINE_PREPARED_FILENAME,
			     error_local->message);
		return FALSE;
	}
	return TRUE;
}
Пример #10
0
static gboolean dl_sync_file(mega_node* node, GFile* file, const gchar* remote_path)
{
  GError *local_err = NULL;
  gchar* local_path = g_file_get_path(file);

  if (g_file_query_exists(file, NULL))
  {
    g_printerr("ERROR: File already exists at %s\n", local_path);
    return FALSE;
  }

  g_print("F %s\n", local_path);

  if (!opt_dryrun)
  {
    if (!mega_session_get(s, g_file_get_path(file), remote_path, &local_err))
    {
      if (!opt_noprogress)
        g_print("\r" ESC_CLREOL);

      g_printerr("ERROR: Download failed for %s: %s\n", remote_path, local_err->message);
      g_clear_error(&local_err);
      return FALSE;
    }

    if (!opt_noprogress)
      g_print("\r" ESC_CLREOL);
  }

  return TRUE;
}
Пример #11
0
/**
 * is_read_only:
 * @location: a GFile Object that represents the file to check
 *
 * This method is copied from gedit, file gedit-commands-file.c
 *
 * Returns: False if file is writeable. True if file doesn't exists, is read-only or read-only attribute can't be check
 */
static gboolean
is_read_only (const gchar * filename)
{
  gboolean ret = TRUE;          /* default to read only */
  GFileInfo *info;
  GFile *location;

  location = g_file_new_for_path (filename);

  if (!g_file_query_exists (location, NULL))
    return FALSE;

  info = g_file_query_info (location,
                            G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
                            G_FILE_QUERY_INFO_NONE, NULL, NULL);
  g_object_unref (location);

  if (info != NULL)
    {
      if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
        {
          ret = !g_file_info_get_attribute_boolean (info,
                                                    G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
        }

      g_object_unref (info);
    }

  return ret;
}
static gboolean
record_windows_licenses (gpointer unused)
{
  g_autoptr(GFile) tables = g_file_new_for_path (ACPI_TABLES_PATH);
  guint32 licenses = 0;
  gsize i;

  for (i = 0; i < G_N_ELEMENTS (windows_license_tables); i++)
    {
      const gchar *table_name = windows_license_tables[i];
      g_autoptr(GFile) table = g_file_get_child (tables, table_name);
      gboolean present = g_file_query_exists (table, NULL);

      g_debug ("ACPI table %s is %s",
               table_name,
               present ? "present" : "absent");

      if (present)
        licenses |= 1 << i;
    }

  emtr_event_recorder_record_event (emtr_event_recorder_get_default (),
                                    WINDOWS_LICENSE_TABLES_EVENT,
                                    g_variant_new_uint32 (licenses));

  return G_SOURCE_REMOVE;
}
Пример #13
0
/**
 * validate_file:
 **/
static gboolean
validate_file (gchar *fname, gboolean pretty)
{
	GFile *file;
	gboolean ret;
	gboolean errors_found;
	AsValidator *validator;
	GList *issues;

	file = g_file_new_for_path (fname);
	if (!g_file_query_exists (file, NULL)) {
		g_print ("File '%s' does not exist.", fname);
		g_print ("\n");
		g_object_unref (file);
		return FALSE;
	}

	validator = as_validator_new ();
	ret = as_validator_validate_file (validator, file);
	issues = as_validator_get_issues (validator);

	errors_found = process_report (issues, pretty);
	if (!ret)
		errors_found = TRUE;

	g_list_free (issues);
	g_object_unref (file);
	g_object_unref (validator);
	return !errors_found;
}
Пример #14
0
void
completion_append_string(const gchar *filename, const gchar *text)
{
	char *path;
	GFile *file;

	g_assert(filename != NULL);
	g_assert(text != NULL);

	path = g_build_filename(pathbuilder_get_user_application_directory(), G_DIR_SEPARATOR_S, filename, NULL);
	file = g_file_new_for_path(path);

	g_debug("Testing if file does exist: \"%s\"", path);

	if(g_file_query_exists(file, NULL))
	{
		_completion_update_text(file, text);
	}
	else
	{
		_completion_create_initial_file(file, text);
	}

	g_object_unref(file);
	g_free(path);
}
Пример #15
0
gchar *albumart_get_album_art_uri(const gchar *album)
{
    gchar *file_uri;
    gchar *file_path;
    gchar *album_key;
    GFile *file;

    if (util_tracker_value_is_unknown(album)) {
        return NULL;
    } else {
        album_key = g_strdup(album);
    }

    /* Get the path to the album-art */
    file_path = hildon_albumart_get_path(NULL, album_key, "album");
    file_uri = g_filename_to_uri(file_path, NULL, NULL);
    g_free(file_path);

    /* Check if file exists */
    file = g_file_new_for_uri(file_uri);
    if (!g_file_query_exists(file, NULL)) {
        g_free(file_uri);
        file_uri = NULL;
    }
    g_object_unref(file);
    g_free(album_key);

    return file_uri;
}
Пример #16
0
gchar*
rookie_misc_get_category_file_path ()
{
	GError *error = NULL;
	gchar *dir	  = get_rookie_user_data_dir ();
	GFile *fil	  = g_file_new_for_path (dir);
	gchar *spath  = g_build_filename (PACKAGE_DATA_DIR, "rookie",
									  "categories.ini", NULL);
	GFile *source = g_file_new_for_path (spath);
	GFile *dest	  = g_file_get_child (fil, "categories.ini");

	if (!g_file_query_exists (dest, NULL) &&
		!g_file_copy (source, dest, G_FILE_COPY_NONE, NULL, NULL, NULL, &error))
		handle_error (error);

	gchar *ret = g_build_filename (dir, "categories.ini", NULL);

	g_object_unref (source);
	g_object_unref (dest);
	g_object_unref (fil);
	g_free (spath);
	g_free (dir);

	return ret;
}
Пример #17
0
static GFileEnumerator *
gnac_profiles_mgr_get_default_profiles_enumerator(void)
{
  GFile *dir = g_file_new_for_path(PKGDATADIR "/profiles/default");
  if (!g_file_query_exists(dir, NULL)) {
    libgnac_warning("%s", _("Unable to find the default profiles directory"));
    return NULL;
  }
  
  GError *error = NULL;
  GFileEnumerator *files = g_file_enumerate_children(dir,
      G_FILE_ATTRIBUTE_STANDARD_NAME ","
      G_FILE_ATTRIBUTE_STANDARD_TYPE,
      G_FILE_QUERY_INFO_NONE, NULL, &error);
  if (!files) {
    libgnac_warning("%s: %s",
        _("Unable to browse the default profiles directory"),
        error->message);
    g_clear_error(&error);
    g_object_unref(dir);
    return NULL;
  }

  g_object_unref(dir);

  return files;
}
static gboolean
copy_modules (const char    *release,
              GCancellable  *cancellable,
              GError       **error)
{
  gboolean ret = FALSE;
  ot_lobj GFile *src_modules_file = NULL;
  ot_lobj GFile *dest_modules_parent = NULL;
  ot_lobj GFile *dest_modules_file = NULL;
  
  src_modules_file = ot_gfile_from_build_path ("/lib/modules", release, NULL);
  dest_modules_file = ot_gfile_from_build_path (opt_ostree_dir, "modules", release, NULL);
  dest_modules_parent = g_file_get_parent (dest_modules_file);
  if (!ot_gfile_ensure_directory (dest_modules_parent, FALSE, error))
    goto out;

  if (!g_file_query_exists (dest_modules_file, cancellable))
    {
      if (!ot_gio_shutil_cp_al_or_fallback (src_modules_file, dest_modules_file, cancellable, error))
        goto out;
    }
      
  ret = TRUE;
 out:
  if (error)
    g_prefix_error (error, "Error copying kernel modules: ");
  return ret;
}
Пример #19
0
void
codeslayer_utils_save_gobjects (GList       *objects,
                                const gchar *file_path, 
                                gpointer     name, ...)
{
  gchar *contents;
  GHashTable *table;
  va_list var_arg;
  GFile *file;

  file = g_file_new_for_path (file_path);
  if (!g_file_query_exists (file, NULL))
    {
      GFileIOStream *stream;           
      stream = g_file_create_readwrite (file, G_FILE_CREATE_NONE, NULL, NULL);
      if (g_io_stream_close (G_IO_STREAM (stream), NULL, NULL))
        g_object_unref (stream);
    }

  va_start (var_arg, name);
  table = codeslayer_xml_create_hashtable (var_arg);
  va_end (var_arg);
  
  contents = codeslayer_xml_serialize_gobjects (objects, name, table);

  g_file_set_contents (file_path, contents, -1, NULL);

  g_object_unref (file);
  g_free (contents);
  codeslayer_xml_free_hashtable (table);
}
Пример #20
0
AnjutaProjectNode*
dir_group_node_new (GFile *file, GObject *emitter)
{
	AnjutaDirGroupNode *group = NULL;

	group = g_object_new (ANJUTA_TYPE_DIR_GROUP_NODE, NULL);
	group->base.type = ANJUTA_PROJECT_GROUP;
	group->base.native_properties = NULL;
	group->base.custom_properties = NULL;
	group->base.file = g_object_ref (file);
	group->base.name = NULL;
	group->base.state = ANJUTA_PROJECT_CAN_ADD_GROUP |
						ANJUTA_PROJECT_CAN_ADD_SOURCE |
						ANJUTA_PROJECT_CAN_REMOVE |
						ANJUTA_PROJECT_REMOVE_FILE;

	group->emitter = emitter;

	/* Connect monitor if file exist */
	if (g_file_query_exists (file, NULL))
	{
		group->monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);

		g_signal_connect (G_OBJECT (group->monitor),
							"changed",
							G_CALLBACK (on_file_changed),
							group);
	}

	return ANJUTA_PROJECT_NODE (group);
}
Пример #21
0
static GKeyFile *
xviewer_print_get_key_file (void)
{
    GKeyFile *key_file;
    GError *error = NULL;
    gchar *filename;
    GFile *file;
    const gchar *dot_dir = xviewer_util_dot_dir ();

    filename = g_build_filename (dot_dir, XVIEWER_PRINT_SETTINGS_FILE, NULL);

    file = g_file_new_for_path (filename);
    key_file = g_key_file_new ();

    if (g_file_query_exists (file, NULL)) {
        g_key_file_load_from_file (key_file, filename,
                                   G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
                                   &error);
        if (error) {
            g_warning ("Error loading print settings file: %s", error->message);
            g_error_free (error);
            g_object_unref (file);
            g_free (filename);
            g_key_file_free (key_file);
            return NULL;
        }
    }

    g_object_unref (file);
    g_free (filename);

    return key_file;
}
Пример #22
0
/**
 * mcm_utils_mkdir_and_copy:
 **/
gboolean
mcm_utils_mkdir_and_copy (GFile *source, GFile *destination, GError **error)
{
	gboolean ret;
	GFile *parent;

	g_return_val_if_fail (source != NULL, FALSE);
	g_return_val_if_fail (destination != NULL, FALSE);

	/* get parent */
	parent = g_file_get_parent (destination);

	/* create directory */
	if (!g_file_query_exists (parent, NULL)) {
		ret = g_file_make_directory_with_parents (parent, NULL, error);
		if (!ret)
			goto out;
	}

	/* do the copy */
	ret = g_file_copy (source, destination, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, error);
	if (!ret)
		goto out;
out:
	g_object_unref (parent);
	return ret;
}
Пример #23
0
static gboolean
prepare_root_ssh (GCancellable   *cancellable,
                  GError        **error)
{
  gboolean ret = FALSE;
  GFile *root_ssh_path = g_file_new_for_path ("/root/.ssh");

  if (!g_file_query_exists (root_ssh_path, NULL))
    {
      if (!g_file_make_directory (root_ssh_path, cancellable, error))
        goto out;

      if (!gs_file_chmod (root_ssh_path, 0700, cancellable, error))
        goto out;

      /* Ignore errors here to be simple, otherwise we'd have to link
       * to libselinux etc.
       */
      (void) gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
                                            cancellable, error,
                                            "restorecon",
                                            gs_file_get_path_cached (root_ssh_path),
                                            NULL);
    }

  ret = TRUE;
 out:
  return ret;
}
Пример #24
0
static gboolean
load_css_from_resource (GApplication *application,
                        GtkCssProvider *provider,
                        gboolean theme)
{
  const char *base_path;
  gs_free char *uri;
  gs_unref_object GFile *file;
  gs_free_error GError *error = NULL;

  base_path = g_application_get_resource_base_path (application);

  if (theme) {
    gs_free char *str, *theme_name;

    g_object_get (gtk_settings_get_default (), "gtk-theme-name", &str, NULL);
    theme_name = g_ascii_strdown (str, -1);
    uri = g_strdup_printf ("resource://%s/css/%s/terminal.css", base_path, theme_name);
  } else {
    uri = g_strdup_printf ("resource://%s/css/terminal.css", base_path);
  }

  file = g_file_new_for_uri (uri);
  if (!g_file_query_exists (file, NULL /* cancellable */))
    return FALSE;

  if (!gtk_css_provider_load_from_file (provider, file, &error))
    g_assert_no_error (error);

  return TRUE;
}
Пример #25
0
static void on_file_read_ready (GObject * object, GAsyncResult * res, gpointer data)
{
	GError *error = NULL;
	GDownloadable *download = G_DOWNLOADABLE (data);
	GioDownload   *gio_download = GIO_DOWNLOAD (data);
	g_assert (download != NULL);
	
	gio_download->priv->input = g_file_read_finish (G_FILE(object), res, &error); 
	handle_critical_error (error);
	
	if (gio_download->priv->input == NULL) {
		// TODO: Error details
		g_downloadable_set_status (download, G_DOWNLOADABLE_NETWORK_ERROR);
	} else {
		if (g_seekable_can_seek(G_SEEKABLE(gio_download->priv->input))
			&& g_file_query_exists (download->priv->local_file, NULL)) {
			//g_message ("appeding file ...\n");
			g_file_append_to_async (download->priv->local_file, 0,G_PRIORITY_DEFAULT,
									NULL, on_file_append_to_ready, download); 
		} else {
			//g_message ("replacing file ...\n");
			g_file_replace_async (download->priv->local_file, NULL, FALSE, 0, G_PRIORITY_DEFAULT,
								  NULL, on_file_replace_ready,  download);
		}
		g_downloadable_set_status (download, G_DOWNLOADABLE_DOWNLOADING);
	}
}
Пример #26
0
/**
 * fu_provider_schedule_update:
 **/
static gboolean
fu_provider_schedule_update (FuProvider *provider,
			     FuDevice *device,
			     GBytes *blob_cab,
			     GError **error)
{
	gchar tmpname[] = {"XXXXXX.cap"};
	guint i;
	g_autofree gchar *dirname = NULL;
	g_autofree gchar *filename = NULL;
	g_autoptr(FuDevice) device_tmp = NULL;
	g_autoptr(FuPending) pending = NULL;
	g_autoptr(GFile) file = NULL;

	/* id already exists */
	pending = fu_pending_new ();
	device_tmp = fu_pending_get_device (pending, fu_device_get_id (device), NULL);
	if (device_tmp != NULL) {
		g_set_error (error,
			     FWUPD_ERROR,
			     FWUPD_ERROR_ALREADY_PENDING,
			     "%s is already scheduled to be updated",
			     fu_device_get_id (device));
		return FALSE;
	}

	/* create directory */
	dirname = g_build_filename (LOCALSTATEDIR, "lib", "fwupd", NULL);
	file = g_file_new_for_path (dirname);
	if (!g_file_query_exists (file, NULL)) {
		if (!g_file_make_directory_with_parents (file, NULL, error))
			return FALSE;
	}

	/* get a random filename */
	for (i = 0; i < 6; i++)
		tmpname[i] = g_random_int_range ('A', 'Z');
	filename = g_build_filename (dirname, tmpname, NULL);

	/* just copy to the temp file */
	fu_provider_set_status (provider, FWUPD_STATUS_SCHEDULING);
	if (!g_file_set_contents (filename,
				  g_bytes_get_data (blob_cab, NULL),
				  g_bytes_get_size (blob_cab),
				  error))
		return FALSE;

	/* schedule for next boot */
	g_debug ("schedule %s to be installed to %s on next boot",
		 filename, fu_device_get_id (device));
	fu_device_set_metadata (device, FU_DEVICE_KEY_FILENAME_CAB, filename);

	/* add to database */
	if (!fu_pending_add_device (pending, device, error))
		return FALSE;

	/* next boot we run offline */
	return fu_provider_offline_setup (error);
}
Пример #27
0
static void test_fetch_git(void) {
    Recipe recipe = {"1","1","1","RHEL-6.0","RedHatEnterpriseLinux6","Server","x86_64",NULL,NULL,NULL};
    Task task = {
        "456",
        &recipe,
        soup_uri_new("http://localhost:8000/recipes/123/tasks/456/"),
        "/distribution/install",
        g_dir_make_tmp("restraint_test_task_XXXXXX", NULL),
        TASK_FETCH_UNPACK,
        { .url = soup_uri_new("git://localhost/repo1?master#restraint/sanity/fetch_git") },
        NULL,
        NULL,
        FALSE,
        FALSE,
        NULL,
        FALSE,
        NULL,
        0,
    };
    restraint_task_run(&task);

    // assert it's on disk
    GFile *base = g_file_new_for_path(task.path);
    GFile *file = g_file_get_child(base, "Makefile");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    file = g_file_get_child(base, "PURPOSE");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    file = g_file_get_child(base, "metadata");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    file = g_file_get_child(base, "runtest.sh");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    g_object_unref(base);

    // assert this is not rhts_compat task
    g_assert(task.rhts_compat == FALSE);

    soup_uri_free(task.task_uri);
    g_free(task.path);
    g_strfreev(task.entry_point);
    g_list_free_full(task.dependencies, (GDestroyNotify) g_free);
    soup_uri_free(task.fetch.url);
}
Пример #28
0
static gboolean
gs_plugin_fwupd_install (GsPlugin *plugin,
			 GsApp *app,
			 GCancellable *cancellable,
			 GError **error)
{
	GsPluginData *priv = gs_plugin_get_data (plugin);
	const gchar *device_id;
	FwupdInstallFlags install_flags = 0;
	GFile *local_file;
	g_autofree gchar *filename = NULL;

	/* not set */
	local_file = gs_app_get_local_file (app);
	if (local_file == NULL) {
		g_set_error (error,
			     GS_PLUGIN_ERROR,
			     GS_PLUGIN_ERROR_FAILED,
			     "not enough data for fwupd %s",
			     filename);
		return FALSE;
	}

	/* file does not yet exist */
	filename = g_file_get_path (local_file);
	if (!g_file_query_exists (local_file, cancellable)) {
		const gchar *uri = gs_fwupd_app_get_update_uri (app);
		gs_app_set_state (app, AS_APP_STATE_INSTALLING);
		if (!gs_plugin_download_file (plugin, app, uri, filename,
					      cancellable, error))
			return FALSE;
	}

	/* limit to single device? */
	device_id = gs_fwupd_app_get_device_id (app);
	if (device_id == NULL)
		device_id = FWUPD_DEVICE_ID_ANY;

	/* set the last object */
	g_set_object (&priv->app_current, app);

	/* only offline supported */
	if (gs_app_get_metadata_item (app, "fwupd::OnlyOffline") != NULL)
		install_flags |= FWUPD_INSTALL_FLAG_OFFLINE;

	gs_app_set_state (app, AS_APP_STATE_INSTALLING);
	if (!fwupd_client_install (priv->client, device_id,
				   filename, install_flags,
				   cancellable, error)) {
		gs_plugin_fwupd_error_convert (error);
		gs_app_set_state_recover (app);
		return FALSE;
	}

	/* delete the file from the cache */
	gs_app_set_state (app, AS_APP_STATE_INSTALLED);
	return g_file_delete (local_file, cancellable, error);
}
static GMarkupParseContext *
create_parser_context (GESBaseXmlFormatter * self, const gchar * uri,
    GError ** error)
{
  gsize xmlsize;
  GFile *file = NULL;
  gchar *xmlcontent = NULL;
  GMarkupParseContext *parsecontext = NULL;
  GESBaseXmlFormatterClass *self_class =
      GES_BASE_XML_FORMATTER_GET_CLASS (self);

  GError *err = NULL;

  GST_DEBUG_OBJECT (self, "loading xml from %s", uri);

  file = g_file_new_for_uri (uri);

  /* TODO Handle GCancellable */
  if (!g_file_query_exists (file, NULL)) {
    err = g_error_new (GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED,
        "Invalid URI: \"%s\"", uri);
    goto failed;
  }

  if (!g_file_load_contents (file, NULL, &xmlcontent, &xmlsize, NULL, &err))
    goto failed;

  if (g_strcmp0 (xmlcontent, "") == 0)
    goto failed;

  parsecontext = g_markup_parse_context_new (&self_class->content_parser,
      G_MARKUP_TREAT_CDATA_AS_TEXT, self, NULL);

  if (g_markup_parse_context_parse (parsecontext, xmlcontent, xmlsize,
          &err) == FALSE)
    goto failed;

  if (!g_markup_parse_context_end_parse (parsecontext, &err))
    goto failed;


done:
  g_free (xmlcontent);
  g_object_unref (file);

  return parsecontext;

failed:
  GST_WARNING ("failed to load contents from \"%s\"", uri);
  g_propagate_error (error, err);

  if (parsecontext) {
    g_markup_parse_context_free (parsecontext);
    parsecontext = NULL;
  }

  goto done;
}
static void
test_copy_directories_medium_undo (void)
{
    g_autoptr (GFile) root = NULL;
    g_autoptr (GFile) file = NULL;
    g_autoptr (GFile) dir = NULL;
    g_autolist (GFile) files = NULL;
    gchar *file_name;

    create_multiple_directories ("copy", 1000);

    root = g_file_new_for_path (g_get_tmp_dir ());
    g_assert_true (root != NULL);

    for (int i = 0; i < 1000; i++)
    {
        file_name = g_strdup_printf ("copy_file_%i", i);
        file = g_file_get_child (root, file_name);
        g_free (file_name);
        g_assert_true (file != NULL);
        files = g_list_prepend (files, g_object_ref (file));
    }

    dir = g_file_get_child (root, "copy_dir");
    g_assert_true (dir != NULL);

    nautilus_file_operations_copy_sync (files,
                                        dir);

    test_operation_undo ();

    for (int i = 0; i < 1000; i++)
    {
        file_name = g_strdup_printf ("copy_file_%i", i);
        file = g_file_get_child (dir, file_name);
        g_assert_false (g_file_query_exists (file, NULL));
        file = g_file_get_child (root, file_name);
        g_free (file_name);
        g_assert_true (g_file_query_exists (file, NULL));
    }

    g_assert_true (g_file_query_exists (dir, NULL));

    empty_directory_by_prefix (root, "copy");
}