GFileEnumerator *
_g_local_file_enumerator_new (GLocalFile *file,
			      const char           *attributes,
			      GFileQueryInfoFlags   flags,
			      GCancellable         *cancellable,
			      GError              **error)
{
  GLocalFileEnumerator *local;
  char *filename = g_file_get_path (G_FILE (file));

#ifdef USE_GDIR
  GError *dir_error;
  GDir *dir;
  
  dir_error = NULL;
  dir = g_dir_open (filename, 0, error != NULL ? &dir_error : NULL);
  if (dir == NULL) 
    {
      if (error != NULL)
	{
	  convert_file_to_io_error (error, dir_error);
	  g_error_free (dir_error);
	}
      g_free (filename);
      return NULL;
    }
#else
  DIR *dir;
  int errsv;

  dir = opendir (filename);
  if (dir == NULL)
    {
      errsv = errno;

      g_set_error_literal (error, G_IO_ERROR,
                           g_io_error_from_errno (errsv),
                           g_strerror (errsv));
      g_free (filename);
      return NULL;
    }

#endif
  
  local = g_object_new (G_TYPE_LOCAL_FILE_ENUMERATOR,
                        "container", file,
                        NULL);

  local->dir = dir;
  local->filename = filename;
  local->matcher = g_file_attribute_matcher_new (attributes);
#ifndef USE_GDIR
  local->reduced_matcher = g_file_attribute_matcher_subtract_attributes (local->matcher,
                                                                         G_LOCAL_FILE_INFO_NOSTAT_ATTRIBUTES","
                                                                         "standard::type");
#endif
  local->flags = flags;
  
  return G_FILE_ENUMERATOR (local);
}
static void
gth_metadata_provider_file_read (GthMetadataProvider *self,
				 GthFileData         *file_data,
				 const char          *attributes)
{
	GFileAttributeMatcher *matcher;
	char                  *value;
	GTimeVal              *timeval_p;
	const char            *value_s;

	matcher = g_file_attribute_matcher_new (attributes);

	value = g_format_size_for_display (g_file_info_get_size (file_data->info));
	g_file_info_set_attribute_string (file_data->info, "gth::file::display-size", value);
	g_free (value);

	timeval_p = gth_file_data_get_modification_time (file_data);
	value = _g_time_val_strftime (timeval_p, "%x %X");
	g_file_info_set_attribute_string (file_data->info, "gth::file::display-mtime", value);
	g_free (value);

	value = g_file_get_parse_name (file_data->file);
	g_file_info_set_attribute_string (file_data->info, "gth::file::full-name", value);
	g_free (value);

	value_s = get_static_string (g_file_info_get_content_type (file_data->info));
	if (value_s != NULL)
		g_file_info_set_attribute_string (file_data->info, "gth::file::content-type", value_s);

	g_file_attribute_matcher_unref (matcher);
}
static VALUE
fileattributematcher_initialize(VALUE self, VALUE attributes)
{
        G_INITIALIZE(self, g_file_attribute_matcher_new(RVAL2CSTR(attributes)));

        return Qnil;
}
static GFileAttributeMatcher *
g_file_attribute_matcher_subtract_attributes (GFileAttributeMatcher *matcher,
                                              const char *           attributes)
{
  GFileAttributeMatcher *result, *tmp;

  tmp = g_file_attribute_matcher_new (attributes);
  result = g_file_attribute_matcher_subtract (matcher, tmp);
  g_file_attribute_matcher_unref (tmp);

  return result;
}
Esempio n. 5
0
GFileEnumerator *
_g_local_file_enumerator_new (const char           *filename,
			      const char           *attributes,
			      GFileQueryInfoFlags   flags,
			      GCancellable         *cancellable,
			      GError              **error)
{
  GLocalFileEnumerator *local;

#ifdef USE_GDIR
  GError *dir_error;
  GDir *dir;
  
  dir_error = NULL;
  dir = g_dir_open (filename, 0, error != NULL ? &dir_error : NULL);
  if (dir == NULL) 
    {
      if (error != NULL)
	{
	  convert_file_to_io_error (error, dir_error);
	  g_error_free (dir_error);
	}
      return NULL;
    }
#else
  DIR *dir;
  int errsv;

  dir = opendir (filename);
  if (dir == NULL)
    {
      errsv = errno;

      g_set_error (error, G_IO_ERROR,
		   g_io_error_from_errno (errsv),
		   "%s", g_strerror (errsv));
      return NULL;
    }

#endif
  
  local = g_object_new (G_TYPE_LOCAL_FILE_ENUMERATOR, NULL);

  local->dir = dir;
  local->filename = g_strdup (filename);
  local->matcher = g_file_attribute_matcher_new (attributes);
  local->flags = flags;
  
  return G_FILE_ENUMERATOR (local);
}
Esempio n. 6
0
static GFileInfo *
g_resource_file_query_filesystem_info (GFile         *file,
                                       const char    *attributes,
                                       GCancellable  *cancellable,
                                       GError       **error)
{
  GFileInfo *info;
  GFileAttributeMatcher *matcher;

  info = g_file_info_new ();

  matcher = g_file_attribute_matcher_new (attributes);
  if (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE))
    g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, "resource");

  if (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY))    g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE);

  g_file_attribute_matcher_unref (matcher);

  return info;
}
Esempio n. 7
0
static GFileInfo *
g_resource_file_query_info (GFile                *file,
			    const char           *attributes,
			    GFileQueryInfoFlags   flags,
			    GCancellable         *cancellable,
			    GError              **error)
{
  GResourceFile *resource = G_RESOURCE_FILE (file);
  GError *my_error = NULL;
  GFileInfo *info;
  GFileAttributeMatcher *matcher;
  gboolean res;
  gsize size;
  guint32 resource_flags;
  char **children;
  gboolean is_dir;
  char *base;

  is_dir = FALSE;
  children = g_resources_enumerate_children (resource->path, 0, NULL);
  if (children != NULL)
    {
      g_strfreev (children);
      is_dir = TRUE;
    }

  /* root is always there */
  if (strcmp ("/", resource->path) == 0)
    is_dir = TRUE;

  if (!is_dir)
    {
      res = g_resources_get_info (resource->path, 0, &size, &resource_flags, &my_error);
      if (!res)
	{
	  if (g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
	    {
	      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
			   _("The resource at '%s' does not exist"),
			   resource->path);
	    }
	  else
	    g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                                 my_error->message);
	  g_clear_error (&my_error);
	  return FALSE;
	}
    }

  matcher = g_file_attribute_matcher_new (attributes);

  info = g_file_info_new ();
  base = g_resource_file_get_basename (file);
  g_file_info_set_name (info, base);

  _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ, TRUE);
  _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE, FALSE);
  _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE, FALSE);
  _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME, FALSE);
  _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE, FALSE);
  _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH, FALSE);

  if (is_dir)
    {
      g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
    }
  else
    {
      GBytes *bytes;
      char *content_type;

      g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR);
      g_file_info_set_size (info, size);

      if ((_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE) ||
           ((~resource_flags & G_RESOURCE_FLAGS_COMPRESSED) && 
            _g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE))) &&
          (bytes = g_resources_lookup_data (resource->path, 0, NULL)))
        {
          const guchar *data;
          gsize data_size;

          data = g_bytes_get_data (bytes, &data_size);
          content_type = g_content_type_guess (base, data, data_size, NULL);

          g_bytes_unref (bytes);
        }
      else
        content_type = NULL;

      if (content_type)
        {
          _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE, content_type);
          _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE, content_type);

          g_free (content_type);
        }
    }

  g_free (base);
  g_file_attribute_matcher_unref (matcher);

  return info;
}