コード例 #1
0
ファイル: dir-project.c プロジェクト: abderrahim/anjuta
static gboolean
dir_pattern_stack_is_match (GList *stack, GFile *file)
{
	gboolean match;
	GList *list;
	GList *name_list;
	gboolean directory;

	/* Create name list from file */
	name_list = dir_cut_filename (file);
	
	directory = g_file_query_file_type (file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_DIRECTORY;
	/* Include directories by default */
	match = directory;

	/* Check all valid patterns */
	for (list = g_list_last (stack); list != NULL; list = g_list_previous (list))
	{
		DirPatternList *pat_list = (DirPatternList *)list->data;
		GList *node;

		/* Mark parent level */
		for (node = g_list_first (name_list); node != NULL; node = g_list_next (node))
		{
			DirMatchString *str = (DirMatchString *)node->data;

			str->parent = g_file_equal (pat_list->directory, str->file);
		}

		for (node = g_list_first (pat_list->pattern); node != NULL; node = g_list_next (node))
		{
			DirPattern *pat = (DirPattern *)node->data;
			GList *pat_part;
			GList *name_part;
			gboolean match_part;

			if (pat->directory && !directory)
				continue;

			name_part = g_list_first (name_list);
			for (pat_part = g_list_first (pat->names); pat_part != NULL; pat_part = g_list_next (pat_part))
			{
				DirMatchString *part = (DirMatchString *)name_part->data;
				match_part = g_pattern_match ((GPatternSpec *)pat_part->data, part->length, part->string, part->reverse);

				if (!match_part) break;
				name_part = g_list_next (name_part);
			}

			/* Local match are relative to parent directory only */
			if (match_part && pat->local && (!((DirMatchString *)name_part->data)->parent)) match_part = FALSE;

			if (match_part)	match = pat->match;
		}
	}

	dir_filename_free (name_list);

	return match;
}
コード例 #2
0
ファイル: eog-util.c プロジェクト: UIKit0/eog
static void
_eog_util_show_file_in_filemanager_fallback (GFile *file, GdkScreen *screen)
{
	gchar *uri = NULL;
	GError *error = NULL;
	guint32 timestamp = gtk_get_current_event_time ();

	if (g_file_query_file_type (file, 0, NULL) == G_FILE_TYPE_DIRECTORY) {
		uri = g_file_get_uri (file);
	} else {
		/* If input file is not a directory we must open it's
		   folder/parent to avoid opening the file itself     */
		GFile *parent_file;

		parent_file = g_file_get_parent (file);
		if (G_LIKELY (parent_file))
			uri = g_file_get_uri (parent_file);
		g_object_unref (parent_file);
	}

	if (uri && !gtk_show_uri (screen, uri, timestamp, &error)) {
		g_warning ("Couldn't show containing folder \"%s\": %s", uri,
			   error->message);
		g_error_free (error);
	}

	g_free (uri);
}
コード例 #3
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;
}
コード例 #4
0
ファイル: test-utils.c プロジェクト: Distrotech/librsvg
void
test_utils_add_test_for_all_files (const gchar   *prefix,
                                   GFile         *base,
                                   GFile         *file,
                                   GTestDataFunc  test_func,
                                   AddTestFunc    add_test_func)
{
  GFileEnumerator *enumerator;
  GFileInfo *info;
  GList *l, *files;
  GError *error = NULL;


  if (g_file_query_file_type (file, 0, NULL) != G_FILE_TYPE_DIRECTORY)
    {
      gchar *test_path;
      gchar *relative_path;

      if (base)
        relative_path = g_file_get_relative_path (base, file);
      else
        relative_path = g_file_get_path (file);

      test_path = g_strconcat (prefix, "/", relative_path, NULL);
      
      g_test_add_data_func_full (test_path, g_object_ref (file), test_func, g_object_unref);
      return;
    }


  enumerator = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
  g_assert_no_error (error);
  files = NULL;

  while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)))
    {
      GFile *next_file = g_file_get_child (file, g_file_info_get_name (info));

      if (add_test_func == NULL || add_test_func (next_file))
        {
          files = g_list_prepend (files, g_object_ref (next_file));
        }

      g_object_unref (next_file);
      g_object_unref (info);
    }
  
  g_assert_no_error (error);
  g_object_unref (enumerator);

  files = g_list_sort (files, compare_files);

  for (l = files; l; l = l->next)
    {
      test_utils_add_test_for_all_files (prefix, base, l->data, test_func, add_test_func);
    }

  g_list_free_full (files, g_object_unref);
}
コード例 #5
0
gboolean locke_appmanager_is_valid_application(LockeAppManager *lam,
		const gchar *baseDir, const gchar *filename) {
	gchar fullpath[2048];
	gchar appfolder[2048];
	/* calculates app folder*/
	strcpy(appfolder, baseDir);
	if (appfolder[strlen(baseDir) - 1] != G_DIR_SEPARATOR)
		strcat(appfolder, G_DIR_SEPARATOR_S);
	strcat(appfolder, filename);
	strcat(appfolder, G_DIR_SEPARATOR_S);
	/* check for .so existence */
	strcpy(fullpath, appfolder);
	strcat(fullpath, "lib");
	strcat(fullpath, filename);
	strcat(fullpath, ".");
	strcat(fullpath, DLL_EXT);

	GFile *file = g_file_new_for_path(fullpath);
	if (g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL)
			!= G_FILE_TYPE_REGULAR) {
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_WARNING,
				"Application path '%s' doesn't exist or is not a regular file. \nWon't try to deploy it. ",
				fullpath);
		return FALSE;
	}
	g_object_unref(file);

	/* check for .ini existence */
	strcpy(fullpath, appfolder);
	strcat(fullpath, filename);
	strcat(fullpath, ".ini");
	file = g_file_new_for_path(fullpath);
	if (g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL)
			!= G_FILE_TYPE_REGULAR) {
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_WARNING,
				"App config file path '%s' doesn't exist or is not a regular file. \nWon't try to deploy it. ",
				fullpath);
		return FALSE;
	}
	g_object_unref(file);
	/* All checks completed, app is valid */
	g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO, "Application path '%s' is valid. \nWill try to deploy it. ",
			fullpath);
	return TRUE;
}
コード例 #6
0
void locke_appmanager_scan_for_deploys(LockeAppManager *lam, GFile *deployDir) {
	if (g_file_query_file_type(deployDir, G_FILE_QUERY_INFO_NONE, NULL)
			!= G_FILE_TYPE_DIRECTORY) {
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_WARNING,
				"Hey, autodeploy dir '%s' does not exist!! Create it to be able to make deploys. ",
				g_file_get_path(deployDir));
		return;
	}
	g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO, "Scanning folder '%s' for application deployments",
			g_file_get_path(deployDir));

	/* Get file enumerator */
	GError *err = NULL;
	GFileEnumerator *files = g_file_enumerate_children(deployDir, "*",
			G_FILE_QUERY_INFO_NONE, NULL, &err);
	if (err != NULL) {
		/* Report error to user, and free error */
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_ERROR, "Unable to get file list for directory '%s': %s",
				g_file_get_path(deployDir), err->message);
		g_error_free(err);
		goto scan_for_deploys_finally;
	}

	/* process each file individually */
	GFileInfo *fileInfo = NULL;
	do {
		fileInfo = g_file_enumerator_next_file(files, NULL, &err);
		if (err != NULL) {
			/* Report error to user, and free error */
			g_log(LSVR_DOMAIN, G_LOG_LEVEL_ERROR,  "Unable to get file for directory '%s': %s",
					g_file_get_path(deployDir), err->message);
			g_error_free(err);
			goto scan_for_deploys_finally;
		}
		/* stop condition */
		if (fileInfo == NULL)
			break;
		/* finally, process the file */
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO, " =========> Processing file '%s'",
				g_file_info_get_display_name(fileInfo));
		locke_appmanager_add_application(lam, g_file_get_path(deployDir),
				g_file_info_get_name(fileInfo));
	} while (TRUE);

	/* Close open things */
	g_file_enumerator_close(files, NULL, &err);
	if (err != NULL) {
		/* Report error to user, and free error */
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_ERROR,
				"Error closing file enumerator for directory '%s': %s",
				g_file_get_path(deployDir), err->message);
		g_error_free(err);
		goto scan_for_deploys_finally;
	}
	/* Free allocated memory  */
	scan_for_deploys_finally: g_object_unref(files);
}
コード例 #7
0
gboolean
fileops_move (GFile* file_list[], guint num, GFile* dest_dir, gboolean prompt)
{
    g_prompt = prompt;
    g_move_response = NULL;

    gboolean retval = TRUE;
    g_debug ("fileops_move: Begin moving files");

    GCancellable* move_cancellable = g_cancellable_new ();
    TDData* data = g_malloc0 (sizeof (TDData));
    data->cancellable = move_cancellable;

    for (guint i = 0; i < num; i++)
    {
        GFile* src = file_list[i];
    #if 1
        char* src_uri = g_file_get_uri (src);
        char* dest_dir_uri = g_file_get_uri (dest_dir);
        g_debug ("fileops_move: file %d: %s to dest: %s", i, src_uri, dest_dir_uri);

        g_free (src_uri);
        g_free (dest_dir_uri);
    #endif
        //make sure dest_dir is a directory before proceeding.
        GFileType type = g_file_query_file_type (dest_dir, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL);
        if (type != G_FILE_TYPE_DIRECTORY)
        {
            //TODO: symbolic links
            g_debug ("dest type is not directory");

            return FALSE;
        }
        char* src_basename= g_file_get_basename (src);
        GFile* move_dest_file = g_file_get_child (dest_dir, src_basename);
        g_free (src_basename);

        data->dest_file = move_dest_file;

        //retval &= _move_files_async (src, data);
        //traverse_directory (dir, _move_files_async, _dummy_func, move_dest_gfile);
        retval &= traverse_directory (src, _move_files_async, _dummy_func, data);
        // here i must check out if dest has the same file or directory ,if true , fileops_delete,else, nothing do
        if (retval)
            fileops_delete (&src, 1);//ensure original file is removed.

        g_object_unref (move_dest_file);
    }
    g_object_unref (data->cancellable);
    g_free (data);

    fileops_response_free (g_move_response);
    g_debug ("fileops_move: End moving files");

    return retval;
}
コード例 #8
0
ファイル: nemo-action.c プロジェクト: IanLee1521/nemo
static gboolean
get_is_dir_hack (NemoFile *file)
{
    gboolean ret = FALSE;

    GFile *f = nemo_file_get_location (file);
    GFileType type = g_file_query_file_type (f, 0, NULL);
    ret = type == G_FILE_TYPE_DIRECTORY;
    return ret;
}
コード例 #9
0
ファイル: dir-project.c プロジェクト: abderrahim/anjuta
static gboolean
dir_project_list_directory (DirProject *project, DirGroup* parent, GError **error) 
{
	gboolean ok;
	GFileEnumerator *enumerator;

	enumerator = g_file_enumerate_children (DIR_GROUP_DATA (parent)->base.directory,
	    G_FILE_ATTRIBUTE_STANDARD_NAME,
	    G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
	    NULL,
	    error);

	ok = enumerator != NULL;
	if (ok)
	{
		GFileInfo *info;
		
		while ((info = g_file_enumerator_next_file (enumerator, NULL, error)) != NULL)
		{
			const gchar *name;
			GFile *file;

			name = g_file_info_get_name (info);
			file = g_file_get_child (DIR_GROUP_DATA (parent)->base.directory, name);
			g_object_unref (info);

			/* Check if file is a source */
			if (!dir_pattern_stack_is_match (project->sources, file)) continue;
			
			if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY)
			{
				/* Create a group for directory */
				DirGroup *group;
				
				group = dir_group_new (file);
				g_hash_table_insert (project->groups, g_file_get_uri (file), group);
				anjuta_project_node_append (parent, group);
				ok = dir_project_list_directory (project, group, error);
				if (!ok) break;
			}
			else
			{
				/* Create a source for files */
				DirSource *source;

				source = dir_source_new (file);
				anjuta_project_node_append (parent, source);
			}
		}
        g_file_enumerator_close (enumerator, NULL, NULL);
        g_object_unref (enumerator);
	}

	return ok;
}
コード例 #10
0
static void locke_appmanager_file_changed(GFileMonitor *file_monitor,
		GFile *child, GFile *other_file, GFileMonitorEvent event_type,
		gpointer user_data) {
	LockeAppManager *lam = (LockeAppManager *) user_data;
	g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO, "\n-----------------------------------------------------\n");
	g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO, "PID=%d Something has changed at '%s'. \nChecking...", getpid(),
			g_file_get_path(lam->deployFolder));
	switch (event_type) {
	case G_FILE_MONITOR_EVENT_DELETED:
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO, "'%s' removed", g_file_get_basename(child));
		if (g_file_has_parent(child, lam->deployFolder)) {
			char *path = g_file_get_path(child);
			g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO,
					" =========> I am going to try to remove the application at path '%s' ",
					path);
			locke_appmanager_remove_application(lam,
					g_file_get_basename(child));
		}
		break;
	case G_FILE_MONITOR_EVENT_CREATED:
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO, "'%s' added\n", g_file_get_basename(child));
		if (g_file_has_parent(child, lam->deployFolder)) {
			char *path = g_file_get_path(child);
			g_log(LSVR_DOMAIN, G_LOG_LEVEL_INFO,
					" =========> I am going to try to create an application for path '%s'  ",
					path);
			locke_appmanager_add_application(lam,
					g_file_get_path(lam->deployFolder),
					g_file_get_basename(child));
		}
		break;
	case G_FILE_MONITOR_EVENT_CHANGED:
		/* g_log(LSVR_DOMAIN, G_LOG_LEVEL_DEBUG, "'%s' started changing\n", g_file_get_basename(child)); */
		break;
	case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
		/* g_log(LSVR_DOMAIN, G_LOG_LEVEL_DEBUG, "'%s' finished changing\n", g_file_get_basename(child)); */
		break;
	case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_DEBUG, "'%s' attributes changed\n", g_file_get_basename(child));
		/* Process only directories. Files are just ignored. */
		if (g_file_query_file_type(child, G_FILE_QUERY_INFO_NONE, NULL)
				!= G_FILE_TYPE_DIRECTORY) {
			break;
		}
		locke_appmanager_file_changed(file_monitor, child, other_file,
				G_FILE_MONITOR_EVENT_DELETED, user_data);
		locke_appmanager_file_changed(file_monitor, child, other_file,
				G_FILE_MONITOR_EVENT_CREATED, user_data);
		break;
	default:
		g_log(LSVR_DOMAIN, G_LOG_LEVEL_DEBUG, "'%s' received event %d ", g_file_get_basename(child),
		 event_type);
		break;
	}
}
コード例 #11
0
static gboolean
_ostree_bootloader_syslinux_query (OstreeBootloader *bootloader,
                                   gboolean         *out_is_active,
                                   GCancellable     *cancellable,
                                   GError          **error)
{
  OstreeBootloaderSyslinux *self = OSTREE_BOOTLOADER_SYSLINUX (bootloader);

  *out_is_active = g_file_query_file_type (self->config_path, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_SYMBOLIC_LINK;
  return TRUE;
}
コード例 #12
0
static gboolean
_ostree_bootloader_uboot_query (OstreeBootloader *bootloader,
                                gboolean         *out_is_active,
                                GCancellable     *cancellable,
                                GError          **error) 
{
  OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader);

  *out_is_active = g_file_query_file_type (self->config_path, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_REGULAR;
  return TRUE;
}
コード例 #13
0
ファイル: copy.c プロジェクト: aaam/megatools
static gboolean dl_sync_dir(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_print("D %s\n", local_path);

    if (!opt_dryrun)
    {
      if (!g_file_make_directory(file, NULL, &local_err))
      {
        g_printerr("ERROR: Can't create local directory %s: %s\n", local_path, local_err->message);
        g_clear_error(&local_err);
        return FALSE;
      }
    }
  }
  else
  {
    if (g_file_query_file_type(file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) != G_FILE_TYPE_DIRECTORY)
    {
      g_printerr("ERROR: Can't create local directory %s: file exists\n", local_path);
      return FALSE;
    }
  }

  // sync children
  GSList* children = mega_session_get_node_chilren(s, node), *i;
  for (i = children; i; i = i->next)
  {
    mega_node* child = i->data;
    gchar* child_remote_path = g_strconcat(remote_path, "/", child->name, NULL);
    GFile* child_file = g_file_get_child(file, child->name);

    if (child->type == MEGA_NODE_FILE)
    {
      dl_sync_file(child, child_file, child_remote_path);
    }
    else
    {
      dl_sync_dir(child, child_file, child_remote_path);
    }

    g_object_unref(child_file);
    g_free(child_remote_path);
  }

  g_slist_free(children);
  return TRUE;
}
コード例 #14
0
static gboolean
thunar_file_info_is_directory (ThunarxFileInfo *file_info)
{
  GFileType ftype;

  ftype = g_file_query_file_type(THUNAR_PLUGGER_FILE (file_info)->gfile,
				 G_FILE_QUERY_INFO_NONE,
				 NULL);
  if (G_FILE_TYPE_DIRECTORY == ftype) {
    return TRUE;
  } else {
    return FALSE;
  }
}
コード例 #15
0
ファイル: gtk-reftest.c プロジェクト: fatman2021/gtk
static void
add_test_for_file (GFile *file)
{
  GFileEnumerator *enumerator;
  GFileInfo *info;
  GList *files;
  GError *error = NULL;


  if (g_file_query_file_type (file, 0, NULL) != G_FILE_TYPE_DIRECTORY)
    {
      g_test_add_vtable (g_file_get_path (file),
                         0,
                         g_object_ref (file),
                         NULL,
                         (GTestFixtureFunc) test_ui_file,
                         (GTestFixtureFunc) g_object_unref);
      return;
    }


  enumerator = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
  g_assert_no_error (error);
  files = NULL;

  while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)))
    {
      const char *filename;

      filename = g_file_info_get_name (info);

      if (!g_str_has_suffix (filename, ".ui") ||
          g_str_has_suffix (filename, ".ref.ui"))
        {
          g_object_unref (info);
          continue;
        }

      files = g_list_prepend (files, g_file_get_child (file, filename));

      g_object_unref (info);
    }
  
  g_assert_no_error (error);
  g_object_unref (enumerator);

  files = g_list_sort (files, compare_files);
  g_list_foreach (files, (GFunc) add_test_for_file, NULL);
  g_list_free_full (files, g_object_unref);
}
コード例 #16
0
ファイル: actions.c プロジェクト: ptomato/gnome-inform7
/* 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);
}
コード例 #17
0
ファイル: amp-source.c プロジェクト: kyoushuu/anjuta
AnjutaProjectNode*
amp_source_node_new_valid (GFile *file, AnjutaProjectNodeType type, GError **error)
{
	/* Validate source name */

	if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY)
	{
		amp_set_error (error, IANJUTA_PROJECT_ERROR_VALIDATION_FAILED,
		               _("Source file must be a regular file, not a directory"));

		return NULL;
	}

	return amp_source_node_new (file, type);
}
コード例 #18
0
ファイル: main.c プロジェクト: eggpi/xmms2-guilherme
static gboolean
updater_is_dir (GFile *file)
{
	GFileType type;

	g_return_val_if_fail (file, FALSE);

	type = g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL);

	if (type != G_FILE_TYPE_DIRECTORY) {
		return FALSE;
	}

	return TRUE;
}
コード例 #19
0
static void
run_file  (GFile* file, GFile* _file_arg)
{
    char* cmd_line = NULL;
    char* file_path = NULL;


    //here we should check the file type
    // if the src is symbolink we should set the file_path as the path for it's value
    GFileType type = g_file_query_file_type (file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL);
    if (type == G_FILE_TYPE_SYMBOLIC_LINK)
    {
        //TODO: symbolic links
        g_debug("the src file type is  G_FILE_TYPE_SYMBOLIC_LINK");
        GFileInfo* info = g_file_query_info(file, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL);
        if (info != NULL) {
            const char * link_target_path = g_file_info_get_symlink_target(info);
            g_debug("symbolic link target is :%s",link_target_path);
            file_path = g_strdup(link_target_path);
        }
        g_object_unref(info);
    }
    else{
        file_path = g_file_get_path (file);
    }
    g_debug("run file_path :%s",file_path);

    if (_file_arg != NULL)
    {
        char* _file_arg_uri = g_file_get_uri (_file_arg);
        cmd_line = g_strdup_printf ("%s %s", file_path, _file_arg_uri);
	g_free (_file_arg_uri);
    }
    else
    {
        cmd_line = g_strdup (file_path);
    }
    g_free (file_path);
    if(cmd_line != NULL)
    {
        g_spawn_command_line_async (cmd_line, NULL);
    }
    else
    {
        g_warning("run file_path is null");
    }
    g_free (cmd_line);
}
コード例 #20
0
ファイル: util.c プロジェクト: davidzchen/budgie
void search_directory(const gchar *path, GSList **list, int n_params, const gchar **mimes)
{
        GFile *file = NULL;
        GFileInfo *next_file;
        GFileType type;
        GFileEnumerator *listing;
        const gchar *next_path;
        const gchar *file_mime;
        gchar *full_path = NULL;
        MediaInfo *media;
        guint i;

        file = g_file_new_for_path(path);
        type = g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL);
        if (type == G_FILE_TYPE_DIRECTORY) {
                /* Enumerate children (needs less query flags!) */
                listing = g_file_enumerate_children(file, "standard::*", G_FILE_QUERY_INFO_NONE,
                        NULL, NULL);

                /* Lets go through them */
                while ((next_file = g_file_enumerator_next_file(listing, NULL, NULL)) != NULL) {
                        next_path = g_file_info_get_name(next_file);
                        full_path = g_strdup_printf("%s/%s", path, next_path);

                        /* Recurse if its a directory */
                        if (g_file_info_get_file_type(next_file) == G_FILE_TYPE_DIRECTORY) {
                                search_directory(full_path, list, n_params, mimes);
                        } else {
                                /* Not exactly a regex but it'll do for now */
                                file_mime = g_file_info_get_content_type(next_file);
                                for (i=0; i < n_params; i++) {
                                        if (g_str_has_prefix(file_mime, mimes[i])) {
                                                media = media_from_file(full_path, next_file, file_mime);
                                                /* Probably switch to a new struct in the future */
                                                *list = g_slist_append(*list, media);
                                        }
                                }
                        }
                        g_free(full_path);
                        g_object_unref(next_file);
                        full_path = NULL;
                }
                g_file_enumerator_close(listing, NULL, NULL);
                g_object_unref(listing);
        }

        g_object_unref(file);
}
コード例 #21
0
ファイル: inotify_item.c プロジェクト: yejingfu/dde-workspace
void handle_update(GFile* f)
{
    // g_message("handle_update");
    if (g_file_query_file_type(f, G_FILE_QUERY_INFO_NONE ,NULL) != G_FILE_TYPE_UNKNOWN) {
        char* path = g_file_get_path(f);
        Entry* entry = dentry_create_by_path(path);
        g_free(path);

        JSObjectRef json = json_create();
        json_append_nobject(json, "entry", entry, g_object_ref, g_object_unref);
        js_post_message("item_update", json);
        desktop_item_update();

        g_object_unref(entry);
    }
}
コード例 #22
0
ファイル: dir-project.c プロジェクト: abderrahim/anjuta
gint
dir_project_probe (GFile *file,
	    GError     **error)
{
	gint probe;

	probe = g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY;
	if (!probe)
	{
		g_set_error (error, IANJUTA_PROJECT_ERROR, 
		             IANJUTA_PROJECT_ERROR_DOESNT_EXIST,
			   _("Project doesn't exist or invalid path"));
	}

	return probe ? IANJUTA_PROJECT_PROBE_FILES : 0;
}
コード例 #23
0
ファイル: main.c プロジェクト: eggpi/xmms2-guilherme
static void
on_entity_changed (updater_t *updater, GFile *entity)
{
	GFileType type;

	g_return_if_fail (updater);
	g_return_if_fail (entity);

	type = g_file_query_file_type (entity, G_FILE_QUERY_INFO_NONE, NULL);
	switch (type) {
	case G_FILE_TYPE_REGULAR:
		updater_rehash_file (updater, entity);
		break;
	default:
		g_debug ("something else changed: %d", (int) type);
		break;
	}
}
コード例 #24
0
ファイル: deadbeef-gvfs.c プロジェクト: asv/deadbeef-gvfs
int
ddb_gvfs_is_container (const char *fname)
{
  const char **sn = scheme_names;
  while (*sn)
    {
      if (g_str_has_prefix (fname, *sn))
        break;
      sn++;
    }

  if (*sn == NULL)
    return 0;

  GFile *file = g_file_new_for_uri (fname);
  GFileType type = g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL);
  g_object_unref (file);

  return type == G_FILE_TYPE_DIRECTORY;
}
コード例 #25
0
ファイル: dir-project.c プロジェクト: abderrahim/anjuta
gboolean
dir_project_reload (DirProject *project, GError **error) 
{
	GFile *root_file;
	GFile *source_file;
	DirGroup *group;
	gboolean ok = TRUE;

	/* Unload current project */
	root_file = g_object_ref (project->root_file);
	dir_project_unload (project);
	project->root_file = root_file;
	DEBUG_PRINT ("reload project %p root file %p", project, project->root_file);

	/* shortcut hash tables */
	project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

	if (g_file_query_file_type (root_file, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY)
	{
		g_set_error (error, IANJUTA_PROJECT_ERROR, 
		             IANJUTA_PROJECT_ERROR_DOESNT_EXIST,
			   _("Project doesn't exist or invalid path"));

		return FALSE;
	}

	group = dir_group_new (root_file);
	g_hash_table_insert (project->groups, g_file_get_uri (root_file), group);
	project->root_node = group;

	/* Load source pattern */
	source_file = g_file_new_for_path (SOURCES_FILE);
	project->sources = dir_push_pattern_list (NULL, g_object_ref (root_file), source_file, FALSE, NULL);
	g_object_unref (source_file);
	
	dir_project_list_directory (project, group, NULL);
	
	monitors_setup (project);
	
	return ok;
}
コード例 #26
0
static NautilusWindowSlot *
get_window_slot_for_location (NautilusApplication *application, GFile *location)
{
	NautilusWindowSlot *slot;
	GList *l, *sl;

	slot = NULL;

	if (g_file_query_file_type (location, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY) {
		location = g_file_get_parent (location);
	} else {
		g_object_ref (location);
	}

	for (l = gtk_application_get_windows (GTK_APPLICATION (application)); l; l = l->next) {
		NautilusWindow *win = NAUTILUS_WINDOW (l->data);

		if (NAUTILUS_IS_DESKTOP_WINDOW (win))
			continue;

		for (sl = nautilus_window_get_slots (win); sl; sl = sl->next) {
			NautilusWindowSlot *current = NAUTILUS_WINDOW_SLOT (sl->data);
			GFile *slot_location = nautilus_window_slot_get_location (current);

			if (g_file_equal (slot_location, location)) {
				slot = current;
				break;
			}
		}

		if (slot) {
			break;
		}
	}

	g_object_unref (location);

	return slot;
}
コード例 #27
0
static void
giggle_plugin_manager_init (GigglePluginManager *manager)
{
	GigglePluginManagerPriv *priv = GET_PRIV (manager);

	priv->cancellable = g_cancellable_new ();
	priv->plugin_dir = g_file_new_for_path ("plugins");

	if (G_FILE_TYPE_DIRECTORY != g_file_query_file_type
			(priv->plugin_dir, G_FILE_QUERY_INFO_NONE, NULL)) {
		g_object_unref (priv->plugin_dir);
		priv->plugin_dir = g_file_new_for_path (PLUGINDIR);
	}

	if (!g_file_query_exists (priv->plugin_dir, priv->cancellable))
		return;

	g_file_enumerate_children_async (priv->plugin_dir,
					 G_FILE_ATTRIBUTE_STANDARD_NAME,
					 G_FILE_QUERY_INFO_NONE,
					 G_PRIORITY_DEFAULT, priv->cancellable,
					 plugin_manager_children_ready, manager);
}
コード例 #28
0
ファイル: main.c プロジェクト: eggpi/xmms2-guilherme
static void
on_entity_created (updater_t *updater, GFile *entity)
{
	GFileType type;

	g_return_if_fail (updater);
	g_return_if_fail (entity);

	type = g_file_query_file_type (entity, G_FILE_QUERY_INFO_NONE, NULL);
	switch (type) {
	case G_FILE_TYPE_DIRECTORY:
		g_debug ("directory created");
		updater_add_watcher_and_import (updater, entity);
		break;
	case G_FILE_TYPE_REGULAR:
		g_debug ("file created");
		updater_add_file (updater, entity);
		break;
	default:
		g_debug ("something else created: %d", (int) type);
		break;
	}
}
コード例 #29
0
static void
reader_libpcapfile_monitor_changed (GFileMonitor      *UNUSED(monitor),
                                    GFile             *file,
                                    GFile             *UNUSED(other_file),
                                    GFileMonitorEvent  event_type,
                                    gpointer           UNUSED(user_data))
{
    // Monitor new directories?
    if (config.pcapRecursive &&
        event_type == G_FILE_MONITOR_EVENT_CREATED &&
        g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY) {

        gchar *path = g_file_get_path(file);
        reader_libpcapfile_monitor_dir(path);
        g_free(path);

        return;
    }

    if (event_type != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
        return;

    gchar *basename = g_file_get_path(file);
    if (!g_regex_match(config.offlineRegex, basename, 0, NULL)) {
        g_free(basename);
        return;
    }
    g_free(basename);

    gchar *path = g_file_get_path(file);
    MolochString_t *string = MOLOCH_TYPE_ALLOC0(MolochString_t);
    string->str = path;

    if (config.debug) 
        LOG("Monitor enqueing %s", string->str);
    DLL_PUSH_TAIL(s_, &monitorQ, string);
}
コード例 #30
0
static GTokenType
gimp_color_profile_store_load_profile (GimpColorProfileStore *store,
                                       GScanner              *scanner,
                                       gint                   index)
{
  GtkTreeIter  iter;
  gchar       *label = NULL;
  gchar       *uri   = NULL;

  if (gimp_scanner_parse_string (scanner, &label) &&
      gimp_scanner_parse_string (scanner, &uri))
    {
      GFile *file = g_file_new_for_uri (uri);

      if (file)
        {
          if (g_file_query_file_type (file, 0, NULL) == G_FILE_TYPE_REGULAR)
            {
              gimp_color_profile_store_history_insert (store, &iter,
                                                       file, label, index);
            }

          g_object_unref (file);
        }

      g_free (label);
      g_free (uri);

      return G_TOKEN_RIGHT_PAREN;
    }

  g_free (label);
  g_free (uri);

  return G_TOKEN_STRING;
}