/**
 * rb_uri_create_parent_dirs:
 * @uri: a URI for which to create parent directories
 * @error: returns error information
 *
 * Ensures that all parent directories of @uri exist so that
 * @uri itself can be created directly.
 *
 * Return value: %TRUE if successful
 */
gboolean
rb_uri_create_parent_dirs (const char *uri, GError **error)
{
	GFile *file;
	GFile *parent;
	gboolean ret;

	/* ignore internal URI schemes */
	if (g_str_has_prefix (uri, "xrb")) {
		return TRUE;
	}

	file = g_file_new_for_uri (uri);
	parent = g_file_get_parent (file);
	g_object_unref (file);
	if (parent == NULL) {
		/* now what? */
		return TRUE;
	}

	ret = check_file_is_directory (parent, error);
	if (ret == FALSE && *error == NULL) {
		ret = g_file_make_directory_with_parents (parent, NULL, error);
	}

	g_object_unref (parent);
	return ret;
}
示例#2
0
gboolean
project_create_files_and_dirs (Project *proj, GError **error)
{
    GFile *file = g_file_new_for_path (proj->file_name);
    GFile *dir = g_file_new_for_path (proj->proj_dir);

    if (!g_file_make_directory_with_parents (dir, NULL, error))
    {
        if (error && !g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_EXISTS))
             return FALSE;

        else if (error)
        {
            g_error_free (*error);
            error = NULL;
        }
    }

    if (!project_write (proj, error))
         return FALSE;

    gchar *main_file = project_get_main_file (proj);
    g_file_set_contents (main_file, "", -1, NULL);
    g_free (main_file);

    g_object_unref (file);
    g_object_unref (dir);
    return TRUE;
}
static gchar *
ensure_dest_path (GFile *file,
                  gint icon_size)
{
  gchar *str, *str2, *size_string, *dest_path;
  GFile *dest_file, *dest_dir, *tmp;

  str = g_file_get_relative_path (gnome_dir, file);
  tmp = g_file_resolve_relative_path (hc_dir, str);
  g_free (str);

  str = g_file_get_path (tmp);
  size_string = g_strdup_printf ("%dx%d", icon_size, icon_size);
  str2 = replace_str (str, "-symbolic.svg", ".png");
  dest_path = replace_str (str2, "scalable", size_string);

  dest_file = g_file_new_for_path (dest_path);
  dest_dir = g_file_get_parent (dest_file);

  g_file_make_directory_with_parents (dest_dir, NULL, NULL);

  g_object_unref (dest_file);
  g_object_unref (dest_dir);
  g_object_unref (tmp);
  g_free (str);
  g_free (size_string);

  return dest_path;
}
示例#4
0
void on_switch_startup_active_notify(GtkSwitch *widget,
				     gpointer data)
{
  gchar *folder_dir, *startup_dir, *desktop_dir;
  GFile *folder_file, *startup_file, *desktop_file;
  
  folder_dir = g_build_filename(g_get_home_dir(), ".config", "autostart", NULL);
  startup_dir = g_build_filename(g_get_home_dir(), ".config",
                                 "autostart", "acal.desktop", NULL);
  desktop_dir = g_build_filename(DATADIR, "applications", "acal.desktop", NULL);
  
  folder_file = g_file_new_for_path(folder_dir);
  startup_file = g_file_new_for_path(startup_dir);
  desktop_file = g_file_new_for_path(desktop_dir);
  
  /* create startup folder if not exists */
  g_file_make_directory_with_parents(folder_file , NULL, NULL);
  
  /* copy acal.desktop to autostart dir on activate autostart */
  if(gtk_switch_get_active(widget))
    g_file_copy(desktop_file, startup_file, G_FILE_COPY_NONE,
		NULL, NULL, NULL, NULL);
  else
    g_file_delete(startup_file, NULL, NULL);
}
示例#5
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;
}
示例#6
0
static const char *
get_output_dir (void)
{
  static const char *output_dir = NULL;
  GError *error = NULL;

  if (output_dir)
    return output_dir;

  if (arg_output_dir)
    {
      GFile *file = g_file_new_for_commandline_arg (arg_output_dir);
      output_dir = g_file_get_path (file);
      g_object_unref (file);
    }
  else
    {
      output_dir = g_get_tmp_dir ();
    }

  if (!g_file_test (output_dir, G_FILE_TEST_EXISTS))
    {
      GFile *file;

      file = g_file_new_for_path (output_dir);
      g_assert (g_file_make_directory_with_parents (file, NULL, &error));
      g_assert_no_error (error);
      g_object_unref (file);
    }

  return output_dir;
}
示例#7
0
gboolean
photos_glib_make_directory_with_parents (GFile *file, GCancellable *cancellable, GError **error)
{
  GError *local_error = NULL;
  gboolean ret_val;

  g_return_val_if_fail (G_IS_FILE (file), FALSE);
  g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  ret_val = g_file_make_directory_with_parents (file, cancellable, &local_error);
  if (local_error != NULL)
    {
      if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
        {
          g_clear_error (&local_error);
          ret_val = TRUE;
        }
    }

  if (local_error != NULL)
    g_propagate_error (error, local_error);

  return ret_val;
}
gboolean
rb_uri_create_parent_dirs (const char *uri, GError **error)
{
	GFile *file;
	GFile *parent;
	gboolean ret;
#if !GLIB_CHECK_VERSION(2,17,1)
	GError *l_error = NULL;
#endif

	file = g_file_new_for_uri (uri);
	parent = g_file_get_parent (file);
	g_object_unref (file);
	if (parent == NULL) {
		/* now what? */
		return TRUE;
	}

#if GLIB_CHECK_VERSION(2,17,1)
	ret = check_file_is_directory (parent, error);
	if (ret == FALSE && *error == NULL) {
		ret = g_file_make_directory_with_parents (parent, NULL, error);
	}
#else
	ret = create_parent_dirs (parent, &l_error);

	if (l_error != NULL) {
		g_propagate_error (error, l_error);
	}
#endif
	g_object_unref (parent);
	return ret;
}
示例#9
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);
}
示例#10
0
int
main (int argc, char *argv[])
{
  GError *error;
  GOptionContext *context;
  GFile *file;
  
  setlocale (LC_ALL, "");

  g_type_init ();
  
  error = NULL;
  context = g_option_context_new ("- delete files");
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_parse (context, &argc, &argv, &error);
  g_option_context_free (context);

  if (error != NULL)
    {
      g_printerr ("Error parsing commandline options: %s\n", error->message);
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."),
                  g_get_prgname ());
      g_printerr ("\n");
      g_error_free(error);
      return 1;
    }
  
  if (argc > 1)
    {
      int i;
      
      for (i = 1; i < argc; i++) 
        {
	  file = g_file_new_for_commandline_arg (argv[i]);
          error = NULL;
          if (parent)
            {
               if (!g_file_make_directory_with_parents (file, NULL, &error))
	        {
	          g_print ("Error creating directory: %s\n", error->message);
	          g_error_free (error);
	        } 
            }
          else
            {
	      if (!g_file_make_directory (file, NULL, &error))
	        {
	          g_print ("Error creating directory: %s\n", error->message);
	          g_error_free (error);
	        }
              g_object_unref (file);
            }
        }
    }

  return 0;
}
ScLocalStorageManager* sc_local_storage_manager_new(const gchar *url) {
  ScLocalStorageManager *manager = g_new0(ScLocalStorageManager, 1);
  SoupURI *uri = soup_uri_new(url);
  GString *filename = g_string_new(NULL);
  const gchar *host = soup_uri_get_host(uri);
  const gchar *path = soup_uri_get_path(uri);
  const gchar *query = soup_uri_get_query(uri);
  const gchar *fragment = soup_uri_get_fragment(uri);
  GFile *parent = NULL;
  GError *error = NULL;

  g_string_append_printf(filename, "%s/%s", host, path);
			 
  if(url[strlen(url) - 1] == '/' || g_strcmp0("/", path) == 0)
    g_string_append(filename, "/index.html");
  
  if(query) g_string_append_printf(filename, "/%s\n", query);
  if(fragment) g_string_append_printf(filename, "#%s\n", fragment);
  manager->file = g_file_new_for_commandline_arg(filename->str);
  g_string_free(filename, TRUE);

  if(g_file_query_exists(manager->file, NULL)) {
    g_file_delete(manager->file, NULL, &error);
    if(error && !g_error_matches(error, G_IO_ERROR,G_IO_ERROR_EXISTS)) {
      g_critical(G_STRLOC ": %d : %s", error->code, error->message);
      g_error_free(error);
      g_object_unref(parent);
      g_object_unref(manager->file);
      g_free(manager);
      return NULL;
    }
  }

  parent = g_file_get_parent(manager->file);
  g_file_make_directory_with_parents(parent, NULL, &error);
  if(error && !g_error_matches(error, G_IO_ERROR,G_IO_ERROR_EXISTS)) {
    g_critical(G_STRLOC ": %d : %s", error->code, error->message);
    g_error_free(error);
    g_object_unref(parent);
    g_object_unref(manager->file);
    g_free(manager);
    return NULL;
  }

  error = NULL;
  manager->ostream = g_file_create(manager->file, G_FILE_CREATE_NONE, NULL, &error);
  if(error) {
    g_critical(G_STRLOC ": %d : %s", error->code, error->message);
    g_error_free(error);
    g_object_unref(parent);
    g_object_unref(manager->file);
    g_free(manager);
    return NULL;
  }
  return manager;
}
示例#12
0
/**
 * cd_main_mkdir_with_parents:
 **/
gboolean
cd_main_mkdir_with_parents (const gchar *filename, GError **error)
{
	/* ensure desination exists */
	if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
		g_autoptr(GFile) file = NULL;
		file = g_file_new_for_path (filename);
		return g_file_make_directory_with_parents (file, NULL, error);
	}
	return TRUE;
}
示例#13
0
static gchar*
get_rookie_user_data_dir ()
{
	gchar *dir	= g_build_filename (g_get_user_data_dir (), "rookie", NULL);
	GFile *fil  = g_file_new_for_path (dir);
	GError *error = NULL;
	if (!g_file_query_exists (fil, NULL) &&
		!g_file_make_directory_with_parents (fil, NULL, &error))
		handle_critical_error (error);

	g_object_unref (fil);
	return dir;
}
示例#14
0
/**
 * hif_db_create_dir:
 **/
static gboolean
hif_db_create_dir(const gchar *dir, GError **error)
{
    g_autoptr(GFile) file = NULL;

    /* already exists */
    if (g_file_test(dir, G_FILE_TEST_IS_DIR))
        return TRUE;

    /* need to create */
    g_debug("creating %s", dir);
    file = g_file_new_for_path(dir);
    return g_file_make_directory_with_parents(file, NULL, error);
}
示例#15
0
/* Release->Open Materials Folder */
void
action_open_materials_folder(GtkAction *action, I7Story *story)
{
	GError *error = NULL;
	gchar *uri;
	GFile *materials_file = i7_story_get_materials_file(story);

	/* Prompt the user to create the folder if it doesn't exist */
	if(!g_file_query_exists(materials_file, NULL)) {
		/* TRANSLATORS: Release->Open Materials Folder */
		GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(story),
			GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION,
			GTK_BUTTONS_OK_CANCEL, _("Could not find Materials folder"));
		gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
			_("At the moment, this project has no Materials folder - a "
			"convenient place to put figures, sounds, manuals, hints or other "
			"matter to be packaged up with a release.\n\nWould you like to "
			"create one?"));
		gint response = gtk_dialog_run(GTK_DIALOG(dialog));
		gtk_widget_destroy(dialog);
		if(response == GTK_RESPONSE_OK) {
			if(!g_file_make_directory_with_parents(materials_file, NULL, &error)) {
				/* shouldn't already exist, so don't ignore G_IO_ERROR_EXISTS */
				IO_ERROR_DIALOG(GTK_WINDOW(story), materials_file, error, _("creating Materials folder"));
				goto finally;
			}
			file_set_custom_icon(materials_file, "application-x-inform-materials");
		} else
			goto finally;
	}

	if(g_file_query_file_type(materials_file, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY) {
		/* Odd; the Materials folder is a file. We open the containing path so
		 the user can see this and correct it if they like. */
		GFile *parent = g_file_get_parent(materials_file);
		uri = g_file_get_uri(parent);
		g_object_unref(parent);
	} else {
		uri = g_file_get_uri(materials_file);
	}

	/* TRANSLATORS: this string is used in error messages and should fit in the
	pattern "We couldn't open a program to show ___" */
	show_uri_externally(uri, GTK_WINDOW(story), _("the Materials folder"));

	g_free(uri);
finally:
	g_object_unref(materials_file);
}
static gboolean
update_counter (const gchar  *counter_path,
                GHashTable   *new_progresses  /* (element-type filename gint32) */,
                GError      **error)
{
  g_autoptr(GFile) counter_file = g_file_new_for_path (counter_path);
  g_autoptr(GFile) parent = g_file_get_parent (counter_file);
  g_autoptr(GKeyFile) counter_keyfile = g_key_file_new ();
  GHashTableIter iter;
  gpointer key, value;
  g_autoptr(GError) local_error = NULL;

  /* Ensure that the directory and the key file are created */
  if (!g_file_make_directory_with_parents (parent, NULL, &local_error))
    {
      if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
        {
          g_propagate_error (error, g_steal_pointer (&local_error));
          return FALSE;
        }

      g_clear_error (&local_error);
    }

  if (!g_key_file_load_from_file (counter_keyfile,
                                  counter_path,
                                  G_KEY_FILE_NONE,
                                  &local_error))
    {
      if (!g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
        {
          g_propagate_error (error, g_steal_pointer (&local_error));
          return FALSE;
        }

      g_clear_error (&local_error);
    }

  g_hash_table_iter_init (&iter, new_progresses);

  while (g_hash_table_iter_next (&iter, &key, &value))
    g_key_file_set_int64 (counter_keyfile, key, "Progress", GPOINTER_TO_INT (value));

  if (!g_key_file_save_to_file (counter_keyfile, counter_path, error))
    return FALSE;

  return TRUE;
}
示例#17
0
static ExtractTest*
extract_test_new (const char *test_name)
{
  ExtractTest *extract_test;
  g_autoptr (GFile) work_directory = NULL;
  GFile *input;
  GFile *output;
  GFile *reference;

  work_directory = g_file_get_child (extract_tests_dir, test_name);
  if (g_file_query_file_type (work_directory, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY) {
    g_printerr ("%s: work directory does not exist", test_name);

    return NULL;
  }

  input = g_file_get_child (work_directory, "input");
  reference = g_file_get_child (work_directory, "reference");

  if (g_file_query_file_type (input, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY ||
      g_file_query_file_type (reference, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY) {
    g_printerr ("%s: input or output directory does not exist\n", test_name);

    g_object_unref (input);

    return NULL;
  }

  output = g_file_get_child (work_directory, "output");

  remove_directory (output);

  g_file_make_directory_with_parents (output, NULL, NULL);

  extract_test = g_new0 (ExtractTest, 1);

  extract_test->input = input;
  extract_test->reference = reference;
  extract_test->output = output;

  extract_test->unmatched_files = g_hash_table_new_full (g_str_hash,
                                                         g_str_equal,
                                                         g_free,
                                                         g_object_unref);

  return extract_test;
}
示例#18
0
static bool
copy_source_file_to_coverage_output(GFile   *source_file,
                                    GFile   *destination_file,
                                    GError **error)
{
    /* We need to recursively make the directory we
     * want to copy to, as g_file_copy doesn't do that */
    GjsAutoUnref<GFile> destination_dir = g_file_get_parent(destination_file);
    if (!g_file_make_directory_with_parents(destination_dir, NULL, error)) {
        if (!g_error_matches(*error, G_IO_ERROR, G_IO_ERROR_EXISTS))
            return false;
        g_clear_error(error);
    }

    return g_file_copy(source_file, destination_file, G_FILE_COPY_OVERWRITE,
                       nullptr, nullptr, nullptr, error);
}
示例#19
0
/**
 * mcm_utils_mkdir_with_parents:
 **/
gboolean
mcm_utils_mkdir_with_parents (const gchar *filename, GError **error)
{
	gboolean ret;
	GFile *file = NULL;

	/* ensure desination exists */
	ret = g_file_test (filename, G_FILE_TEST_EXISTS);
	if (!ret) {
		file = g_file_new_for_path (filename);
		ret = g_file_make_directory_with_parents (file, NULL, error);
		if (!ret)
			goto out;
	}
out:
	if (file != NULL)
		g_object_unref (file);
	return ret;
}
示例#20
0
static void
install_button_clicked_cb (GtkButton   *button,
                           const gchar *font_file)
{
    GFile *src, *dest;
    gchar *dest_path, *dest_filename;

    GError *err = NULL;

    /* first check if ~/.fonts exists */
    dest_path = g_build_filename (g_get_home_dir (), ".fonts", NULL);
    if (!g_file_test (dest_path, G_FILE_TEST_EXISTS)) {
        GFile *f = g_file_new_for_path (dest_path);
        g_file_make_directory_with_parents (f, NULL, &err);
        g_object_unref (f);
        if (err) {
            /* TODO: show error dialog */
            g_warning ("Could not create fonts directory: %s", err->message);
            g_error_free (err);
            g_free (dest_path);
            return;
        }
    }
    g_free (dest_path);

    /* create destination filename */
    src = g_file_new_for_uri (font_file);

    dest_filename = g_file_get_basename (src);
    dest_path = g_build_filename (g_get_home_dir (), ".fonts", dest_filename, NULL);
    g_free (dest_filename);

    dest = g_file_new_for_path (dest_path);

    /* TODO: show error dialog if file exists */
    g_file_copy_async (src, dest, G_FILE_COPY_NONE, 0, NULL, NULL, NULL,
                       font_install_finished_cb, button);

    g_object_unref (src);
    g_object_unref (dest);
    g_free (dest_path);
}
示例#21
0
/**
 * hif_db_create_dir:
 **/
static gboolean
hif_db_create_dir (const gchar *dir, GError **error)
{
	GFile *file = NULL;
	gboolean ret = TRUE;

	/* already exists */
	ret = g_file_test (dir, G_FILE_TEST_IS_DIR);
	if (ret)
		goto out;

	/* need to create */
	g_debug ("creating %s", dir);
	file = g_file_new_for_path (dir);
	ret = g_file_make_directory_with_parents (file, NULL, error);
out:
	if (file != NULL)
		g_object_unref (file);
	return ret;
}
static void
setup_merge_dir_symlink(void)
{
    gchar *user_config = g_get_user_config_dir();
    gchar *merge_path = g_build_filename (user_config, "menus", "applications-merged", NULL);
    GFile *merge_file = g_file_new_for_path (merge_path);

    g_file_make_directory_with_parents (merge_file, NULL, NULL);

    gchar *sym_path = g_build_filename (user_config, "menus", "cinnamon-applications-merged", NULL);
    GFile *sym_file = g_file_new_for_path (sym_path);
    if (!g_file_query_exists (sym_file, NULL)) {
        g_file_make_symbolic_link (sym_file, merge_path, NULL, NULL);
    }

    g_free (merge_path);
    g_free (sym_path);
    g_object_unref (merge_file);
    g_object_unref (sym_file);
}
示例#23
0
文件: utils.c 项目: madbob/FSter
void check_and_create_folder (gchar *path)
{
    gboolean ret;
    GFile *dummy;
    GError *error;

    dummy = g_file_new_for_path (path);

    if (g_file_query_exists (dummy, NULL) == FALSE) {
        error = NULL;
        ret = g_file_make_directory_with_parents (dummy, NULL, &error);

        if (ret == FALSE) {
            g_warning ("Error: unable to create directory %s", error->message);
            g_error_free (error);
        }
    }

    g_object_unref (dummy);
}
示例#24
0
int32 MakeDir(ExtensionString path, int mode)
{
    const char *pathStr = path.c_str();
    GFile *file;
    GError *gerror = NULL;
    int32 error = NO_ERROR;

    if (g_file_test(pathStr, G_FILE_TEST_EXISTS)) {
        return ERR_FILE_EXISTS;
    }

    file = g_file_new_for_path(pathStr);
    mode = mode | 0777;

    if (!g_file_make_directory_with_parents(file, NULL, &gerror)) {
        error = GErrorToErrorCode(gerror);
    }
    g_object_unref(file);

    return error;
}
示例#25
0
static GFile *
gnac_profiles_mgr_get_profiles_dir(void)
{
  saved_profiles_dir = g_build_filename(g_get_user_data_dir(),
      PACKAGE, "profiles", NULL);
  GFile *dir = g_file_new_for_path(saved_profiles_dir);
  if (g_file_query_exists(dir, NULL)) {
    return dir;
  }

  GError *error = NULL;

  if (!g_file_make_directory_with_parents(dir, NULL, &error)) {
    libgnac_warning("%s: %s",
        _("Unable to create the profiles directory"), error->message);
    g_clear_error(&error);
    return NULL;
  }

  return dir;
}
示例#26
0
GFile*
rookie_misc_get_log_file (guint uid)
{
	gchar *dir = get_rookie_user_data_dir ();
	GFile *fil = g_file_new_for_path (dir);
	GFile *logDir = g_file_get_child (fil, "log");
	GError *error = NULL;

	if (!g_file_query_exists (logDir, NULL) &&
		!g_file_make_directory_with_parents (fil, NULL, &error))
		handle_critical_error (error);

	gchar *uid_str = g_strdup_printf ("%u", uid);
	GFile *logFile = g_file_get_child (logDir, uid_str);

	g_object_unref (logDir);
	g_object_unref (fil);
	g_free (uid_str);
	g_free (dir);

	return logFile;
}
static void
ensure_dirs_task_thread_func (GTask *task,
			      gpointer source,
			      gpointer task_data,
			      GCancellable *cancellable)
{
	RestoreFilesData *data = task_data;
	NautilusFile *original_dir;
	GFile *original_dir_location;
	GList *original_dirs, *l;

	original_dirs = g_hash_table_get_keys (data->original_dirs_hash);
	for (l = original_dirs; l != NULL; l = l->next) {
		original_dir = NAUTILUS_FILE (l->data);
		original_dir_location = nautilus_file_get_location (original_dir);

		g_file_make_directory_with_parents (original_dir_location, cancellable, NULL);
		g_object_unref (original_dir_location);
	}

	g_task_return_pointer (task, NULL, NULL);
}
示例#28
0
GFile *
fetch_archive (const gchar  *url,
               const gchar  *sha,
               const gchar  *module_name,
               GFile        *destination,
               guint         strip_components,
               GError      **error)
{
  g_autoptr(GFile) archive_file = NULL;
  g_autoptr(GFile) source_dir = NULL;
  g_autoptr(SoupURI) uri = NULL;
  g_autofree char *archive_name = NULL;
  GError *local_error = NULL;

  source_dir = g_file_get_child (destination, module_name);
  if (!g_file_make_directory_with_parents (source_dir, NULL, &local_error))
    {
      if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
        {
          g_propagate_error (error, local_error);
          return NULL;
        }

      g_error_free (local_error);
    }

  uri = soup_uri_new (url);
  archive_name = g_path_get_basename (soup_uri_get_path (uri));
  archive_file = g_file_get_child (source_dir, archive_name);

  if (!download_archive (uri, sha, archive_file, error))
    return NULL;

  if (!extract_archive (source_dir, archive_file, strip_components, error))
    return NULL;

  return g_steal_pointer (&source_dir);
}
示例#29
0
void macro_edit_button_cb(GtkButton* btn, gpointer user_data)
{
    GtkWidget* parent_dlg = GTK_WIDGET(user_data);

    gtk_widget_set_sensitive(parent_dlg, FALSE);

    GtkWidget* dlg = unikey_macro_dialog_new();

    gchar* macrofile = get_macro_file();

    CMacroTable macro;
    macro.init();
    macro.loadFromFile(macrofile);

    unikey_macro_dialog_load_macro(GTK_DIALOG(dlg), macro);

    int ret = gtk_dialog_run(GTK_DIALOG(dlg));

    if (ret == GTK_RESPONSE_OK)
    {
        unikey_macro_dialog_save_macro(GTK_DIALOG(dlg), &macro);

        GFile* f = g_file_get_parent(g_file_new_for_path(macrofile));
        if (g_file_query_exists(f, NULL) == FALSE)
        {
            g_file_make_directory_with_parents(f, NULL, NULL);
        }
        g_object_unref(f);

        macro.writeToFile(macrofile);
    }

    g_free(macrofile);

    gtk_widget_destroy(dlg);

    gtk_widget_set_sensitive(parent_dlg, TRUE);
}
示例#30
0
static gboolean
gs_install_appstream_copy_file (GFile *file, GError **error)
{
	g_autofree gchar *basename = g_file_get_basename (file);
	g_autofree gchar *cachefn = gs_external_appstream_utils_get_file_cache_path (basename);
	g_autoptr(GFile) cachefn_file = g_file_new_for_path (cachefn);
	g_autoptr(GFile) cachedir_file = g_file_get_parent (cachefn_file);

	/* make sure the parent directory exists, but if not then create with
	 * the ownership and permissions of the current process */
	if (!g_file_query_exists (cachedir_file, NULL)) {
		if (!g_file_make_directory_with_parents (cachedir_file, NULL, error))
			return FALSE;
	}

	/* do the copy, overwriting existing files and setting the permissions
	 * of the current process (so that should be -rw-r--r--) */
	return g_file_copy (file, cachefn_file,
			    G_FILE_COPY_OVERWRITE |
			    G_FILE_COPY_NOFOLLOW_SYMLINKS |
			    G_FILE_COPY_TARGET_DEFAULT_PERMS,
			    NULL, NULL, NULL, error);
}