Implement this function by moving bits from glocalfileinfo.c
2008-02-21 David Zeuthen <davidz@redhat.com>
* glocalfileinfo.c: (_g_local_file_info_get):
* gcontenttype.c:
(g_content_type_get_icon): Implement this function by
moving bits from glocalfileinfo.c
(g_content_type_get_description): Unalias before getting
description (#517687)
* gfile.c: (g_file_class_init),
(g_file_query_filesystem_info_async),
(g_file_query_filesystem_info_finish),
(query_filesystem_info_data_free),
(query_filesystem_info_async_thread),
(g_file_real_query_filesystem_info_async),
(g_file_real_query_filesystem_info_finish):
* gfile.h: Implement async version of
g_file_query_filesystem_info()
* gfileinfo.h: Add new attributes for filesystem::use-preview
* gio.symbols: Update
* gthemedicon.c: (g_themed_icon_append_name):
* gthemedicon.h: Add new new convenience function.
* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
(get_mounts), (get_volumes), (get_connected_drives),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_init), (populate_union_monitor),
(g_volume_monitor_get), (_g_mount_get_for_mount_path),
(g_volume_monitor_adopt_orphan_mount):
* gvolumemonitor.c:
* gvolumemonitor.h: Use recursive locks so it's safe for volume
monitor implementations to call into the main volume monitor. Also
separate object initialization and volume monitor initialization
such that non-native volume monitors can properly adopt their
mounts away.
svn path=/trunk/; revision=6550
2008-02-21 13:35:05 +01:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/* GIO - GLib Input, Output and Streaming Library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2007 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
|
|
|
* Public License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Author: Alexander Larsson <alexl@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-06-22 17:10:51 +02:00
|
|
|
#include "config.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2007-12-08 13:01:06 +01:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
2007-11-26 17:13:05 +01:00
|
|
|
#include <sys/time.h>
|
2007-12-08 13:01:06 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
2007-12-08 13:01:06 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2007-11-26 17:13:05 +01:00
|
|
|
#include <unistd.h>
|
2007-12-08 13:01:06 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_GRP_H
|
|
|
|
#include <grp.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SELINUX
|
|
|
|
#include <selinux/selinux.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XATTR
|
|
|
|
|
|
|
|
#if defined HAVE_SYS_XATTR_H
|
|
|
|
#include <sys/xattr.h>
|
|
|
|
#elif defined HAVE_ATTR_XATTR_H
|
|
|
|
#include <attr/xattr.h>
|
|
|
|
#else
|
|
|
|
#error "Neither <sys/xattr.h> nor <attr/xattr.h> is present but extended attribute support is enabled."
|
|
|
|
#endif /* defined HAVE_SYS_XATTR_H || HAVE_ATTR_XATTR_H */
|
|
|
|
|
|
|
|
#endif /* HAVE_XATTR */
|
|
|
|
|
|
|
|
#include <glib/gstdio.h>
|
2007-12-14 16:56:56 +01:00
|
|
|
#include <gfileattribute-priv.h>
|
2009-06-29 14:13:14 +02:00
|
|
|
#include <gfileinfo-priv.h>
|
2009-06-18 09:05:27 +02:00
|
|
|
#include <gvfs.h>
|
2007-12-04 17:33:24 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
#include "glibintl.h"
|
|
|
|
|
2007-12-08 13:01:06 +01:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <io.h>
|
|
|
|
#ifndef W_OK
|
|
|
|
#define W_OK 2
|
|
|
|
#endif
|
|
|
|
#ifndef R_OK
|
|
|
|
#define R_OK 4
|
|
|
|
#endif
|
|
|
|
#ifndef X_OK
|
|
|
|
#define X_OK 0 /* not really */
|
|
|
|
#endif
|
|
|
|
#ifndef S_ISREG
|
|
|
|
#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
|
|
|
|
#endif
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
|
|
|
|
#endif
|
|
|
|
#ifndef S_IXUSR
|
|
|
|
#define S_IXUSR _S_IEXEC
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
#include "glocalfileinfo.h"
|
|
|
|
#include "gioerror.h"
|
|
|
|
#include "gthemedicon.h"
|
|
|
|
#include "gcontenttypeprivate.h"
|
|
|
|
|
2007-11-28 13:39:07 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
struct ThumbMD5Context {
|
|
|
|
guint32 buf[4];
|
|
|
|
guint32 bits[2];
|
|
|
|
unsigned char in[64];
|
|
|
|
};
|
2008-03-12 19:33:59 +01:00
|
|
|
|
2007-12-08 13:01:06 +01:00
|
|
|
#ifndef G_OS_WIN32
|
2008-03-12 19:33:59 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
typedef struct {
|
|
|
|
char *user_name;
|
|
|
|
char *real_name;
|
|
|
|
} UidData;
|
2008-03-12 19:33:59 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
G_LOCK_DEFINE_STATIC (uid_cache);
|
|
|
|
static GHashTable *uid_cache = NULL;
|
|
|
|
|
|
|
|
G_LOCK_DEFINE_STATIC (gid_cache);
|
|
|
|
static GHashTable *gid_cache = NULL;
|
|
|
|
|
2008-03-12 19:33:59 +01:00
|
|
|
#endif /* !G_OS_WIN32 */
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
char *
|
2008-03-12 19:33:59 +01:00
|
|
|
_g_local_file_info_create_etag (GLocalFileStat *statbuf)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2010-11-01 22:04:31 +01:00
|
|
|
glong sec, usec;
|
|
|
|
|
|
|
|
sec = statbuf->st_mtime;
|
2007-11-26 17:13:05 +01:00
|
|
|
#if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
|
2010-11-01 22:04:31 +01:00
|
|
|
usec = statbuf->st_mtimensec / 1000;
|
2007-11-26 17:13:05 +01:00
|
|
|
#elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
|
2010-11-01 22:04:31 +01:00
|
|
|
usec = statbuf->st_mtim.tv_nsec / 1000;
|
2007-11-26 17:13:05 +01:00
|
|
|
#else
|
2010-11-01 22:04:31 +01:00
|
|
|
usec = 0;
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
|
|
|
|
2010-11-01 22:04:31 +01:00
|
|
|
return g_strdup_printf ("%lu:%lu", sec, usec);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2008-03-12 19:33:59 +01:00
|
|
|
_g_local_file_info_create_file_id (GLocalFileStat *statbuf)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
return g_strdup_printf ("l%" G_GUINT64_FORMAT ":%" G_GUINT64_FORMAT,
|
|
|
|
(guint64) statbuf->st_dev,
|
|
|
|
(guint64) statbuf->st_ino);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2008-03-12 19:33:59 +01:00
|
|
|
_g_local_file_info_create_fs_id (GLocalFileStat *statbuf)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
return g_strdup_printf ("l%" G_GUINT64_FORMAT,
|
|
|
|
(guint64) statbuf->st_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-12 19:33:59 +01:00
|
|
|
#ifdef S_ISLNK
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
static gchar *
|
|
|
|
read_link (const gchar *full_name)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_READLINK
|
|
|
|
gchar *buffer;
|
|
|
|
guint size;
|
|
|
|
|
|
|
|
size = 256;
|
|
|
|
buffer = g_malloc (size);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int read_size;
|
|
|
|
|
|
|
|
read_size = readlink (full_name, buffer, size);
|
|
|
|
if (read_size < 0)
|
|
|
|
{
|
|
|
|
g_free (buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (read_size < size)
|
|
|
|
{
|
|
|
|
buffer[read_size] = 0;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
size *= 2;
|
|
|
|
buffer = g_realloc (buffer, size);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-03-12 19:33:59 +01:00
|
|
|
#endif /* S_ISLNK */
|
|
|
|
|
2008-10-15 05:37:56 +02:00
|
|
|
#ifdef HAVE_SELINUX
|
2007-11-26 17:13:05 +01:00
|
|
|
/* Get the SELinux security context */
|
|
|
|
static void
|
2007-11-30 06:11:25 +01:00
|
|
|
get_selinux_context (const char *path,
|
|
|
|
GFileInfo *info,
|
2007-11-26 17:13:05 +01:00
|
|
|
GFileAttributeMatcher *attribute_matcher,
|
2007-11-30 06:11:25 +01:00
|
|
|
gboolean follow_symlinks)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
char *context;
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (!_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT))
|
2007-11-26 17:13:05 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (is_selinux_enabled ())
|
|
|
|
{
|
|
|
|
if (follow_symlinks)
|
|
|
|
{
|
|
|
|
if (lgetfilecon_raw (path, &context) < 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (getfilecon_raw (path, &context) < 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
{
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT, context);
|
2008-01-03 10:01:00 +01:00
|
|
|
freecon (context);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-15 05:37:56 +02:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_XATTR
|
|
|
|
|
2007-12-03 11:23:03 +01:00
|
|
|
/* Wrappers to hide away differences between (Linux) getxattr/lgetxattr and
|
|
|
|
* (Mac) getxattr(..., XATTR_NOFOLLOW)
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_XATTR_NOFOLLOW
|
|
|
|
#define g_fgetxattr(fd,name,value,size) fgetxattr(fd,name,value,size,0,0)
|
|
|
|
#define g_flistxattr(fd,name,size) flistxattr(fd,name,size,0)
|
|
|
|
#define g_setxattr(path,name,value,size) setxattr(path,name,value,size,0,0)
|
|
|
|
#else
|
|
|
|
#define g_fgetxattr fgetxattr
|
|
|
|
#define g_flistxattr flistxattr
|
|
|
|
#define g_setxattr(path,name,value,size) setxattr(path,name,value,size,0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
g_getxattr (const char *path, const char *name, void *value, size_t size,
|
|
|
|
gboolean follow_symlinks)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_XATTR_NOFOLLOW
|
|
|
|
return getxattr (path, name, value, size, 0, follow_symlinks ? 0 : XATTR_NOFOLLOW);
|
|
|
|
#else
|
|
|
|
if (follow_symlinks)
|
|
|
|
return getxattr (path, name, value, size);
|
|
|
|
else
|
|
|
|
return lgetxattr (path, name, value, size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
g_listxattr(const char *path, char *namebuf, size_t size,
|
|
|
|
gboolean follow_symlinks)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_XATTR_NOFOLLOW
|
|
|
|
return listxattr (path, namebuf, size, follow_symlinks ? 0 : XATTR_NOFOLLOW);
|
|
|
|
#else
|
|
|
|
if (follow_symlinks)
|
|
|
|
return listxattr (path, namebuf, size);
|
|
|
|
else
|
|
|
|
return llistxattr (path, namebuf, size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
static gboolean
|
|
|
|
valid_char (char c)
|
|
|
|
{
|
|
|
|
return c >= 32 && c <= 126 && c != '\\';
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
name_is_valid (const char *str)
|
|
|
|
{
|
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
if (!valid_char (*str++))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2007-11-30 06:11:25 +01:00
|
|
|
hex_escape_string (const char *str,
|
|
|
|
gboolean *free_return)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
int num_invalid, i;
|
|
|
|
char *escaped_str, *p;
|
|
|
|
unsigned char c;
|
|
|
|
static char *hex_digits = "0123456789abcdef";
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen (str);
|
|
|
|
|
|
|
|
num_invalid = 0;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (!valid_char (str[i]))
|
|
|
|
num_invalid++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_invalid == 0)
|
|
|
|
{
|
|
|
|
*free_return = FALSE;
|
|
|
|
return (char *)str;
|
|
|
|
}
|
|
|
|
|
|
|
|
escaped_str = g_malloc (len + num_invalid*3 + 1);
|
|
|
|
|
|
|
|
p = escaped_str;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (valid_char (str[i]))
|
|
|
|
*p++ = str[i];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c = str[i];
|
|
|
|
*p++ = '\\';
|
|
|
|
*p++ = 'x';
|
|
|
|
*p++ = hex_digits[(c >> 4) & 0xf];
|
|
|
|
*p++ = hex_digits[c & 0xf];
|
|
|
|
}
|
|
|
|
}
|
2009-09-07 09:12:06 +02:00
|
|
|
*p = 0;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
*free_return = TRUE;
|
|
|
|
return escaped_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2007-11-30 06:11:25 +01:00
|
|
|
hex_unescape_string (const char *str,
|
|
|
|
int *out_len,
|
|
|
|
gboolean *free_return)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *unescaped_str, *p;
|
|
|
|
unsigned char c;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen (str);
|
|
|
|
|
|
|
|
if (strchr (str, '\\') == NULL)
|
|
|
|
{
|
|
|
|
if (out_len)
|
|
|
|
*out_len = len;
|
|
|
|
*free_return = FALSE;
|
|
|
|
return (char *)str;
|
|
|
|
}
|
|
|
|
|
|
|
|
unescaped_str = g_malloc (len + 1);
|
|
|
|
|
|
|
|
p = unescaped_str;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (str[i] == '\\' &&
|
|
|
|
str[i+1] == 'x' &&
|
|
|
|
len - i >= 4)
|
|
|
|
{
|
|
|
|
c =
|
|
|
|
(g_ascii_xdigit_value (str[i+2]) << 4) |
|
|
|
|
g_ascii_xdigit_value (str[i+3]);
|
|
|
|
*p++ = c;
|
|
|
|
i += 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*p++ = str[i];
|
|
|
|
}
|
|
|
|
*p++ = 0;
|
|
|
|
|
|
|
|
if (out_len)
|
|
|
|
*out_len = p - unescaped_str;
|
|
|
|
*free_return = TRUE;
|
|
|
|
return unescaped_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-30 06:11:25 +01:00
|
|
|
escape_xattr (GFileInfo *info,
|
2007-11-26 17:13:05 +01:00
|
|
|
const char *gio_attr, /* gio attribute name */
|
|
|
|
const char *value, /* Is zero terminated */
|
2007-11-30 06:11:25 +01:00
|
|
|
size_t len /* not including zero termination */)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
char *escaped_val;
|
|
|
|
gboolean free_escaped_val;
|
|
|
|
|
|
|
|
escaped_val = hex_escape_string (value, &free_escaped_val);
|
|
|
|
|
|
|
|
g_file_info_set_attribute_string (info, gio_attr, escaped_val);
|
|
|
|
|
|
|
|
if (free_escaped_val)
|
|
|
|
g_free (escaped_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_one_xattr (const char *path,
|
2007-11-30 06:11:25 +01:00
|
|
|
GFileInfo *info,
|
2007-11-26 17:13:05 +01:00
|
|
|
const char *gio_attr,
|
|
|
|
const char *xattr,
|
2007-11-30 06:11:25 +01:00
|
|
|
gboolean follow_symlinks)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
char value[64];
|
|
|
|
char *value_p;
|
|
|
|
ssize_t len;
|
|
|
|
|
2007-12-03 11:23:03 +01:00
|
|
|
len = g_getxattr (path, xattr, value, sizeof (value)-1, follow_symlinks);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
value_p = NULL;
|
|
|
|
if (len >= 0)
|
|
|
|
value_p = value;
|
|
|
|
else if (len == -1 && errno == ERANGE)
|
|
|
|
{
|
2007-12-03 11:23:03 +01:00
|
|
|
len = g_getxattr (path, xattr, NULL, 0, follow_symlinks);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
value_p = g_malloc (len+1);
|
|
|
|
|
2007-12-03 11:23:03 +01:00
|
|
|
len = g_getxattr (path, xattr, value_p, len, follow_symlinks);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
{
|
|
|
|
g_free (value_p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Null terminate */
|
|
|
|
value_p[len] = 0;
|
|
|
|
|
|
|
|
escape_xattr (info, gio_attr, value_p, len);
|
|
|
|
|
|
|
|
if (value_p != value)
|
|
|
|
g_free (value_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined HAVE_XATTR */
|
|
|
|
|
|
|
|
static void
|
2007-11-30 06:11:25 +01:00
|
|
|
get_xattrs (const char *path,
|
|
|
|
gboolean user,
|
|
|
|
GFileInfo *info,
|
2007-11-26 17:13:05 +01:00
|
|
|
GFileAttributeMatcher *matcher,
|
2007-11-30 06:11:25 +01:00
|
|
|
gboolean follow_symlinks)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_XATTR
|
|
|
|
gboolean all;
|
|
|
|
gsize list_size;
|
|
|
|
ssize_t list_res_size;
|
|
|
|
size_t len;
|
|
|
|
char *list;
|
|
|
|
const char *attr, *attr2;
|
|
|
|
|
|
|
|
if (user)
|
|
|
|
all = g_file_attribute_matcher_enumerate_namespace (matcher, "xattr");
|
|
|
|
else
|
2008-01-03 10:01:00 +01:00
|
|
|
all = g_file_attribute_matcher_enumerate_namespace (matcher, "xattr-sys");
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (all)
|
|
|
|
{
|
2007-12-03 11:23:03 +01:00
|
|
|
list_res_size = g_listxattr (path, NULL, 0, follow_symlinks);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (list_res_size == -1 ||
|
|
|
|
list_res_size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_size = list_res_size;
|
|
|
|
list = g_malloc (list_size);
|
|
|
|
|
|
|
|
retry:
|
|
|
|
|
2007-12-03 11:23:03 +01:00
|
|
|
list_res_size = g_listxattr (path, list, list_size, follow_symlinks);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (list_res_size == -1 && errno == ERANGE)
|
|
|
|
{
|
|
|
|
list_size = list_size * 2;
|
|
|
|
list = g_realloc (list, list_size);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list_res_size == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
attr = list;
|
|
|
|
while (list_res_size > 0)
|
|
|
|
{
|
|
|
|
if ((user && g_str_has_prefix (attr, "user.")) ||
|
|
|
|
(!user && !g_str_has_prefix (attr, "user.")))
|
|
|
|
{
|
|
|
|
char *escaped_attr, *gio_attr;
|
|
|
|
gboolean free_escaped_attr;
|
|
|
|
|
|
|
|
if (user)
|
|
|
|
{
|
|
|
|
escaped_attr = hex_escape_string (attr + 5, &free_escaped_attr);
|
2007-12-12 16:50:45 +01:00
|
|
|
gio_attr = g_strconcat ("xattr::", escaped_attr, NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
escaped_attr = hex_escape_string (attr, &free_escaped_attr);
|
2007-12-12 16:50:45 +01:00
|
|
|
gio_attr = g_strconcat ("xattr-sys::", escaped_attr, NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (free_escaped_attr)
|
|
|
|
g_free (escaped_attr);
|
|
|
|
|
|
|
|
get_one_xattr (path, info, gio_attr, attr, follow_symlinks);
|
2009-01-31 21:06:02 +01:00
|
|
|
|
|
|
|
g_free (gio_attr);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen (attr) + 1;
|
|
|
|
attr += len;
|
|
|
|
list_res_size -= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (list);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while ((attr = g_file_attribute_matcher_enumerate_next (matcher)) != NULL)
|
|
|
|
{
|
|
|
|
char *unescaped_attribute, *a;
|
|
|
|
gboolean free_unescaped_attribute;
|
|
|
|
|
|
|
|
attr2 = strchr (attr, ':');
|
|
|
|
if (attr2)
|
|
|
|
{
|
2009-04-22 20:09:34 +02:00
|
|
|
attr2 += 2; /* Skip '::' */
|
2007-11-26 17:13:05 +01:00
|
|
|
unescaped_attribute = hex_unescape_string (attr2, NULL, &free_unescaped_attribute);
|
|
|
|
if (user)
|
|
|
|
a = g_strconcat ("user.", unescaped_attribute, NULL);
|
|
|
|
else
|
|
|
|
a = unescaped_attribute;
|
|
|
|
|
|
|
|
get_one_xattr (path, info, attr, a, follow_symlinks);
|
|
|
|
|
|
|
|
if (user)
|
|
|
|
g_free (a);
|
|
|
|
|
|
|
|
if (free_unescaped_attribute)
|
|
|
|
g_free (unescaped_attribute);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* defined HAVE_XATTR */
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_XATTR
|
|
|
|
static void
|
2007-11-30 06:11:25 +01:00
|
|
|
get_one_xattr_from_fd (int fd,
|
|
|
|
GFileInfo *info,
|
2007-11-26 17:13:05 +01:00
|
|
|
const char *gio_attr,
|
|
|
|
const char *xattr)
|
|
|
|
{
|
|
|
|
char value[64];
|
|
|
|
char *value_p;
|
|
|
|
ssize_t len;
|
|
|
|
|
2008-01-21 15:02:19 +01:00
|
|
|
len = g_fgetxattr (fd, xattr, value, sizeof (value) - 1);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
value_p = NULL;
|
|
|
|
if (len >= 0)
|
|
|
|
value_p = value;
|
|
|
|
else if (len == -1 && errno == ERANGE)
|
|
|
|
{
|
2007-12-03 11:23:03 +01:00
|
|
|
len = g_fgetxattr (fd, xattr, NULL, 0);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
return;
|
|
|
|
|
2008-01-21 15:02:19 +01:00
|
|
|
value_p = g_malloc (len + 1);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2007-12-03 11:23:03 +01:00
|
|
|
len = g_fgetxattr (fd, xattr, value_p, len);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
{
|
|
|
|
g_free (value_p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Null terminate */
|
|
|
|
value_p[len] = 0;
|
|
|
|
|
|
|
|
escape_xattr (info, gio_attr, value_p, len);
|
|
|
|
|
|
|
|
if (value_p != value)
|
|
|
|
g_free (value_p);
|
|
|
|
}
|
|
|
|
#endif /* defined HAVE_XATTR */
|
|
|
|
|
|
|
|
static void
|
2007-11-30 06:11:25 +01:00
|
|
|
get_xattrs_from_fd (int fd,
|
|
|
|
gboolean user,
|
|
|
|
GFileInfo *info,
|
2007-11-26 17:13:05 +01:00
|
|
|
GFileAttributeMatcher *matcher)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_XATTR
|
|
|
|
gboolean all;
|
|
|
|
gsize list_size;
|
|
|
|
ssize_t list_res_size;
|
|
|
|
size_t len;
|
|
|
|
char *list;
|
|
|
|
const char *attr, *attr2;
|
|
|
|
|
|
|
|
if (user)
|
|
|
|
all = g_file_attribute_matcher_enumerate_namespace (matcher, "xattr");
|
|
|
|
else
|
2007-12-12 16:50:45 +01:00
|
|
|
all = g_file_attribute_matcher_enumerate_namespace (matcher, "xattr-sys");
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (all)
|
|
|
|
{
|
2007-12-03 11:23:03 +01:00
|
|
|
list_res_size = g_flistxattr (fd, NULL, 0);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (list_res_size == -1 ||
|
|
|
|
list_res_size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_size = list_res_size;
|
|
|
|
list = g_malloc (list_size);
|
|
|
|
|
|
|
|
retry:
|
|
|
|
|
2007-12-03 11:23:03 +01:00
|
|
|
list_res_size = g_flistxattr (fd, list, list_size);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (list_res_size == -1 && errno == ERANGE)
|
|
|
|
{
|
|
|
|
list_size = list_size * 2;
|
|
|
|
list = g_realloc (list, list_size);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list_res_size == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
attr = list;
|
|
|
|
while (list_res_size > 0)
|
|
|
|
{
|
|
|
|
if ((user && g_str_has_prefix (attr, "user.")) ||
|
|
|
|
(!user && !g_str_has_prefix (attr, "user.")))
|
|
|
|
{
|
|
|
|
char *escaped_attr, *gio_attr;
|
|
|
|
gboolean free_escaped_attr;
|
|
|
|
|
|
|
|
if (user)
|
|
|
|
{
|
|
|
|
escaped_attr = hex_escape_string (attr + 5, &free_escaped_attr);
|
2007-12-12 16:50:45 +01:00
|
|
|
gio_attr = g_strconcat ("xattr::", escaped_attr, NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
escaped_attr = hex_escape_string (attr, &free_escaped_attr);
|
2007-12-12 16:50:45 +01:00
|
|
|
gio_attr = g_strconcat ("xattr-sys::", escaped_attr, NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (free_escaped_attr)
|
|
|
|
g_free (escaped_attr);
|
|
|
|
|
|
|
|
get_one_xattr_from_fd (fd, info, gio_attr, attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen (attr) + 1;
|
|
|
|
attr += len;
|
|
|
|
list_res_size -= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (list);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while ((attr = g_file_attribute_matcher_enumerate_next (matcher)) != NULL)
|
|
|
|
{
|
|
|
|
char *unescaped_attribute, *a;
|
|
|
|
gboolean free_unescaped_attribute;
|
|
|
|
|
|
|
|
attr2 = strchr (attr, ':');
|
|
|
|
if (attr2)
|
|
|
|
{
|
|
|
|
attr2++; /* Skip ':' */
|
|
|
|
unescaped_attribute = hex_unescape_string (attr2, NULL, &free_unescaped_attribute);
|
|
|
|
if (user)
|
|
|
|
a = g_strconcat ("user.", unescaped_attribute, NULL);
|
|
|
|
else
|
|
|
|
a = unescaped_attribute;
|
|
|
|
|
|
|
|
get_one_xattr_from_fd (fd, info, attr, a);
|
|
|
|
|
|
|
|
if (user)
|
|
|
|
g_free (a);
|
|
|
|
|
|
|
|
if (free_unescaped_attribute)
|
|
|
|
g_free (unescaped_attribute);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* defined HAVE_XATTR */
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_XATTR
|
|
|
|
static gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
set_xattr (char *filename,
|
|
|
|
const char *escaped_attribute,
|
|
|
|
const GFileAttributeValue *attr_value,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
char *attribute, *value;
|
|
|
|
gboolean free_attribute, free_value;
|
|
|
|
int val_len, res, errsv;
|
|
|
|
gboolean is_user;
|
|
|
|
char *a;
|
|
|
|
|
|
|
|
if (attr_value == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Attribute value must be non-NULL"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr_value->type != G_FILE_ATTRIBUTE_TYPE_STRING)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Invalid attribute type (string expected)"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name_is_valid (escaped_attribute))
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Invalid extended attribute name"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-12-12 16:50:45 +01:00
|
|
|
if (g_str_has_prefix (escaped_attribute, "xattr::"))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2008-06-10 17:55:31 +02:00
|
|
|
escaped_attribute += strlen ("xattr::");
|
2007-11-26 17:13:05 +01:00
|
|
|
is_user = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-12 16:50:45 +01:00
|
|
|
g_warn_if_fail (g_str_has_prefix (escaped_attribute, "xattr-sys::"));
|
2008-06-10 17:55:31 +02:00
|
|
|
escaped_attribute += strlen ("xattr-sys::");
|
2007-11-26 17:13:05 +01:00
|
|
|
is_user = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = hex_unescape_string (escaped_attribute, NULL, &free_attribute);
|
|
|
|
value = hex_unescape_string (attr_value->u.string, &val_len, &free_value);
|
|
|
|
|
|
|
|
if (is_user)
|
|
|
|
a = g_strconcat ("user.", attribute, NULL);
|
|
|
|
else
|
|
|
|
a = attribute;
|
|
|
|
|
2007-12-03 11:23:03 +01:00
|
|
|
res = g_setxattr (filename, a, value, val_len);
|
2007-11-26 17:13:05 +01:00
|
|
|
errsv = errno;
|
|
|
|
|
|
|
|
if (is_user)
|
|
|
|
g_free (a);
|
|
|
|
|
|
|
|
if (free_attribute)
|
|
|
|
g_free (attribute);
|
|
|
|
|
|
|
|
if (free_value)
|
|
|
|
g_free (value);
|
|
|
|
|
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
g_io_error_from_errno (errsv),
|
|
|
|
_("Error setting extended attribute '%s': %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
escaped_attribute, g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2007-11-30 06:11:25 +01:00
|
|
|
_g_local_file_info_get_parent_info (const char *dir,
|
|
|
|
GFileAttributeMatcher *attribute_matcher,
|
|
|
|
GLocalParentFileInfo *parent_info)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2010-03-21 19:04:18 +01:00
|
|
|
GStatBuf statbuf;
|
2007-11-26 17:13:05 +01:00
|
|
|
int res;
|
2009-06-18 09:05:27 +02:00
|
|
|
|
|
|
|
parent_info->extra_data = NULL;
|
|
|
|
parent_info->free_extra_data = NULL;
|
2007-11-26 17:13:05 +01:00
|
|
|
parent_info->writable = FALSE;
|
|
|
|
parent_info->is_sticky = FALSE;
|
2008-03-11 15:48:28 +01:00
|
|
|
parent_info->has_trash_dir = FALSE;
|
2007-11-26 17:13:05 +01:00
|
|
|
parent_info->device = 0;
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME) ||
|
|
|
|
_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE) ||
|
|
|
|
_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH) ||
|
|
|
|
_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2008-03-12 19:33:59 +01:00
|
|
|
/* FIXME: Windows: The underlying _waccess() call in the C
|
|
|
|
* library is mostly pointless as it only looks at the READONLY
|
|
|
|
* FAT-style attribute of the file, it doesn't check the ACL at
|
|
|
|
* all.
|
|
|
|
*/
|
2007-11-26 17:13:05 +01:00
|
|
|
parent_info->writable = (g_access (dir, W_OK) == 0);
|
|
|
|
|
|
|
|
res = g_stat (dir, &statbuf);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The sticky bit (S_ISVTX) on a directory means that a file in that directory can be
|
|
|
|
* renamed or deleted only by the owner of the file, by the owner of the directory, and
|
|
|
|
* by a privileged process.
|
|
|
|
*/
|
|
|
|
if (res == 0)
|
|
|
|
{
|
2007-12-08 13:01:06 +01:00
|
|
|
#ifdef S_ISVTX
|
2007-11-26 17:13:05 +01:00
|
|
|
parent_info->is_sticky = (statbuf.st_mode & S_ISVTX) != 0;
|
2007-12-08 13:01:06 +01:00
|
|
|
#else
|
|
|
|
parent_info->is_sticky = FALSE;
|
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
parent_info->owner = statbuf.st_uid;
|
|
|
|
parent_info->device = statbuf.st_dev;
|
2009-02-23 05:30:06 +01:00
|
|
|
/* No need to find trash dir if it's not writable anyway */
|
2008-03-11 15:48:28 +01:00
|
|
|
if (parent_info->writable &&
|
2009-06-29 14:13:14 +02:00
|
|
|
_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH))
|
2008-03-11 15:48:28 +01:00
|
|
|
parent_info->has_trash_dir = _g_local_file_has_trash_dir (dir, statbuf.st_dev);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-18 09:05:27 +02:00
|
|
|
void
|
|
|
|
_g_local_file_info_free_parent_info (GLocalParentFileInfo *parent_info)
|
|
|
|
{
|
|
|
|
if (parent_info->extra_data &&
|
|
|
|
parent_info->free_extra_data)
|
|
|
|
parent_info->free_extra_data (parent_info->extra_data);
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
static void
|
|
|
|
get_access_rights (GFileAttributeMatcher *attribute_matcher,
|
2007-11-30 06:11:25 +01:00
|
|
|
GFileInfo *info,
|
|
|
|
const gchar *path,
|
2008-03-12 19:33:59 +01:00
|
|
|
GLocalFileStat *statbuf,
|
2007-11-30 06:11:25 +01:00
|
|
|
GLocalParentFileInfo *parent_info)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2008-03-12 19:33:59 +01:00
|
|
|
/* FIXME: Windows: The underlyin _waccess() is mostly pointless */
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ))
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ,
|
|
|
|
g_access (path, R_OK) == 0);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE))
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE,
|
|
|
|
g_access (path, W_OK) == 0);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE))
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE,
|
|
|
|
g_access (path, X_OK) == 0);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (parent_info)
|
|
|
|
{
|
|
|
|
gboolean writable;
|
|
|
|
|
|
|
|
writable = FALSE;
|
|
|
|
if (parent_info->writable)
|
|
|
|
{
|
|
|
|
if (parent_info->is_sticky)
|
|
|
|
{
|
2007-12-08 13:01:06 +01:00
|
|
|
#ifndef G_OS_WIN32
|
2007-11-26 17:13:05 +01:00
|
|
|
uid_t uid = geteuid ();
|
|
|
|
|
|
|
|
if (uid == statbuf->st_uid ||
|
|
|
|
uid == parent_info->owner ||
|
|
|
|
uid == 0)
|
2007-12-08 13:01:06 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
writable = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
writable = TRUE;
|
|
|
|
}
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME))
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME,
|
|
|
|
writable);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE))
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE,
|
|
|
|
writable);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH))
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH,
|
|
|
|
writable && parent_info->has_trash_dir);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-30 06:11:25 +01:00
|
|
|
set_info_from_stat (GFileInfo *info,
|
2008-03-12 19:33:59 +01:00
|
|
|
GLocalFileStat *statbuf,
|
2007-11-26 17:13:05 +01:00
|
|
|
GFileAttributeMatcher *attribute_matcher)
|
|
|
|
{
|
|
|
|
GFileType file_type;
|
|
|
|
|
|
|
|
file_type = G_FILE_TYPE_UNKNOWN;
|
|
|
|
|
|
|
|
if (S_ISREG (statbuf->st_mode))
|
|
|
|
file_type = G_FILE_TYPE_REGULAR;
|
|
|
|
else if (S_ISDIR (statbuf->st_mode))
|
|
|
|
file_type = G_FILE_TYPE_DIRECTORY;
|
2007-12-08 13:01:06 +01:00
|
|
|
#ifndef G_OS_WIN32
|
2007-11-26 17:13:05 +01:00
|
|
|
else if (S_ISCHR (statbuf->st_mode) ||
|
|
|
|
S_ISBLK (statbuf->st_mode) ||
|
|
|
|
S_ISFIFO (statbuf->st_mode)
|
|
|
|
#ifdef S_ISSOCK
|
|
|
|
|| S_ISSOCK (statbuf->st_mode)
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
file_type = G_FILE_TYPE_SPECIAL;
|
2007-12-08 13:01:06 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
#ifdef S_ISLNK
|
|
|
|
else if (S_ISLNK (statbuf->st_mode))
|
|
|
|
file_type = G_FILE_TYPE_SYMBOLIC_LINK;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
g_file_info_set_file_type (info, file_type);
|
|
|
|
g_file_info_set_size (info, statbuf->st_size);
|
|
|
|
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_DEVICE, statbuf->st_dev);
|
2008-03-12 19:33:59 +01:00
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
/* Pointless setting these on Windows even if they exist in the struct */
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_INODE, statbuf->st_ino);
|
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_NLINK, statbuf->st_nlink);
|
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_UID, statbuf->st_uid);
|
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_GID, statbuf->st_gid);
|
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_RDEV, statbuf->st_rdev);
|
2008-03-12 19:33:59 +01:00
|
|
|
#endif
|
|
|
|
/* FIXME: st_mode is mostly pointless on Windows, too. Set the attribute or not? */
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_MODE, statbuf->st_mode);
|
2007-12-25 22:21:32 +01:00
|
|
|
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_BLOCK_SIZE, statbuf->st_blksize);
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
2007-12-25 22:21:32 +01:00
|
|
|
#if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_BLOCKS, statbuf->st_blocks);
|
|
|
|
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_ALLOCATED_SIZE,
|
|
|
|
statbuf->st_blocks * G_GUINT64_CONSTANT (512));
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
|
|
|
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED, statbuf->st_mtime);
|
2007-11-26 17:13:05 +01:00
|
|
|
#if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC, statbuf->st_mtimensec / 1000);
|
2007-11-26 17:13:05 +01:00
|
|
|
#elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC, statbuf->st_mtim.tv_nsec / 1000);
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
|
|
|
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_ACCESS, statbuf->st_atime);
|
2007-11-26 17:13:05 +01:00
|
|
|
#if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC, statbuf->st_atimensec / 1000);
|
2007-11-26 17:13:05 +01:00
|
|
|
#elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC, statbuf->st_atim.tv_nsec / 1000);
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
|
|
|
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CHANGED, statbuf->st_ctime);
|
2007-11-26 17:13:05 +01:00
|
|
|
#if defined (HAVE_STRUCT_STAT_ST_CTIMENSEC)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC, statbuf->st_ctimensec / 1000);
|
2007-11-26 17:13:05 +01:00
|
|
|
#elif defined (HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC, statbuf->st_ctim.tv_nsec / 1000);
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_ETAG_VALUE))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
char *etag = _g_local_file_info_create_etag (statbuf);
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_ETAG_VALUE, etag);
|
2007-11-26 17:13:05 +01:00
|
|
|
g_free (etag);
|
|
|
|
}
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_ID_FILE))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
char *id = _g_local_file_info_create_file_id (statbuf);
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_ID_FILE, id);
|
2007-11-26 17:13:05 +01:00
|
|
|
g_free (id);
|
|
|
|
}
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_ID_FILESYSTEM))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
char *id = _g_local_file_info_create_fs_id (statbuf);
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_ID_FILESYSTEM, id);
|
2007-11-26 17:13:05 +01:00
|
|
|
g_free (id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-12 19:33:59 +01:00
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
static char *
|
|
|
|
make_valid_utf8 (const char *name)
|
|
|
|
{
|
|
|
|
GString *string;
|
|
|
|
const gchar *remainder, *invalid;
|
|
|
|
gint remaining_bytes, valid_bytes;
|
|
|
|
|
|
|
|
string = NULL;
|
|
|
|
remainder = name;
|
|
|
|
remaining_bytes = strlen (name);
|
|
|
|
|
|
|
|
while (remaining_bytes != 0)
|
|
|
|
{
|
|
|
|
if (g_utf8_validate (remainder, remaining_bytes, &invalid))
|
|
|
|
break;
|
|
|
|
valid_bytes = invalid - remainder;
|
|
|
|
|
|
|
|
if (string == NULL)
|
|
|
|
string = g_string_sized_new (remaining_bytes);
|
|
|
|
|
|
|
|
g_string_append_len (string, remainder, valid_bytes);
|
|
|
|
/* append U+FFFD REPLACEMENT CHARACTER */
|
|
|
|
g_string_append (string, "\357\277\275");
|
|
|
|
|
|
|
|
remaining_bytes -= valid_bytes + 1;
|
|
|
|
remainder = invalid + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string == NULL)
|
|
|
|
return g_strdup (name);
|
|
|
|
|
|
|
|
g_string_append (string, remainder);
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_utf8_validate (string->str, -1, NULL));
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
return g_string_free (string, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
convert_pwd_string_to_utf8 (char *pwd_str)
|
|
|
|
{
|
|
|
|
char *utf8_string;
|
|
|
|
|
|
|
|
if (!g_utf8_validate (pwd_str, -1, NULL))
|
|
|
|
{
|
|
|
|
utf8_string = g_locale_to_utf8 (pwd_str, -1, NULL, NULL, NULL);
|
|
|
|
if (utf8_string == NULL)
|
|
|
|
utf8_string = make_valid_utf8 (pwd_str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
utf8_string = g_strdup (pwd_str);
|
|
|
|
|
|
|
|
return utf8_string;
|
|
|
|
}
|
2008-03-12 19:33:59 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
static void
|
|
|
|
uid_data_free (UidData *data)
|
|
|
|
{
|
|
|
|
g_free (data->user_name);
|
|
|
|
g_free (data->real_name);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called with lock held */
|
|
|
|
static UidData *
|
|
|
|
lookup_uid_data (uid_t uid)
|
|
|
|
{
|
|
|
|
UidData *data;
|
|
|
|
char buffer[4096];
|
|
|
|
struct passwd pwbuf;
|
|
|
|
struct passwd *pwbufp;
|
|
|
|
char *gecos, *comma;
|
|
|
|
|
|
|
|
if (uid_cache == NULL)
|
|
|
|
uid_cache = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)uid_data_free);
|
|
|
|
|
|
|
|
data = g_hash_table_lookup (uid_cache, GINT_TO_POINTER (uid));
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
return data;
|
|
|
|
|
|
|
|
data = g_new0 (UidData, 1);
|
|
|
|
|
|
|
|
#if defined(HAVE_POSIX_GETPWUID_R)
|
|
|
|
getpwuid_r (uid, &pwbuf, buffer, sizeof(buffer), &pwbufp);
|
|
|
|
#elif defined(HAVE_NONPOSIX_GETPWUID_R)
|
|
|
|
pwbufp = getpwuid_r (uid, &pwbuf, buffer, sizeof(buffer));
|
|
|
|
#else
|
|
|
|
pwbufp = getpwuid (uid);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (pwbufp != NULL)
|
|
|
|
{
|
|
|
|
if (pwbufp->pw_name != NULL && pwbufp->pw_name[0] != 0)
|
|
|
|
data->user_name = convert_pwd_string_to_utf8 (pwbufp->pw_name);
|
|
|
|
|
|
|
|
gecos = pwbufp->pw_gecos;
|
|
|
|
|
|
|
|
if (gecos)
|
|
|
|
{
|
|
|
|
comma = strchr (gecos, ',');
|
|
|
|
if (comma)
|
|
|
|
*comma = 0;
|
|
|
|
data->real_name = convert_pwd_string_to_utf8 (gecos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default fallbacks */
|
|
|
|
if (data->real_name == NULL)
|
|
|
|
{
|
|
|
|
if (data->user_name != NULL)
|
|
|
|
data->real_name = g_strdup (data->user_name);
|
|
|
|
else
|
2008-01-21 15:02:19 +01:00
|
|
|
data->real_name = g_strdup_printf ("user #%d", (int)uid);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data->user_name == NULL)
|
2008-01-21 15:02:19 +01:00
|
|
|
data->user_name = g_strdup_printf ("%d", (int)uid);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
g_hash_table_replace (uid_cache, GINT_TO_POINTER (uid), data);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_username_from_uid (uid_t uid)
|
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
UidData *data;
|
|
|
|
|
|
|
|
G_LOCK (uid_cache);
|
|
|
|
data = lookup_uid_data (uid);
|
|
|
|
res = g_strdup (data->user_name);
|
|
|
|
G_UNLOCK (uid_cache);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_realname_from_uid (uid_t uid)
|
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
UidData *data;
|
|
|
|
|
|
|
|
G_LOCK (uid_cache);
|
|
|
|
data = lookup_uid_data (uid);
|
|
|
|
res = g_strdup (data->real_name);
|
|
|
|
G_UNLOCK (uid_cache);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called with lock held */
|
|
|
|
static char *
|
|
|
|
lookup_gid_name (gid_t gid)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
char buffer[4096];
|
|
|
|
struct group gbuf;
|
|
|
|
struct group *gbufp;
|
|
|
|
|
|
|
|
if (gid_cache == NULL)
|
|
|
|
gid_cache = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_free);
|
|
|
|
|
|
|
|
name = g_hash_table_lookup (gid_cache, GINT_TO_POINTER (gid));
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
return name;
|
|
|
|
|
|
|
|
#if defined (HAVE_POSIX_GETGRGID_R)
|
|
|
|
getgrgid_r (gid, &gbuf, buffer, sizeof(buffer), &gbufp);
|
|
|
|
#elif defined (HAVE_NONPOSIX_GETGRGID_R)
|
|
|
|
gbufp = getgrgid_r (gid, &gbuf, buffer, sizeof(buffer));
|
|
|
|
#else
|
|
|
|
gbufp = getgrgid (gid);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (gbufp != NULL &&
|
|
|
|
gbufp->gr_name != NULL &&
|
|
|
|
gbufp->gr_name[0] != 0)
|
|
|
|
name = convert_pwd_string_to_utf8 (gbufp->gr_name);
|
|
|
|
else
|
|
|
|
name = g_strdup_printf("%d", (int)gid);
|
|
|
|
|
|
|
|
g_hash_table_replace (gid_cache, GINT_TO_POINTER (gid), name);
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_groupname_from_gid (gid_t gid)
|
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
G_LOCK (gid_cache);
|
|
|
|
name = lookup_gid_name (gid);
|
|
|
|
res = g_strdup (name);
|
|
|
|
G_UNLOCK (gid_cache);
|
|
|
|
return res;
|
|
|
|
}
|
2008-03-12 19:33:59 +01:00
|
|
|
|
2007-12-08 13:01:06 +01:00
|
|
|
#endif /* !G_OS_WIN32 */
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
static char *
|
2007-11-30 06:11:25 +01:00
|
|
|
get_content_type (const char *basename,
|
|
|
|
const char *path,
|
2008-03-12 19:33:59 +01:00
|
|
|
GLocalFileStat *statbuf,
|
2007-11-30 06:11:25 +01:00
|
|
|
gboolean is_symlink,
|
|
|
|
gboolean symlink_broken,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
gboolean fast)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
if (is_symlink &&
|
|
|
|
(symlink_broken || (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)))
|
2010-07-08 20:19:08 +02:00
|
|
|
return g_strdup ("inode/symlink");
|
|
|
|
else if (statbuf != NULL && S_ISDIR(statbuf->st_mode))
|
2007-11-26 17:13:05 +01:00
|
|
|
return g_strdup ("inode/directory");
|
2007-12-08 13:01:06 +01:00
|
|
|
#ifndef G_OS_WIN32
|
2010-07-08 20:19:08 +02:00
|
|
|
else if (statbuf != NULL && S_ISCHR(statbuf->st_mode))
|
2007-11-26 17:13:05 +01:00
|
|
|
return g_strdup ("inode/chardevice");
|
2010-07-08 20:19:08 +02:00
|
|
|
else if (statbuf != NULL && S_ISBLK(statbuf->st_mode))
|
2007-11-26 17:13:05 +01:00
|
|
|
return g_strdup ("inode/blockdevice");
|
2010-07-08 20:19:08 +02:00
|
|
|
else if (statbuf != NULL && S_ISFIFO(statbuf->st_mode))
|
2007-11-26 17:13:05 +01:00
|
|
|
return g_strdup ("inode/fifo");
|
2007-12-08 13:01:06 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
#ifdef S_ISSOCK
|
2010-07-08 20:19:08 +02:00
|
|
|
else if (statbuf != NULL && S_ISSOCK(statbuf->st_mode))
|
2007-11-26 17:13:05 +01:00
|
|
|
return g_strdup ("inode/socket");
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *content_type;
|
|
|
|
gboolean result_uncertain;
|
|
|
|
|
|
|
|
content_type = g_content_type_guess (basename, NULL, 0, &result_uncertain);
|
|
|
|
|
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
if (!fast && result_uncertain && path != NULL)
|
|
|
|
{
|
|
|
|
guchar sniff_buffer[4096];
|
|
|
|
gsize sniff_length;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
sniff_length = _g_unix_content_type_get_sniff_len ();
|
|
|
|
if (sniff_length > 4096)
|
|
|
|
sniff_length = 4096;
|
2009-01-05 17:20:40 +01:00
|
|
|
|
|
|
|
#ifdef O_NOATIME
|
2012-08-28 00:30:06 +02:00
|
|
|
fd = g_open (path, O_RDONLY | O_NOATIME, 0);
|
2009-01-05 17:20:40 +01:00
|
|
|
if (fd < 0 && errno == EPERM)
|
|
|
|
#endif
|
2012-08-28 00:30:06 +02:00
|
|
|
fd = g_open (path, O_RDONLY, 0);
|
2009-01-05 17:20:40 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
if (fd != -1)
|
|
|
|
{
|
|
|
|
ssize_t res;
|
|
|
|
|
|
|
|
res = read (fd, sniff_buffer, sniff_length);
|
|
|
|
close (fd);
|
2008-02-29 10:49:08 +01:00
|
|
|
if (res >= 0)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
g_free (content_type);
|
|
|
|
content_type = g_content_type_guess (basename, sniff_buffer, res, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return content_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_thumbnail_attributes (const char *path,
|
2007-11-30 06:11:25 +01:00
|
|
|
GFileInfo *info)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-04 17:33:24 +01:00
|
|
|
GChecksum *checksum;
|
2007-11-26 17:13:05 +01:00
|
|
|
char *uri;
|
|
|
|
char *filename;
|
|
|
|
char *basename;
|
|
|
|
|
|
|
|
uri = g_filename_to_uri (path, NULL, NULL);
|
|
|
|
|
2007-12-04 17:33:24 +01:00
|
|
|
checksum = g_checksum_new (G_CHECKSUM_MD5);
|
2007-12-14 12:07:31 +01:00
|
|
|
g_checksum_update (checksum, (const guchar *) uri, strlen (uri));
|
2008-01-22 14:24:48 +01:00
|
|
|
|
|
|
|
g_free (uri);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2007-12-04 17:33:24 +01:00
|
|
|
basename = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
|
|
|
|
g_checksum_free (checksum);
|
|
|
|
|
2012-04-30 18:51:25 +02:00
|
|
|
filename = g_build_filename (g_get_user_cache_dir (),
|
2012-05-01 04:39:57 +02:00
|
|
|
"thumbnails", "large", basename,
|
2007-12-04 17:33:24 +01:00
|
|
|
NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_byte_string_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH, filename);
|
2007-11-26 17:13:05 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (filename);
|
2012-04-30 18:51:25 +02:00
|
|
|
filename = g_build_filename (g_get_user_cache_dir (),
|
2012-05-01 04:39:57 +02:00
|
|
|
"thumbnails", "normal", basename,
|
2007-12-04 17:33:24 +01:00
|
|
|
NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
|
2012-05-01 04:39:57 +02:00
|
|
|
_g_file_info_set_attribute_byte_string_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH, filename);
|
|
|
|
else
|
|
|
|
{
|
2012-11-20 00:11:56 +01:00
|
|
|
g_free (filename);
|
2012-05-01 04:39:57 +02:00
|
|
|
filename = g_build_filename (g_get_user_cache_dir (),
|
|
|
|
"thumbnails", "fail",
|
|
|
|
"gnome-thumbnail-factory",
|
|
|
|
basename,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
|
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_THUMBNAILING_FAILED, TRUE);
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
g_free (basename);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
|
2007-12-08 15:29:37 +01:00
|
|
|
#ifdef G_OS_WIN32
|
2007-12-09 23:10:40 +01:00
|
|
|
static void
|
2008-01-21 15:02:19 +01:00
|
|
|
win32_get_file_user_info (const gchar *filename,
|
|
|
|
gchar **group_name,
|
|
|
|
gchar **user_name,
|
|
|
|
gchar **real_name)
|
2007-12-08 13:01:06 +01:00
|
|
|
{
|
|
|
|
PSECURITY_DESCRIPTOR psd = NULL;
|
2007-12-09 23:10:40 +01:00
|
|
|
DWORD sd_size = 0; /* first call calculates the size required */
|
2007-12-08 13:01:06 +01:00
|
|
|
|
|
|
|
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
|
|
|
|
if ((GetFileSecurityW (wfilename,
|
|
|
|
GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
|
|
|
|
NULL,
|
|
|
|
sd_size,
|
|
|
|
&sd_size) || (ERROR_INSUFFICIENT_BUFFER == GetLastError())) &&
|
|
|
|
(psd = g_try_malloc (sd_size)) != NULL &&
|
|
|
|
GetFileSecurityW (wfilename,
|
2007-12-09 23:10:40 +01:00
|
|
|
GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
|
|
|
|
psd,
|
|
|
|
sd_size,
|
|
|
|
&sd_size))
|
2007-12-08 13:01:06 +01:00
|
|
|
{
|
2007-12-12 13:19:02 +01:00
|
|
|
PSID psid = 0;
|
2007-12-09 23:10:40 +01:00
|
|
|
BOOL defaulted;
|
|
|
|
SID_NAME_USE name_use = 0; /* don't care? */
|
2007-12-12 13:19:02 +01:00
|
|
|
wchar_t *name = NULL;
|
|
|
|
wchar_t *domain = NULL;
|
|
|
|
DWORD name_len = 0;
|
|
|
|
DWORD domain_len = 0;
|
|
|
|
/* get the user name */
|
|
|
|
do {
|
|
|
|
if (!user_name)
|
|
|
|
break;
|
|
|
|
if (!GetSecurityDescriptorOwner (psd, &psid, &defaulted))
|
|
|
|
break;
|
|
|
|
if (!LookupAccountSidW (NULL, /* local machine */
|
|
|
|
psid,
|
|
|
|
name, &name_len,
|
|
|
|
domain, &domain_len, /* no domain info yet */
|
|
|
|
&name_use) && (ERROR_INSUFFICIENT_BUFFER != GetLastError()))
|
|
|
|
break;
|
2008-01-21 15:02:19 +01:00
|
|
|
name = g_try_malloc (name_len * sizeof (wchar_t));
|
|
|
|
domain = g_try_malloc (domain_len * sizeof (wchar_t));
|
2007-12-12 13:19:02 +01:00
|
|
|
if (name && domain &&
|
|
|
|
LookupAccountSidW (NULL, /* local machine */
|
|
|
|
psid,
|
|
|
|
name, &name_len,
|
|
|
|
domain, &domain_len, /* no domain info yet */
|
|
|
|
&name_use))
|
|
|
|
{
|
|
|
|
*user_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
g_free (name);
|
|
|
|
g_free (domain);
|
|
|
|
} while (FALSE);
|
|
|
|
|
|
|
|
/* get the group name */
|
|
|
|
do {
|
|
|
|
if (!group_name)
|
|
|
|
break;
|
|
|
|
if (!GetSecurityDescriptorGroup (psd, &psid, &defaulted))
|
|
|
|
break;
|
|
|
|
if (!LookupAccountSidW (NULL, /* local machine */
|
|
|
|
psid,
|
|
|
|
name, &name_len,
|
|
|
|
domain, &domain_len, /* no domain info yet */
|
|
|
|
&name_use) && (ERROR_INSUFFICIENT_BUFFER != GetLastError()))
|
|
|
|
break;
|
2008-01-21 15:02:19 +01:00
|
|
|
name = g_try_malloc (name_len * sizeof (wchar_t));
|
|
|
|
domain = g_try_malloc (domain_len * sizeof (wchar_t));
|
2007-12-12 13:19:02 +01:00
|
|
|
if (name && domain &&
|
|
|
|
LookupAccountSidW (NULL, /* local machine */
|
|
|
|
psid,
|
|
|
|
name, &name_len,
|
|
|
|
domain, &domain_len, /* no domain info yet */
|
|
|
|
&name_use))
|
|
|
|
{
|
|
|
|
*group_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
g_free (name);
|
|
|
|
g_free (domain);
|
|
|
|
} while (FALSE);
|
|
|
|
|
|
|
|
/* TODO: get real name */
|
|
|
|
|
|
|
|
g_free (psd);
|
2007-12-08 13:01:06 +01:00
|
|
|
}
|
|
|
|
g_free (wfilename);
|
|
|
|
}
|
2007-12-08 15:29:37 +01:00
|
|
|
#endif /* G_OS_WIN32 */
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2011-11-01 23:37:35 +01:00
|
|
|
void
|
|
|
|
_g_local_file_info_get_nostat (GFileInfo *info,
|
|
|
|
const char *basename,
|
|
|
|
const char *path,
|
|
|
|
GFileAttributeMatcher *attribute_matcher)
|
|
|
|
{
|
|
|
|
g_file_info_set_name (info, basename);
|
|
|
|
|
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_STANDARD_DISPLAY_NAME))
|
|
|
|
{
|
|
|
|
char *display_name = g_filename_display_basename (path);
|
|
|
|
|
|
|
|
/* look for U+FFFD REPLACEMENT CHARACTER */
|
|
|
|
if (strstr (display_name, "\357\277\275") != NULL)
|
|
|
|
{
|
|
|
|
char *p = display_name;
|
|
|
|
display_name = g_strconcat (display_name, _(" (invalid encoding)"), NULL);
|
|
|
|
g_free (p);
|
|
|
|
}
|
|
|
|
g_file_info_set_display_name (info, display_name);
|
|
|
|
g_free (display_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_STANDARD_EDIT_NAME))
|
|
|
|
{
|
|
|
|
char *edit_name = g_filename_display_basename (path);
|
|
|
|
g_file_info_set_edit_name (info, edit_name);
|
|
|
|
g_free (edit_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_STANDARD_COPY_NAME))
|
|
|
|
{
|
|
|
|
char *copy_name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
|
|
|
|
if (copy_name)
|
|
|
|
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_COPY_NAME, copy_name);
|
|
|
|
g_free (copy_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-29 00:56:53 +02:00
|
|
|
static const char *
|
|
|
|
get_icon_name (const char *path,
|
|
|
|
gboolean use_symbolic,
|
|
|
|
gboolean *with_fallbacks_out)
|
|
|
|
{
|
|
|
|
const char *name = NULL;
|
|
|
|
gboolean with_fallbacks = TRUE;
|
|
|
|
|
|
|
|
if (strcmp (path, g_get_home_dir ()) == 0)
|
|
|
|
{
|
|
|
|
name = use_symbolic ? "user-home-symbolic" : "user-home";
|
|
|
|
with_fallbacks = FALSE;
|
|
|
|
}
|
|
|
|
else if (strcmp (path, g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP)) == 0)
|
|
|
|
{
|
|
|
|
name = use_symbolic ? "user-desktop-symbolic" : "user-desktop";
|
|
|
|
with_fallbacks = FALSE;
|
|
|
|
}
|
|
|
|
else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS)) == 0)
|
|
|
|
{
|
|
|
|
name = use_symbolic ? "folder-documents-symbolic" : "folder-documents";
|
|
|
|
}
|
|
|
|
else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD)) == 0)
|
|
|
|
{
|
|
|
|
name = use_symbolic ? "folder-download-symbolic" : "folder-download";
|
|
|
|
}
|
|
|
|
else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_MUSIC)) == 0)
|
|
|
|
{
|
|
|
|
name = use_symbolic ? "folder-music-symbolic" : "folder-music";
|
|
|
|
}
|
|
|
|
else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES)) == 0)
|
|
|
|
{
|
|
|
|
name = use_symbolic ? "folder-pictures-symbolic" : "folder-pictures";
|
|
|
|
}
|
|
|
|
else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE)) == 0)
|
|
|
|
{
|
|
|
|
name = use_symbolic ? "folder-publicshare-symbolic" : "folder-publicshare";
|
|
|
|
}
|
|
|
|
else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES)) == 0)
|
|
|
|
{
|
|
|
|
name = use_symbolic ? "folder-templates-symbolic" : "folder-templates";
|
|
|
|
}
|
|
|
|
else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS)) == 0)
|
|
|
|
{
|
|
|
|
name = use_symbolic ? "folder-videos-symbolic" : "folder-videos";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (with_fallbacks_out != NULL)
|
|
|
|
*with_fallbacks_out = with_fallbacks;
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2012-08-29 01:22:01 +02:00
|
|
|
static GIcon *
|
|
|
|
get_icon (const char *path,
|
|
|
|
const char *content_type,
|
|
|
|
gboolean is_folder,
|
|
|
|
gboolean use_symbolic)
|
|
|
|
{
|
|
|
|
GIcon *icon = NULL;
|
|
|
|
const char *icon_name;
|
|
|
|
gboolean with_fallbacks;
|
|
|
|
|
|
|
|
icon_name = get_icon_name (path, use_symbolic, &with_fallbacks);
|
|
|
|
if (icon_name != NULL)
|
|
|
|
{
|
|
|
|
if (with_fallbacks)
|
|
|
|
icon = g_themed_icon_new_with_default_fallbacks (icon_name);
|
|
|
|
else
|
|
|
|
icon = g_themed_icon_new (icon_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-18 11:05:49 +02:00
|
|
|
#ifdef G_OS_UNIX
|
2012-08-29 01:22:01 +02:00
|
|
|
if (use_symbolic)
|
|
|
|
icon = g_content_type_get_symbolic_icon (content_type);
|
|
|
|
else
|
2012-09-18 11:05:49 +02:00
|
|
|
#endif
|
2012-08-29 01:22:01 +02:00
|
|
|
icon = g_content_type_get_icon (content_type);
|
|
|
|
|
|
|
|
if (G_IS_THEMED_ICON (icon) && is_folder)
|
|
|
|
{
|
|
|
|
g_themed_icon_append_name (G_THEMED_ICON (icon), use_symbolic ? "folder-symbolic" : "folder");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
GFileInfo *
|
2007-11-30 06:11:25 +01:00
|
|
|
_g_local_file_info_get (const char *basename,
|
|
|
|
const char *path,
|
|
|
|
GFileAttributeMatcher *attribute_matcher,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GLocalParentFileInfo *parent_info,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileInfo *info;
|
2008-03-12 19:33:59 +01:00
|
|
|
GLocalFileStat statbuf;
|
|
|
|
#ifdef S_ISLNK
|
2007-11-26 17:13:05 +01:00
|
|
|
struct stat statbuf2;
|
2008-03-12 19:33:59 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
int res;
|
2010-07-08 20:19:08 +02:00
|
|
|
gboolean stat_ok;
|
2007-11-26 17:13:05 +01:00
|
|
|
gboolean is_symlink, symlink_broken;
|
2008-03-12 19:33:59 +01:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
DWORD dos_attributes;
|
|
|
|
#endif
|
2009-06-18 09:05:27 +02:00
|
|
|
char *symlink_target;
|
|
|
|
GVfs *vfs;
|
|
|
|
GVfsClass *class;
|
2009-11-26 16:05:07 +01:00
|
|
|
guint64 device;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
info = g_file_info_new ();
|
|
|
|
|
|
|
|
/* Make sure we don't set any unwanted attributes */
|
|
|
|
g_file_info_set_attribute_mask (info, attribute_matcher);
|
|
|
|
|
2011-11-01 23:37:35 +01:00
|
|
|
_g_local_file_info_get_nostat (info, basename, path, attribute_matcher);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (attribute_matcher == NULL)
|
2011-10-16 21:58:29 +02:00
|
|
|
{
|
|
|
|
g_file_info_unset_attribute_mask (info);
|
|
|
|
return info;
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2008-03-12 19:33:59 +01:00
|
|
|
#ifndef G_OS_WIN32
|
2007-11-26 17:13:05 +01:00
|
|
|
res = g_lstat (path, &statbuf);
|
2008-03-12 19:33:59 +01:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
wchar_t *wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, error);
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (wpath == NULL)
|
|
|
|
{
|
|
|
|
g_object_unref (info);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = wcslen (wpath);
|
|
|
|
while (len > 0 && G_IS_DIR_SEPARATOR (wpath[len-1]))
|
|
|
|
len--;
|
|
|
|
if (len > 0 &&
|
|
|
|
(!g_path_is_absolute (path) || len > g_path_skip_root (path) - path))
|
|
|
|
wpath[len] = '\0';
|
|
|
|
|
|
|
|
res = _wstati64 (wpath, &statbuf);
|
|
|
|
dos_attributes = GetFileAttributesW (wpath);
|
|
|
|
|
|
|
|
g_free (wpath);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
if (res == -1)
|
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
2010-07-08 20:19:08 +02:00
|
|
|
|
|
|
|
/* Don't bail out if we get Permission denied (SELinux?) */
|
|
|
|
if (errsv != EACCES)
|
|
|
|
{
|
|
|
|
char *display_name = g_filename_display_name (path);
|
|
|
|
g_object_unref (info);
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
g_io_error_from_errno (errsv),
|
2011-09-08 16:11:56 +02:00
|
|
|
_("Error when getting information for file '%s': %s"),
|
2010-07-08 20:19:08 +02:00
|
|
|
display_name, g_strerror (errsv));
|
|
|
|
g_free (display_name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
2009-11-26 16:05:07 +01:00
|
|
|
|
2010-07-08 20:19:08 +02:00
|
|
|
/* Even if stat() fails, try to get as much as other attributes possible */
|
|
|
|
stat_ok = res != -1;
|
|
|
|
|
|
|
|
if (stat_ok)
|
|
|
|
device = statbuf.st_dev;
|
|
|
|
else
|
|
|
|
device = 0;
|
2009-11-26 16:05:07 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
#ifdef S_ISLNK
|
2010-07-08 20:19:08 +02:00
|
|
|
is_symlink = stat_ok && S_ISLNK (statbuf.st_mode);
|
2007-11-26 17:13:05 +01:00
|
|
|
#else
|
|
|
|
is_symlink = FALSE;
|
|
|
|
#endif
|
|
|
|
symlink_broken = FALSE;
|
2008-03-12 19:33:59 +01:00
|
|
|
#ifdef S_ISLNK
|
2007-11-26 17:13:05 +01:00
|
|
|
if (is_symlink)
|
|
|
|
{
|
|
|
|
g_file_info_set_is_symlink (info, TRUE);
|
|
|
|
|
|
|
|
/* Unless NOFOLLOW was set we default to following symlinks */
|
|
|
|
if (!(flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS))
|
|
|
|
{
|
|
|
|
res = stat (path, &statbuf2);
|
|
|
|
|
2010-07-08 20:19:08 +02:00
|
|
|
/* Report broken links as symlinks */
|
2007-11-26 17:13:05 +01:00
|
|
|
if (res != -1)
|
2010-07-08 20:19:08 +02:00
|
|
|
{
|
|
|
|
statbuf = statbuf2;
|
|
|
|
stat_ok = TRUE;
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
else
|
|
|
|
symlink_broken = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-03-12 19:33:59 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2010-07-08 20:19:08 +02:00
|
|
|
if (stat_ok)
|
|
|
|
set_info_from_stat (info, &statbuf, attribute_matcher);
|
|
|
|
|
2008-03-12 19:33:59 +01:00
|
|
|
#ifndef G_OS_WIN32
|
2007-11-26 17:13:05 +01:00
|
|
|
if (basename != NULL && basename[0] == '.')
|
|
|
|
g_file_info_set_is_hidden (info, TRUE);
|
|
|
|
|
2009-04-08 09:12:02 +02:00
|
|
|
if (basename != NULL && basename[strlen (basename) -1] == '~' &&
|
2010-07-08 20:19:08 +02:00
|
|
|
(stat_ok && S_ISREG (statbuf.st_mode)))
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_IS_BACKUP, TRUE);
|
2008-03-12 19:33:59 +01:00
|
|
|
#else
|
|
|
|
if (dos_attributes & FILE_ATTRIBUTE_HIDDEN)
|
|
|
|
g_file_info_set_is_hidden (info, TRUE);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2008-03-12 19:33:59 +01:00
|
|
|
if (dos_attributes & FILE_ATTRIBUTE_ARCHIVE)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_DOS_IS_ARCHIVE, TRUE);
|
2008-03-12 19:33:59 +01:00
|
|
|
|
|
|
|
if (dos_attributes & FILE_ATTRIBUTE_SYSTEM)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_DOS_IS_SYSTEM, TRUE);
|
2008-03-12 19:33:59 +01:00
|
|
|
#endif
|
|
|
|
|
2009-06-18 09:05:27 +02:00
|
|
|
symlink_target = NULL;
|
2009-07-07 13:37:45 +02:00
|
|
|
#ifdef S_ISLNK
|
2009-06-18 09:05:27 +02:00
|
|
|
if (is_symlink)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2009-06-18 09:05:27 +02:00
|
|
|
symlink_target = read_link (path);
|
|
|
|
if (symlink_target &&
|
2009-06-29 14:13:14 +02:00
|
|
|
_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_STANDARD_SYMLINK_TARGET))
|
2009-06-18 09:05:27 +02:00
|
|
|
g_file_info_set_symlink_target (info, symlink_target);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
2009-07-07 13:37:45 +02:00
|
|
|
#endif
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE) ||
|
|
|
|
_g_file_attribute_matcher_matches_id (attribute_matcher,
|
2012-08-29 00:56:53 +02:00
|
|
|
G_FILE_ATTRIBUTE_ID_STANDARD_ICON) ||
|
|
|
|
_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_STANDARD_SYMBOLIC_ICON))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2010-07-08 20:19:08 +02:00
|
|
|
char *content_type = get_content_type (basename, path, stat_ok ? &statbuf : NULL, is_symlink, symlink_broken, flags, FALSE);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (content_type)
|
|
|
|
{
|
|
|
|
g_file_info_set_content_type (info, content_type);
|
|
|
|
|
2012-08-29 01:22:01 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_STANDARD_ICON)
|
|
|
|
|| _g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_STANDARD_SYMBOLIC_ICON))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GIcon *icon;
|
|
|
|
|
2012-08-29 01:22:01 +02:00
|
|
|
/* non symbolic icon */
|
|
|
|
icon = get_icon (path, content_type, S_ISDIR (statbuf.st_mode), FALSE);
|
|
|
|
if (icon != NULL)
|
Implement this function by moving bits from glocalfileinfo.c
2008-02-21 David Zeuthen <davidz@redhat.com>
* glocalfileinfo.c: (_g_local_file_info_get):
* gcontenttype.c:
(g_content_type_get_icon): Implement this function by
moving bits from glocalfileinfo.c
(g_content_type_get_description): Unalias before getting
description (#517687)
* gfile.c: (g_file_class_init),
(g_file_query_filesystem_info_async),
(g_file_query_filesystem_info_finish),
(query_filesystem_info_data_free),
(query_filesystem_info_async_thread),
(g_file_real_query_filesystem_info_async),
(g_file_real_query_filesystem_info_finish):
* gfile.h: Implement async version of
g_file_query_filesystem_info()
* gfileinfo.h: Add new attributes for filesystem::use-preview
* gio.symbols: Update
* gthemedicon.c: (g_themed_icon_append_name):
* gthemedicon.h: Add new new convenience function.
* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
(get_mounts), (get_volumes), (get_connected_drives),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_init), (populate_union_monitor),
(g_volume_monitor_get), (_g_mount_get_for_mount_path),
(g_volume_monitor_adopt_orphan_mount):
* gvolumemonitor.c:
* gvolumemonitor.h: Use recursive locks so it's safe for volume
monitor implementations to call into the main volume monitor. Also
separate object initialization and volume monitor initialization
such that non-native volume monitors can properly adopt their
mounts away.
svn path=/trunk/; revision=6550
2008-02-21 13:35:05 +01:00
|
|
|
{
|
2012-08-29 01:22:01 +02:00
|
|
|
g_file_info_set_icon (info, icon);
|
|
|
|
g_object_unref (icon);
|
2008-06-19 05:30:17 +02:00
|
|
|
}
|
Implement this function by moving bits from glocalfileinfo.c
2008-02-21 David Zeuthen <davidz@redhat.com>
* glocalfileinfo.c: (_g_local_file_info_get):
* gcontenttype.c:
(g_content_type_get_icon): Implement this function by
moving bits from glocalfileinfo.c
(g_content_type_get_description): Unalias before getting
description (#517687)
* gfile.c: (g_file_class_init),
(g_file_query_filesystem_info_async),
(g_file_query_filesystem_info_finish),
(query_filesystem_info_data_free),
(query_filesystem_info_async_thread),
(g_file_real_query_filesystem_info_async),
(g_file_real_query_filesystem_info_finish):
* gfile.h: Implement async version of
g_file_query_filesystem_info()
* gfileinfo.h: Add new attributes for filesystem::use-preview
* gio.symbols: Update
* gthemedicon.c: (g_themed_icon_append_name):
* gthemedicon.h: Add new new convenience function.
* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
(get_mounts), (get_volumes), (get_connected_drives),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_init), (populate_union_monitor),
(g_volume_monitor_get), (_g_mount_get_for_mount_path),
(g_volume_monitor_adopt_orphan_mount):
* gvolumemonitor.c:
* gvolumemonitor.h: Use recursive locks so it's safe for volume
monitor implementations to call into the main volume monitor. Also
separate object initialization and volume monitor initialization
such that non-native volume monitors can properly adopt their
mounts away.
svn path=/trunk/; revision=6550
2008-02-21 13:35:05 +01:00
|
|
|
|
2012-08-29 01:22:01 +02:00
|
|
|
/* symbolic icon */
|
|
|
|
icon = get_icon (path, content_type, S_ISDIR (statbuf.st_mode), TRUE);
|
2008-06-19 05:30:17 +02:00
|
|
|
if (icon != NULL)
|
|
|
|
{
|
2012-08-29 01:22:01 +02:00
|
|
|
g_file_info_set_symbolic_icon (info, icon);
|
Implement this function by moving bits from glocalfileinfo.c
2008-02-21 David Zeuthen <davidz@redhat.com>
* glocalfileinfo.c: (_g_local_file_info_get):
* gcontenttype.c:
(g_content_type_get_icon): Implement this function by
moving bits from glocalfileinfo.c
(g_content_type_get_description): Unalias before getting
description (#517687)
* gfile.c: (g_file_class_init),
(g_file_query_filesystem_info_async),
(g_file_query_filesystem_info_finish),
(query_filesystem_info_data_free),
(query_filesystem_info_async_thread),
(g_file_real_query_filesystem_info_async),
(g_file_real_query_filesystem_info_finish):
* gfile.h: Implement async version of
g_file_query_filesystem_info()
* gfileinfo.h: Add new attributes for filesystem::use-preview
* gio.symbols: Update
* gthemedicon.c: (g_themed_icon_append_name):
* gthemedicon.h: Add new new convenience function.
* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
(get_mounts), (get_volumes), (get_connected_drives),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_init), (populate_union_monitor),
(g_volume_monitor_get), (_g_mount_get_for_mount_path),
(g_volume_monitor_adopt_orphan_mount):
* gvolumemonitor.c:
* gvolumemonitor.h: Use recursive locks so it's safe for volume
monitor implementations to call into the main volume monitor. Also
separate object initialization and volume monitor initialization
such that non-native volume monitors can properly adopt their
mounts away.
svn path=/trunk/; revision=6550
2008-02-21 13:35:05 +01:00
|
|
|
g_object_unref (icon);
|
|
|
|
}
|
2012-08-29 01:22:01 +02:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (content_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2010-07-08 20:19:08 +02:00
|
|
|
char *content_type = get_content_type (basename, path, stat_ok ? &statbuf : NULL, is_symlink, symlink_broken, flags, TRUE);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (content_type)
|
|
|
|
{
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE, content_type);
|
2007-11-26 17:13:05 +01:00
|
|
|
g_free (content_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_OWNER_USER))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-08 13:01:06 +01:00
|
|
|
char *name = NULL;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2007-12-08 13:01:06 +01:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
win32_get_file_user_info (path, NULL, &name, NULL);
|
|
|
|
#else
|
2010-07-08 20:19:08 +02:00
|
|
|
if (stat_ok)
|
|
|
|
name = get_username_from_uid (statbuf.st_uid);
|
2007-12-08 13:01:06 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
if (name)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_OWNER_USER, name);
|
2007-11-26 17:13:05 +01:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_OWNER_USER_REAL))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-08 13:01:06 +01:00
|
|
|
char *name = NULL;
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
win32_get_file_user_info (path, NULL, NULL, &name);
|
|
|
|
#else
|
2010-07-08 20:19:08 +02:00
|
|
|
if (stat_ok)
|
|
|
|
name = get_realname_from_uid (statbuf.st_uid);
|
2007-12-08 13:01:06 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
if (name)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_OWNER_USER_REAL, name);
|
2007-11-26 17:13:05 +01:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_OWNER_GROUP))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-08 13:01:06 +01:00
|
|
|
char *name = NULL;
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
win32_get_file_user_info (path, &name, NULL, NULL);
|
|
|
|
#else
|
2010-07-08 20:19:08 +02:00
|
|
|
if (stat_ok)
|
|
|
|
name = get_groupname_from_gid (statbuf.st_gid);
|
2007-12-08 13:01:06 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
if (name)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_OWNER_GROUP, name);
|
2007-11-26 17:13:05 +01:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
2010-07-08 20:19:08 +02:00
|
|
|
if (stat_ok && parent_info && parent_info->device != 0 &&
|
2009-06-29 14:13:14 +02:00
|
|
|
_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT) &&
|
2007-11-26 17:13:05 +01:00
|
|
|
statbuf.st_dev != parent_info->device)
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT, TRUE);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2010-07-08 20:19:08 +02:00
|
|
|
if (stat_ok)
|
|
|
|
get_access_rights (attribute_matcher, info, path, &statbuf, parent_info);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2008-10-15 05:37:56 +02:00
|
|
|
#ifdef HAVE_SELINUX
|
2007-11-26 17:13:05 +01:00
|
|
|
get_selinux_context (path, info, attribute_matcher, (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS) == 0);
|
2008-10-15 05:37:56 +02:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
get_xattrs (path, TRUE, info, attribute_matcher, (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS) == 0);
|
|
|
|
get_xattrs (path, FALSE, info, attribute_matcher, (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS) == 0);
|
|
|
|
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (attribute_matcher,
|
|
|
|
G_FILE_ATTRIBUTE_ID_THUMBNAIL_PATH))
|
2007-11-26 17:13:05 +01:00
|
|
|
get_thumbnail_attributes (path, info);
|
2009-06-18 09:05:27 +02:00
|
|
|
|
|
|
|
vfs = g_vfs_get_default ();
|
|
|
|
class = G_VFS_GET_CLASS (vfs);
|
|
|
|
if (class->local_file_add_info)
|
|
|
|
{
|
|
|
|
class->local_file_add_info (vfs,
|
2009-09-28 15:55:44 +02:00
|
|
|
path,
|
2009-11-26 16:05:07 +01:00
|
|
|
device,
|
2009-06-18 09:05:27 +02:00
|
|
|
attribute_matcher,
|
|
|
|
info,
|
|
|
|
NULL,
|
|
|
|
&parent_info->extra_data,
|
|
|
|
&parent_info->free_extra_data);
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_file_info_unset_attribute_mask (info);
|
|
|
|
|
2009-06-18 09:05:27 +02:00
|
|
|
g_free (symlink_target);
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
GFileInfo *
|
2009-03-03 16:50:13 +01:00
|
|
|
_g_local_file_info_get_from_fd (int fd,
|
|
|
|
const char *attributes,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2008-03-12 19:33:59 +01:00
|
|
|
GLocalFileStat stat_buf;
|
2007-11-26 17:13:05 +01:00
|
|
|
GFileAttributeMatcher *matcher;
|
|
|
|
GFileInfo *info;
|
|
|
|
|
2008-03-12 19:33:59 +01:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#define FSTAT _fstati64
|
|
|
|
#else
|
|
|
|
#define FSTAT fstat
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (FSTAT (fd, &stat_buf) == -1)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2011-09-08 16:11:56 +02:00
|
|
|
_("Error when getting information for file descriptor: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
info = g_file_info_new ();
|
|
|
|
|
|
|
|
matcher = g_file_attribute_matcher_new (attributes);
|
|
|
|
|
|
|
|
/* Make sure we don't set any unwanted attributes */
|
|
|
|
g_file_info_set_attribute_mask (info, matcher);
|
|
|
|
|
|
|
|
set_info_from_stat (info, &stat_buf, matcher);
|
|
|
|
|
|
|
|
#ifdef HAVE_SELINUX
|
2009-06-29 14:13:14 +02:00
|
|
|
if (_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT) &&
|
2007-11-26 17:13:05 +01:00
|
|
|
is_selinux_enabled ())
|
|
|
|
{
|
|
|
|
char *context;
|
|
|
|
if (fgetfilecon_raw (fd, &context) >= 0)
|
|
|
|
{
|
2009-06-29 15:28:08 +02:00
|
|
|
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_SELINUX_CONTEXT, context);
|
2008-01-03 10:01:00 +01:00
|
|
|
freecon (context);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
get_xattrs_from_fd (fd, TRUE, info, matcher);
|
|
|
|
get_xattrs_from_fd (fd, FALSE, info, matcher);
|
|
|
|
|
|
|
|
g_file_attribute_matcher_unref (matcher);
|
|
|
|
|
|
|
|
g_file_info_unset_attribute_mask (info);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
get_uint32 (const GFileAttributeValue *value,
|
|
|
|
guint32 *val_out,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
if (value->type != G_FILE_ATTRIBUTE_TYPE_UINT32)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Invalid attribute type (uint32 expected)"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*val_out = value->u.uint32;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-03-12 19:33:59 +01:00
|
|
|
#ifdef HAVE_UTIMES
|
2007-11-26 17:13:05 +01:00
|
|
|
static gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
get_uint64 (const GFileAttributeValue *value,
|
|
|
|
guint64 *val_out,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
if (value->type != G_FILE_ATTRIBUTE_TYPE_UINT64)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Invalid attribute type (uint64 expected)"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*val_out = value->u.uint64;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-03-12 19:33:59 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
#if defined(HAVE_SYMLINK)
|
|
|
|
static gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
get_byte_string (const GFileAttributeValue *value,
|
|
|
|
const char **val_out,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
if (value->type != G_FILE_ATTRIBUTE_TYPE_BYTE_STRING)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Invalid attribute type (byte string expected)"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*val_out = value->u.string;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-15 05:37:56 +02:00
|
|
|
#ifdef HAVE_SELINUX
|
2008-07-23 06:11:02 +02:00
|
|
|
static gboolean
|
|
|
|
get_string (const GFileAttributeValue *value,
|
|
|
|
const char **val_out,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
if (value->type != G_FILE_ATTRIBUTE_TYPE_STRING)
|
|
|
|
{
|
2008-10-10 06:54:51 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Invalid attribute type (byte string expected)"));
|
2008-07-23 06:11:02 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*val_out = value->u.string;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-10-15 05:37:56 +02:00
|
|
|
#endif
|
2008-07-23 06:11:02 +02:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
static gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
set_unix_mode (char *filename,
|
2009-09-01 11:54:48 +02:00
|
|
|
GFileQueryInfoFlags flags,
|
2007-11-30 06:11:25 +01:00
|
|
|
const GFileAttributeValue *value,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2011-04-26 19:28:17 +02:00
|
|
|
guint32 val = 0;
|
2009-09-01 21:26:08 +02:00
|
|
|
int res = 0;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (!get_uint32 (value, &val, error))
|
|
|
|
return FALSE;
|
2009-09-01 20:36:31 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_SYMLINK
|
2009-09-01 11:54:48 +02:00
|
|
|
if (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS) {
|
2009-09-01 21:53:35 +02:00
|
|
|
#ifdef HAVE_LCHMOD
|
|
|
|
res = lchmod (filename, val);
|
|
|
|
#else
|
2009-09-01 21:26:08 +02:00
|
|
|
struct stat statbuf;
|
|
|
|
/* Calling chmod on a symlink changes permissions on the symlink.
|
|
|
|
* We don't want to do this, so we need to check for a symlink */
|
|
|
|
res = g_lstat (filename, &statbuf);
|
|
|
|
if (res == 0 && S_ISLNK (statbuf.st_mode))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Cannot set permissions on symlinks"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-09-01 21:53:35 +02:00
|
|
|
else if (res == 0)
|
|
|
|
res = g_chmod (filename, val);
|
|
|
|
#endif
|
|
|
|
} else
|
2009-09-01 20:36:31 +02:00
|
|
|
#endif
|
2009-09-01 21:26:08 +02:00
|
|
|
res = g_chmod (filename, val);
|
|
|
|
|
|
|
|
if (res == -1)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2007-11-26 17:13:05 +01:00
|
|
|
_("Error setting permissions: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_CHOWN
|
|
|
|
static gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
set_unix_uid_gid (char *filename,
|
|
|
|
const GFileAttributeValue *uid_value,
|
|
|
|
const GFileAttributeValue *gid_value,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
int res;
|
2011-04-26 19:28:17 +02:00
|
|
|
guint32 val = 0;
|
2007-11-26 17:13:05 +01:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
|
|
|
|
if (uid_value)
|
|
|
|
{
|
|
|
|
if (!get_uint32 (uid_value, &val, error))
|
|
|
|
return FALSE;
|
|
|
|
uid = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
uid = -1;
|
|
|
|
|
|
|
|
if (gid_value)
|
|
|
|
{
|
|
|
|
if (!get_uint32 (gid_value, &val, error))
|
|
|
|
return FALSE;
|
|
|
|
gid = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gid = -1;
|
|
|
|
|
2008-01-03 10:13:39 +01:00
|
|
|
#ifdef HAVE_LCHOWN
|
2007-11-26 17:13:05 +01:00
|
|
|
if (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)
|
|
|
|
res = lchown (filename, uid, gid);
|
|
|
|
else
|
2008-01-03 10:13:39 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
res = chown (filename, uid, gid);
|
|
|
|
|
|
|
|
if (res == -1)
|
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2007-11-26 17:13:05 +01:00
|
|
|
_("Error setting owner: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYMLINK
|
|
|
|
static gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
set_symlink (char *filename,
|
|
|
|
const GFileAttributeValue *value,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
const char *val;
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
if (!get_byte_string (value, &val, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (val == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("symlink must be non-NULL"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_lstat (filename, &statbuf))
|
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2007-11-26 17:13:05 +01:00
|
|
|
_("Error setting symlink: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISLNK (statbuf.st_mode))
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SYMBOLIC_LINK,
|
|
|
|
_("Error setting symlink: file is not a symlink"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_unlink (filename))
|
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2007-11-26 17:13:05 +01:00
|
|
|
_("Error setting symlink: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (symlink (filename, val) != 0)
|
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2007-11-26 17:13:05 +01:00
|
|
|
_("Error setting symlink: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-03-12 19:33:59 +01:00
|
|
|
#ifdef HAVE_UTIMES
|
2007-11-26 17:13:05 +01:00
|
|
|
static int
|
2007-11-30 06:11:25 +01:00
|
|
|
lazy_stat (char *filename,
|
|
|
|
struct stat *statbuf,
|
|
|
|
gboolean *called_stat)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (*called_stat)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
res = g_stat (filename, statbuf);
|
|
|
|
|
|
|
|
if (res == 0)
|
|
|
|
*called_stat = TRUE;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
set_mtime_atime (char *filename,
|
|
|
|
const GFileAttributeValue *mtime_value,
|
|
|
|
const GFileAttributeValue *mtime_usec_value,
|
|
|
|
const GFileAttributeValue *atime_value,
|
|
|
|
const GFileAttributeValue *atime_usec_value,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
int res;
|
2011-04-26 19:28:17 +02:00
|
|
|
guint64 val = 0;
|
|
|
|
guint32 val_usec = 0;
|
2007-11-26 17:13:05 +01:00
|
|
|
struct stat statbuf;
|
|
|
|
gboolean got_stat = FALSE;
|
|
|
|
struct timeval times[2] = { {0, 0}, {0, 0} };
|
|
|
|
|
|
|
|
/* ATIME */
|
|
|
|
if (atime_value)
|
|
|
|
{
|
|
|
|
if (!get_uint64 (atime_value, &val, error))
|
|
|
|
return FALSE;
|
|
|
|
times[0].tv_sec = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (lazy_stat (filename, &statbuf, &got_stat) == 0)
|
|
|
|
{
|
|
|
|
times[0].tv_sec = statbuf.st_mtime;
|
|
|
|
#if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
|
|
|
|
times[0].tv_usec = statbuf.st_atimensec / 1000;
|
|
|
|
#elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
|
|
|
|
times[0].tv_usec = statbuf.st_atim.tv_nsec / 1000;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atime_usec_value)
|
|
|
|
{
|
|
|
|
if (!get_uint32 (atime_usec_value, &val_usec, error))
|
|
|
|
return FALSE;
|
|
|
|
times[0].tv_usec = val_usec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MTIME */
|
|
|
|
if (mtime_value)
|
|
|
|
{
|
|
|
|
if (!get_uint64 (mtime_value, &val, error))
|
|
|
|
return FALSE;
|
|
|
|
times[1].tv_sec = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (lazy_stat (filename, &statbuf, &got_stat) == 0)
|
|
|
|
{
|
|
|
|
times[1].tv_sec = statbuf.st_mtime;
|
|
|
|
#if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
|
|
|
|
times[1].tv_usec = statbuf.st_mtimensec / 1000;
|
|
|
|
#elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
|
|
|
|
times[1].tv_usec = statbuf.st_mtim.tv_nsec / 1000;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mtime_usec_value)
|
|
|
|
{
|
|
|
|
if (!get_uint32 (mtime_usec_value, &val_usec, error))
|
|
|
|
return FALSE;
|
|
|
|
times[1].tv_usec = val_usec;
|
|
|
|
}
|
|
|
|
|
2008-01-21 15:02:19 +01:00
|
|
|
res = utimes (filename, times);
|
2007-11-26 17:13:05 +01:00
|
|
|
if (res == -1)
|
|
|
|
{
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
int errsv = errno;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR,
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_io_error_from_errno (errsv),
|
2009-05-17 14:17:57 +02:00
|
|
|
_("Error setting modification or access time: %s"),
|
Save errno before calling other funcs that potentially alter it. Bug
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c:
(g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
Save
errno before calling other funcs that potentially alter it. Bug
#514766.
svn path=/trunk/; revision=6466
2008-02-06 16:10:08 +01:00
|
|
|
g_strerror (errsv));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-07-23 06:11:02 +02:00
|
|
|
|
2008-10-15 05:37:56 +02:00
|
|
|
#ifdef HAVE_SELINUX
|
2008-07-23 06:11:02 +02:00
|
|
|
static gboolean
|
|
|
|
set_selinux_context (char *filename,
|
|
|
|
const GFileAttributeValue *value,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
const char *val;
|
|
|
|
|
|
|
|
if (!get_string (value, &val, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (val == NULL)
|
|
|
|
{
|
2008-10-10 06:54:51 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("SELinux context must be non-NULL"));
|
2008-07-23 06:11:02 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_selinux_enabled ()) {
|
|
|
|
security_context_t val_s;
|
|
|
|
|
|
|
|
val_s = g_strdup (val);
|
|
|
|
|
|
|
|
if (setfilecon_raw (filename, val_s) < 0)
|
|
|
|
{
|
|
|
|
int errsv = errno;
|
|
|
|
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
g_io_error_from_errno (errsv),
|
|
|
|
_("Error setting SELinux context: %s"),
|
|
|
|
g_strerror (errsv));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
g_free (val_s);
|
|
|
|
} else {
|
2008-10-10 06:54:51 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("SELinux is not enabled on this system"));
|
2008-07-23 06:11:02 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-10-15 05:37:56 +02:00
|
|
|
#endif
|
2008-07-23 06:11:02 +02:00
|
|
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
gboolean
|
2008-01-21 15:02:19 +01:00
|
|
|
_g_local_file_info_set_attribute (char *filename,
|
|
|
|
const char *attribute,
|
|
|
|
GFileAttributeType type,
|
|
|
|
gpointer value_p,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-14 16:56:56 +01:00
|
|
|
GFileAttributeValue value = { 0 };
|
2009-06-18 09:05:27 +02:00
|
|
|
GVfsClass *class;
|
|
|
|
GVfs *vfs;
|
2007-12-14 16:56:56 +01:00
|
|
|
|
|
|
|
_g_file_attribute_value_set_from_pointer (&value, type, value_p, FALSE);
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
if (strcmp (attribute, G_FILE_ATTRIBUTE_UNIX_MODE) == 0)
|
2009-09-01 11:54:48 +02:00
|
|
|
return set_unix_mode (filename, flags, &value, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_CHOWN
|
|
|
|
else if (strcmp (attribute, G_FILE_ATTRIBUTE_UNIX_UID) == 0)
|
2007-12-14 16:56:56 +01:00
|
|
|
return set_unix_uid_gid (filename, &value, NULL, flags, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
else if (strcmp (attribute, G_FILE_ATTRIBUTE_UNIX_GID) == 0)
|
2007-12-14 16:56:56 +01:00
|
|
|
return set_unix_uid_gid (filename, NULL, &value, flags, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYMLINK
|
2007-12-20 14:30:47 +01:00
|
|
|
else if (strcmp (attribute, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET) == 0)
|
2007-12-14 16:56:56 +01:00
|
|
|
return set_symlink (filename, &value, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_UTIMES
|
|
|
|
else if (strcmp (attribute, G_FILE_ATTRIBUTE_TIME_MODIFIED) == 0)
|
2007-12-14 16:56:56 +01:00
|
|
|
return set_mtime_atime (filename, &value, NULL, NULL, NULL, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
else if (strcmp (attribute, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC) == 0)
|
2007-12-14 16:56:56 +01:00
|
|
|
return set_mtime_atime (filename, NULL, &value, NULL, NULL, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
else if (strcmp (attribute, G_FILE_ATTRIBUTE_TIME_ACCESS) == 0)
|
2007-12-14 16:56:56 +01:00
|
|
|
return set_mtime_atime (filename, NULL, NULL, &value, NULL, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
else if (strcmp (attribute, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC) == 0)
|
2007-12-14 16:56:56 +01:00
|
|
|
return set_mtime_atime (filename, NULL, NULL, NULL, &value, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XATTR
|
2007-12-12 16:50:45 +01:00
|
|
|
else if (g_str_has_prefix (attribute, "xattr::"))
|
2007-12-14 16:56:56 +01:00
|
|
|
return set_xattr (filename, attribute, &value, error);
|
2007-12-12 16:50:45 +01:00
|
|
|
else if (g_str_has_prefix (attribute, "xattr-sys::"))
|
2007-12-14 16:56:56 +01:00
|
|
|
return set_xattr (filename, attribute, &value, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
2008-07-23 06:11:02 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_SELINUX
|
|
|
|
else if (strcmp (attribute, G_FILE_ATTRIBUTE_SELINUX_CONTEXT) == 0)
|
|
|
|
return set_selinux_context (filename, &value, error);
|
|
|
|
#endif
|
2009-06-18 09:05:27 +02:00
|
|
|
|
|
|
|
vfs = g_vfs_get_default ();
|
|
|
|
class = G_VFS_GET_CLASS (vfs);
|
|
|
|
if (class->local_file_set_attributes)
|
|
|
|
{
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
info = g_file_info_new ();
|
|
|
|
g_file_info_set_attribute (info,
|
|
|
|
attribute,
|
|
|
|
type,
|
|
|
|
value_p);
|
|
|
|
if (!class->local_file_set_attributes (vfs, filename,
|
|
|
|
info,
|
|
|
|
flags, cancellable,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
g_object_unref (info);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_file_info_get_attribute_status (info, attribute) == G_FILE_ATTRIBUTE_STATUS_SET)
|
|
|
|
{
|
|
|
|
g_object_unref (info);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Setting attribute %s not supported"), attribute);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2007-11-30 06:11:25 +01:00
|
|
|
_g_local_file_info_set_attributes (char *filename,
|
|
|
|
GFileInfo *info,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2008-03-12 19:33:59 +01:00
|
|
|
GFileAttributeValue *value;
|
|
|
|
#ifdef HAVE_CHOWN
|
|
|
|
GFileAttributeValue *uid, *gid;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UTIMES
|
2007-11-26 17:13:05 +01:00
|
|
|
GFileAttributeValue *mtime, *mtime_usec, *atime, *atime_usec;
|
2008-03-12 19:33:59 +01:00
|
|
|
#endif
|
2009-02-25 14:30:49 +01:00
|
|
|
#if defined (HAVE_CHOWN) || defined (HAVE_UTIMES)
|
2007-11-26 17:13:05 +01:00
|
|
|
GFileAttributeStatus status;
|
2008-03-12 19:33:59 +01:00
|
|
|
#endif
|
2007-11-26 17:13:05 +01:00
|
|
|
gboolean res;
|
2009-06-18 09:05:27 +02:00
|
|
|
GVfsClass *class;
|
|
|
|
GVfs *vfs;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
/* Handles setting multiple specified data in a single set, and takes care
|
|
|
|
of ordering restrictions when setting attributes */
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
|
|
|
|
/* Set symlink first, since this recreates the file */
|
|
|
|
#ifdef HAVE_SYMLINK
|
2007-12-20 14:30:47 +01:00
|
|
|
value = _g_file_info_get_attribute_value (info, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
|
2007-11-26 17:13:05 +01:00
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
if (!set_symlink (filename, value, error))
|
|
|
|
{
|
|
|
|
value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
|
|
|
|
res = FALSE;
|
|
|
|
/* Don't set error multiple times */
|
|
|
|
error = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value->status = G_FILE_ATTRIBUTE_STATUS_SET;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CHOWN
|
|
|
|
/* Group uid and gid setting into one call
|
|
|
|
* Change ownership before permissions, since ownership changes can
|
|
|
|
change permissions (e.g. setuid)
|
|
|
|
*/
|
2007-12-14 16:56:56 +01:00
|
|
|
uid = _g_file_info_get_attribute_value (info, G_FILE_ATTRIBUTE_UNIX_UID);
|
|
|
|
gid = _g_file_info_get_attribute_value (info, G_FILE_ATTRIBUTE_UNIX_GID);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (uid || gid)
|
|
|
|
{
|
|
|
|
if (!set_unix_uid_gid (filename, uid, gid, flags, error))
|
|
|
|
{
|
|
|
|
status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
|
|
|
|
res = FALSE;
|
|
|
|
/* Don't set error multiple times */
|
|
|
|
error = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = G_FILE_ATTRIBUTE_STATUS_SET;
|
|
|
|
if (uid)
|
|
|
|
uid->status = status;
|
|
|
|
if (gid)
|
|
|
|
gid->status = status;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-12-14 16:56:56 +01:00
|
|
|
value = _g_file_info_get_attribute_value (info, G_FILE_ATTRIBUTE_UNIX_MODE);
|
2007-11-26 17:13:05 +01:00
|
|
|
if (value)
|
|
|
|
{
|
2009-09-01 11:54:48 +02:00
|
|
|
if (!set_unix_mode (filename, flags, value, error))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
|
|
|
|
res = FALSE;
|
|
|
|
/* Don't set error multiple times */
|
|
|
|
error = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value->status = G_FILE_ATTRIBUTE_STATUS_SET;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_UTIMES
|
|
|
|
/* Group all time settings into one call
|
|
|
|
* Change times as the last thing to avoid it changing due to metadata changes
|
|
|
|
*/
|
|
|
|
|
2007-12-14 16:56:56 +01:00
|
|
|
mtime = _g_file_info_get_attribute_value (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
|
|
|
mtime_usec = _g_file_info_get_attribute_value (info, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
|
|
|
|
atime = _g_file_info_get_attribute_value (info, G_FILE_ATTRIBUTE_TIME_ACCESS);
|
|
|
|
atime_usec = _g_file_info_get_attribute_value (info, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (mtime || mtime_usec || atime || atime_usec)
|
|
|
|
{
|
|
|
|
if (!set_mtime_atime (filename, mtime, mtime_usec, atime, atime_usec, error))
|
|
|
|
{
|
|
|
|
status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
|
|
|
|
res = FALSE;
|
|
|
|
/* Don't set error multiple times */
|
|
|
|
error = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = G_FILE_ATTRIBUTE_STATUS_SET;
|
|
|
|
|
|
|
|
if (mtime)
|
|
|
|
mtime->status = status;
|
|
|
|
if (mtime_usec)
|
|
|
|
mtime_usec->status = status;
|
|
|
|
if (atime)
|
|
|
|
atime->status = status;
|
|
|
|
if (atime_usec)
|
|
|
|
atime_usec->status = status;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* xattrs are handled by default callback */
|
|
|
|
|
2008-07-23 06:11:02 +02:00
|
|
|
|
|
|
|
/* SELinux context */
|
|
|
|
#ifdef HAVE_SELINUX
|
|
|
|
if (is_selinux_enabled ()) {
|
|
|
|
value = _g_file_info_get_attribute_value (info, G_FILE_ATTRIBUTE_SELINUX_CONTEXT);
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
if (!set_selinux_context (filename, value, error))
|
|
|
|
{
|
|
|
|
value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
|
|
|
|
res = FALSE;
|
|
|
|
/* Don't set error multiple times */
|
|
|
|
error = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value->status = G_FILE_ATTRIBUTE_STATUS_SET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-18 09:05:27 +02:00
|
|
|
vfs = g_vfs_get_default ();
|
|
|
|
class = G_VFS_GET_CLASS (vfs);
|
|
|
|
if (class->local_file_set_attributes)
|
|
|
|
{
|
|
|
|
if (!class->local_file_set_attributes (vfs, filename,
|
|
|
|
info,
|
|
|
|
flags, cancellable,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
res = FALSE;
|
|
|
|
/* Don't set error multiple times */
|
|
|
|
error = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
return res;
|
|
|
|
}
|