mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 06:56:14 +01:00
glocalfileinfo: Use accessors to access struct stat members
This will allow the actual struct in use to be changed in future without code changes everywhere. Helps: #1970
This commit is contained in:
parent
83a59e99ff
commit
8edbfe8bb0
@ -1358,7 +1358,7 @@ g_local_file_read (GFile *file,
|
||||
ret = fstat (fd, &buf);
|
||||
#endif
|
||||
|
||||
if (ret == 0 && S_ISDIR (buf.st_mode))
|
||||
if (ret == 0 && S_ISDIR (_g_stat_mode (&buf)))
|
||||
{
|
||||
(void) g_close (fd, NULL);
|
||||
g_set_io_error (error,
|
||||
@ -2730,7 +2730,7 @@ g_local_file_measure_size_of_file (gint parent_fd,
|
||||
/* If not at the toplevel, check for a device boundary. */
|
||||
|
||||
if (state->flags & G_FILE_MEASURE_NO_XDEV)
|
||||
if (state->contained_on != buf.st_dev)
|
||||
if (state->contained_on != _g_stat_dev (&buf))
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
@ -2738,7 +2738,7 @@ g_local_file_measure_size_of_file (gint parent_fd,
|
||||
/* If, however, this is the toplevel, set the device number so
|
||||
* that recursive invocations can compare against it.
|
||||
*/
|
||||
state->contained_on = buf.st_dev;
|
||||
state->contained_on = _g_stat_dev (&buf);
|
||||
}
|
||||
|
||||
#if defined (G_OS_WIN32)
|
||||
@ -2747,12 +2747,12 @@ g_local_file_measure_size_of_file (gint parent_fd,
|
||||
else
|
||||
#elif defined (HAVE_STRUCT_STAT_ST_BLOCKS)
|
||||
if (~state->flags & G_FILE_MEASURE_APPARENT_SIZE)
|
||||
state->disk_usage += buf.st_blocks * G_GUINT64_CONSTANT (512);
|
||||
state->disk_usage += _g_stat_blocks (&buf) * G_GUINT64_CONSTANT (512);
|
||||
else
|
||||
#endif
|
||||
state->disk_usage += buf.st_size;
|
||||
state->disk_usage += _g_stat_size (&buf);
|
||||
|
||||
if (S_ISDIR (buf.st_mode))
|
||||
if (S_ISDIR (_g_stat_mode (&buf)))
|
||||
state->num_dirs++;
|
||||
else
|
||||
state->num_files++;
|
||||
@ -2787,7 +2787,7 @@ g_local_file_measure_size_of_file (gint parent_fd,
|
||||
}
|
||||
}
|
||||
|
||||
if (S_ISDIR (buf.st_mode))
|
||||
if (S_ISDIR (_g_stat_mode (&buf)))
|
||||
{
|
||||
int dir_fd = -1;
|
||||
#ifdef AT_FDCWD
|
||||
|
@ -127,11 +127,11 @@ _g_local_file_info_create_etag (GLocalFileStat *statbuf)
|
||||
sec = statbuf->st_mtim.tv_sec;
|
||||
usec = statbuf->st_mtim.tv_nsec / 1000;
|
||||
#else
|
||||
sec = statbuf->st_mtime;
|
||||
sec = _g_stat_mtime (statbuf);
|
||||
#if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
|
||||
usec = statbuf->st_mtimensec / 1000;
|
||||
#elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
|
||||
usec = statbuf->st_mtim.tv_nsec / 1000;
|
||||
usec = _g_stat_mtim_nsec (statbuf) / 1000;
|
||||
#else
|
||||
usec = 0;
|
||||
#endif
|
||||
@ -147,10 +147,10 @@ _g_local_file_info_create_file_id (GLocalFileStat *statbuf)
|
||||
#ifdef G_OS_WIN32
|
||||
ino = statbuf->file_index;
|
||||
#else
|
||||
ino = statbuf->st_ino;
|
||||
ino = _g_stat_ino (statbuf);
|
||||
#endif
|
||||
return g_strdup_printf ("l%" G_GUINT64_FORMAT ":%" G_GUINT64_FORMAT,
|
||||
(guint64) statbuf->st_dev,
|
||||
(guint64) _g_stat_dev (statbuf),
|
||||
ino);
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ static char *
|
||||
_g_local_file_info_create_fs_id (GLocalFileStat *statbuf)
|
||||
{
|
||||
return g_strdup_printf ("l%" G_GUINT64_FORMAT,
|
||||
(guint64) statbuf->st_dev);
|
||||
(guint64) _g_stat_dev (statbuf));
|
||||
}
|
||||
|
||||
#if defined (S_ISLNK) || defined (G_OS_WIN32)
|
||||
@ -926,7 +926,7 @@ get_access_rights (GFileAttributeMatcher *attribute_matcher,
|
||||
{
|
||||
uid_t uid = geteuid ();
|
||||
|
||||
if (uid == statbuf->st_uid ||
|
||||
if (uid == _g_stat_uid (statbuf) ||
|
||||
uid == parent_info->owner ||
|
||||
uid == 0)
|
||||
writable = TRUE;
|
||||
@ -959,22 +959,22 @@ set_info_from_stat (GFileInfo *info,
|
||||
|
||||
file_type = G_FILE_TYPE_UNKNOWN;
|
||||
|
||||
if (S_ISREG (statbuf->st_mode))
|
||||
if (S_ISREG (_g_stat_mode (statbuf)))
|
||||
file_type = G_FILE_TYPE_REGULAR;
|
||||
else if (S_ISDIR (statbuf->st_mode))
|
||||
else if (S_ISDIR (_g_stat_mode (statbuf)))
|
||||
file_type = G_FILE_TYPE_DIRECTORY;
|
||||
#ifndef G_OS_WIN32
|
||||
else if (S_ISCHR (statbuf->st_mode) ||
|
||||
S_ISBLK (statbuf->st_mode) ||
|
||||
S_ISFIFO (statbuf->st_mode)
|
||||
else if (S_ISCHR (_g_stat_mode (statbuf)) ||
|
||||
S_ISBLK (_g_stat_mode (statbuf)) ||
|
||||
S_ISFIFO (_g_stat_mode (statbuf))
|
||||
#ifdef S_ISSOCK
|
||||
|| S_ISSOCK (statbuf->st_mode)
|
||||
|| S_ISSOCK (_g_stat_mode (statbuf))
|
||||
#endif
|
||||
)
|
||||
file_type = G_FILE_TYPE_SPECIAL;
|
||||
#endif
|
||||
#ifdef S_ISLNK
|
||||
else if (S_ISLNK (statbuf->st_mode))
|
||||
else if (S_ISLNK (_g_stat_mode (statbuf)))
|
||||
file_type = G_FILE_TYPE_SYMBOLIC_LINK;
|
||||
#elif defined (G_OS_WIN32)
|
||||
else if (statbuf->reparse_tag == IO_REPARSE_TAG_SYMLINK ||
|
||||
@ -983,28 +983,28 @@ set_info_from_stat (GFileInfo *info,
|
||||
#endif
|
||||
|
||||
g_file_info_set_file_type (info, file_type);
|
||||
g_file_info_set_size (info, statbuf->st_size);
|
||||
g_file_info_set_size (info, _g_stat_size (statbuf));
|
||||
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_DEVICE, statbuf->st_dev);
|
||||
_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_DEVICE, _g_stat_dev (statbuf));
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_NLINK, _g_stat_nlink (statbuf));
|
||||
#ifndef G_OS_WIN32
|
||||
/* Pointless setting these on Windows even if they exist in the struct */
|
||||
_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_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);
|
||||
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_INODE, _g_stat_ino (statbuf));
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_UID, _g_stat_uid (statbuf));
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_GID, _g_stat_gid (statbuf));
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_RDEV, _g_stat_rdev (statbuf));
|
||||
#endif
|
||||
/* Mostly pointless on Windows.
|
||||
* Still, it allows for S_ISREG/S_ISDIR and IWRITE (read-only) checks.
|
||||
*/
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_MODE, statbuf->st_mode);
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_MODE, _g_stat_mode (statbuf));
|
||||
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_BLOCK_SIZE, statbuf->st_blksize);
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_BLOCK_SIZE, _g_stat_blksize (statbuf));
|
||||
#endif
|
||||
#if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
|
||||
_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_UNIX_BLOCKS, _g_stat_blocks (statbuf));
|
||||
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_ALLOCATED_SIZE,
|
||||
statbuf->st_blocks * G_GUINT64_CONSTANT (512));
|
||||
_g_stat_blocks (statbuf) * G_GUINT64_CONSTANT (512));
|
||||
#elif defined (G_OS_WIN32)
|
||||
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_ALLOCATED_SIZE,
|
||||
statbuf->allocated_size);
|
||||
@ -1017,18 +1017,18 @@ set_info_from_stat (GFileInfo *info,
|
||||
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_ACCESS, statbuf->st_atim.tv_sec);
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC, statbuf->st_atim.tv_nsec / 1000);
|
||||
#else
|
||||
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED, statbuf->st_mtime);
|
||||
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED, _g_stat_mtime (statbuf));
|
||||
#if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC, statbuf->st_mtimensec / 1000);
|
||||
#elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC, statbuf->st_mtim.tv_nsec / 1000);
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC, _g_stat_mtim_nsec (statbuf) / 1000);
|
||||
#endif
|
||||
|
||||
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_ACCESS, statbuf->st_atime);
|
||||
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_ACCESS, _g_stat_atime (statbuf));
|
||||
#if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC, statbuf->st_atimensec / 1000);
|
||||
#elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC, statbuf->st_atim.tv_nsec / 1000);
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_ACCESS_USEC, _g_stat_atim_nsec (statbuf) / 1000);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -1038,11 +1038,11 @@ set_info_from_stat (GFileInfo *info,
|
||||
* https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions#generic-text-routine-mappings
|
||||
* Thank you, Microsoft!
|
||||
*/
|
||||
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CHANGED, statbuf->st_ctime);
|
||||
_g_file_info_set_attribute_uint64_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CHANGED, _g_stat_ctime (statbuf));
|
||||
#if defined (HAVE_STRUCT_STAT_ST_CTIMENSEC)
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC, statbuf->st_ctimensec / 1000);
|
||||
#elif defined (HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC)
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC, statbuf->st_ctim.tv_nsec / 1000);
|
||||
_g_file_info_set_attribute_uint32_by_id (info, G_FILE_ATTRIBUTE_ID_TIME_CHANGED_USEC, _g_stat_ctim_nsec (statbuf) / 1000);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -1306,16 +1306,16 @@ get_content_type (const char *basename,
|
||||
if (is_symlink &&
|
||||
(symlink_broken || (flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)))
|
||||
return g_content_type_from_mime_type ("inode/symlink");
|
||||
else if (statbuf != NULL && S_ISDIR(statbuf->st_mode))
|
||||
else if (statbuf != NULL && S_ISDIR(_g_stat_mode (statbuf)))
|
||||
return g_content_type_from_mime_type ("inode/directory");
|
||||
#ifndef G_OS_WIN32
|
||||
else if (statbuf != NULL && S_ISCHR(statbuf->st_mode))
|
||||
else if (statbuf != NULL && S_ISCHR(_g_stat_mode (statbuf)))
|
||||
return g_content_type_from_mime_type ("inode/chardevice");
|
||||
else if (statbuf != NULL && S_ISBLK(statbuf->st_mode))
|
||||
else if (statbuf != NULL && S_ISBLK(_g_stat_mode (statbuf)))
|
||||
return g_content_type_from_mime_type ("inode/blockdevice");
|
||||
else if (statbuf != NULL && S_ISFIFO(statbuf->st_mode))
|
||||
else if (statbuf != NULL && S_ISFIFO(_g_stat_mode (statbuf)))
|
||||
return g_content_type_from_mime_type ("inode/fifo");
|
||||
else if (statbuf != NULL && S_ISREG(statbuf->st_mode) && statbuf->st_size == 0)
|
||||
else if (statbuf != NULL && S_ISREG(_g_stat_mode (statbuf)) && _g_stat_size (statbuf) == 0)
|
||||
{
|
||||
/* Don't sniff zero-length files in order to avoid reading files
|
||||
* that appear normal but are not (eg: files in /proc and /sys)
|
||||
@ -1328,7 +1328,7 @@ get_content_type (const char *basename,
|
||||
}
|
||||
#endif
|
||||
#ifdef S_ISSOCK
|
||||
else if (statbuf != NULL && S_ISSOCK(statbuf->st_mode))
|
||||
else if (statbuf != NULL && S_ISSOCK(_g_stat_mode (statbuf)))
|
||||
return g_content_type_from_mime_type ("inode/socket");
|
||||
#endif
|
||||
else
|
||||
@ -1827,12 +1827,12 @@ _g_local_file_info_get (const char *basename,
|
||||
stat_ok = res != -1;
|
||||
|
||||
if (stat_ok)
|
||||
device = statbuf.st_dev;
|
||||
device = _g_stat_dev (&statbuf);
|
||||
else
|
||||
device = 0;
|
||||
|
||||
#ifdef S_ISLNK
|
||||
is_symlink = stat_ok && S_ISLNK (statbuf.st_mode);
|
||||
is_symlink = stat_ok && S_ISLNK (_g_stat_mode (&statbuf));
|
||||
#elif defined (G_OS_WIN32)
|
||||
/* glib already checked the FILE_ATTRIBUTE_REPARSE_POINT for us */
|
||||
is_symlink = stat_ok &&
|
||||
@ -1871,7 +1871,7 @@ _g_local_file_info_get (const char *basename,
|
||||
set_info_from_stat (info, &statbuf, attribute_matcher);
|
||||
|
||||
#ifdef G_OS_UNIX
|
||||
if (stat_ok && _g_local_file_is_lost_found_dir (path, statbuf.st_dev))
|
||||
if (stat_ok && _g_local_file_is_lost_found_dir (path, _g_stat_dev (&statbuf)))
|
||||
g_file_info_set_is_hidden (info, TRUE);
|
||||
#endif
|
||||
|
||||
@ -1886,7 +1886,7 @@ _g_local_file_info_get (const char *basename,
|
||||
}
|
||||
|
||||
if (basename != NULL && basename[strlen (basename) -1] == '~' &&
|
||||
(stat_ok && S_ISREG (statbuf.st_mode)))
|
||||
(stat_ok && S_ISREG (_g_stat_mode (&statbuf))))
|
||||
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_IS_BACKUP, TRUE);
|
||||
#else
|
||||
if (statbuf.attributes & FILE_ATTRIBUTE_HIDDEN)
|
||||
@ -1980,7 +1980,7 @@ _g_local_file_info_get (const char *basename,
|
||||
win32_get_file_user_info (path, NULL, &name, NULL);
|
||||
#else
|
||||
if (stat_ok)
|
||||
name = get_username_from_uid (statbuf.st_uid);
|
||||
name = get_username_from_uid (_g_stat_uid (&statbuf));
|
||||
#endif
|
||||
if (name)
|
||||
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_OWNER_USER, name);
|
||||
@ -1995,7 +1995,7 @@ _g_local_file_info_get (const char *basename,
|
||||
win32_get_file_user_info (path, NULL, NULL, &name);
|
||||
#else
|
||||
if (stat_ok)
|
||||
name = get_realname_from_uid (statbuf.st_uid);
|
||||
name = get_realname_from_uid (_g_stat_uid (&statbuf));
|
||||
#endif
|
||||
if (name)
|
||||
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_OWNER_USER_REAL, name);
|
||||
@ -2010,7 +2010,7 @@ _g_local_file_info_get (const char *basename,
|
||||
win32_get_file_user_info (path, &name, NULL, NULL);
|
||||
#else
|
||||
if (stat_ok)
|
||||
name = get_groupname_from_gid (statbuf.st_gid);
|
||||
name = get_groupname_from_gid (_g_stat_gid (&statbuf));
|
||||
#endif
|
||||
if (name)
|
||||
_g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_OWNER_GROUP, name);
|
||||
@ -2019,7 +2019,7 @@ _g_local_file_info_get (const char *basename,
|
||||
|
||||
if (stat_ok && parent_info && parent_info->device != 0 &&
|
||||
_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT) &&
|
||||
(statbuf.st_dev != parent_info->device || statbuf.st_ino == parent_info->inode))
|
||||
(_g_stat_dev (&statbuf) != parent_info->device || _g_stat_ino (&statbuf) == parent_info->inode))
|
||||
_g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_UNIX_IS_MOUNTPOINT, TRUE);
|
||||
|
||||
if (stat_ok)
|
||||
|
@ -48,6 +48,43 @@ typedef struct
|
||||
#define GLocalFileStat struct stat
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef G_OS_WIN32
|
||||
inline static mode_t _g_stat_mode (const GLocalFileStat *buf) { return buf->st_mode; }
|
||||
inline static nlink_t _g_stat_nlink (const GLocalFileStat *buf) { return buf->st_nlink; }
|
||||
#else
|
||||
inline static guint16 _g_stat_mode (const GLocalFileStat *buf) { return buf->st_mode; }
|
||||
inline static guint32 _g_stat_nlink (const GLocalFileStat *buf) { return buf->st_nlink; }
|
||||
#endif
|
||||
inline static dev_t _g_stat_dev (const GLocalFileStat *buf) { return buf->st_dev; }
|
||||
inline static ino_t _g_stat_ino (const GLocalFileStat *buf) { return buf->st_ino; }
|
||||
inline static off_t _g_stat_size (const GLocalFileStat *buf) { return buf->st_size; }
|
||||
|
||||
#ifndef G_OS_WIN32
|
||||
inline static uid_t _g_stat_uid (const GLocalFileStat *buf) { return buf->st_uid; }
|
||||
inline static gid_t _g_stat_gid (const GLocalFileStat *buf) { return buf->st_gid; }
|
||||
inline static dev_t _g_stat_rdev (const GLocalFileStat *buf) { return buf->st_rdev; }
|
||||
inline static blksize_t _g_stat_blksize (const GLocalFileStat *buf) { return buf->st_blksize; }
|
||||
#else
|
||||
inline static guint16 _g_stat_uid (const GLocalFileStat *buf) { return buf->st_uid; }
|
||||
inline static guint16 _g_stat_gid (const GLocalFileStat *buf) { return buf->st_gid; }
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
||||
inline static blkcnt_t _g_stat_blocks (const GLocalFileStat *buf) { return buf->st_blocks; }
|
||||
#endif
|
||||
|
||||
#ifndef G_OS_WIN32
|
||||
inline static time_t _g_stat_atime (const GLocalFileStat *buf) { return buf->st_atime; }
|
||||
inline static time_t _g_stat_ctime (const GLocalFileStat *buf) { return buf->st_ctime; }
|
||||
inline static time_t _g_stat_mtime (const GLocalFileStat *buf) { return buf->st_mtime; }
|
||||
#endif
|
||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
|
||||
inline static guint32 _g_stat_atim_nsec (const GLocalFileStat *buf) { return buf->st_atim.tv_nsec; }
|
||||
inline static guint32 _g_stat_ctim_nsec (const GLocalFileStat *buf) { return buf->st_ctim.tv_nsec; }
|
||||
inline static guint32 _g_stat_mtim_nsec (const GLocalFileStat *buf) { return buf->st_mtim.tv_nsec; }
|
||||
#endif
|
||||
|
||||
#define G_LOCAL_FILE_INFO_NOSTAT_ATTRIBUTES \
|
||||
G_FILE_ATTRIBUTE_STANDARD_NAME "," \
|
||||
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," \
|
||||
|
@ -911,9 +911,9 @@ handle_overwrite_open (const char *filename,
|
||||
}
|
||||
|
||||
/* not a regular file */
|
||||
if (!S_ISREG (original_stat.st_mode))
|
||||
if (!S_ISREG (_g_stat_mode (&original_stat)))
|
||||
{
|
||||
if (S_ISDIR (original_stat.st_mode))
|
||||
if (S_ISDIR (_g_stat_mode (&original_stat)))
|
||||
g_set_error_literal (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_IS_DIRECTORY,
|
||||
@ -953,7 +953,7 @@ handle_overwrite_open (const char *filename,
|
||||
*/
|
||||
|
||||
if ((flags & G_FILE_CREATE_REPLACE_DESTINATION) ||
|
||||
(!(original_stat.st_nlink > 1) && !is_symlink))
|
||||
(!(_g_stat_nlink (&original_stat) > 1) && !is_symlink))
|
||||
{
|
||||
char *dirname, *tmp_filename;
|
||||
int tmpfd;
|
||||
@ -974,10 +974,10 @@ handle_overwrite_open (const char *filename,
|
||||
if ( ! (flags & G_FILE_CREATE_REPLACE_DESTINATION) &&
|
||||
(
|
||||
#ifdef HAVE_FCHOWN
|
||||
fchown (tmpfd, original_stat.st_uid, original_stat.st_gid) == -1 ||
|
||||
fchown (tmpfd, _g_stat_uid (&original_stat), _g_stat_gid (&original_stat)) == -1 ||
|
||||
#endif
|
||||
#ifdef HAVE_FCHMOD
|
||||
fchmod (tmpfd, original_stat.st_mode & ~S_IFMT) == -1 ||
|
||||
fchmod (tmpfd, _g_stat_mode (&original_stat) & ~S_IFMT) == -1 ||
|
||||
#endif
|
||||
0
|
||||
)
|
||||
@ -993,9 +993,9 @@ handle_overwrite_open (const char *filename,
|
||||
#endif
|
||||
/* Check that we really needed to change something */
|
||||
if (tres != 0 ||
|
||||
original_stat.st_uid != tmp_statbuf.st_uid ||
|
||||
original_stat.st_gid != tmp_statbuf.st_gid ||
|
||||
original_stat.st_mode != tmp_statbuf.st_mode)
|
||||
_g_stat_uid (&original_stat) != _g_stat_uid (&tmp_statbuf) ||
|
||||
_g_stat_gid (&original_stat) != _g_stat_gid (&tmp_statbuf) ||
|
||||
_g_stat_mode (&original_stat) != _g_stat_mode (&tmp_statbuf))
|
||||
{
|
||||
g_close (tmpfd, NULL);
|
||||
g_unlink (tmp_filename);
|
||||
@ -1033,7 +1033,7 @@ handle_overwrite_open (const char *filename,
|
||||
|
||||
bfd = g_open (backup_filename,
|
||||
O_WRONLY | O_CREAT | O_EXCL | O_BINARY,
|
||||
original_stat.st_mode & 0777);
|
||||
_g_stat_mode (&original_stat) & 0777);
|
||||
|
||||
if (bfd == -1)
|
||||
{
|
||||
@ -1062,12 +1062,12 @@ handle_overwrite_open (const char *filename,
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
if ((original_stat.st_gid != tmp_statbuf.st_gid) &&
|
||||
fchown (bfd, (uid_t) -1, original_stat.st_gid) != 0)
|
||||
if ((_g_stat_gid (&original_stat) != _g_stat_gid (&tmp_statbuf)) &&
|
||||
fchown (bfd, (uid_t) -1, _g_stat_gid (&original_stat)) != 0)
|
||||
{
|
||||
if (fchmod (bfd,
|
||||
(original_stat.st_mode & 0707) |
|
||||
((original_stat.st_mode & 07) << 3)) != 0)
|
||||
(_g_stat_mode (&original_stat) & 0707) |
|
||||
((_g_stat_mode (&original_stat) & 07) << 3)) != 0)
|
||||
{
|
||||
g_set_error_literal (error,
|
||||
G_IO_ERROR,
|
||||
|
@ -235,9 +235,9 @@ thumbnail_verify (const char *thumbnail_path,
|
||||
#ifdef G_OS_WIN32
|
||||
expected_info.mtime = (guint64) file_stat_buf->st_mtim.tv_sec;
|
||||
#else
|
||||
expected_info.mtime = (guint64) file_stat_buf->st_mtime;
|
||||
expected_info.mtime = _g_stat_mtime (file_stat_buf);
|
||||
#endif
|
||||
expected_info.size = file_stat_buf->st_size;
|
||||
expected_info.size = _g_stat_size (file_stat_buf);
|
||||
|
||||
file = g_mapped_file_new (thumbnail_path, FALSE, NULL);
|
||||
if (file)
|
||||
|
Loading…
Reference in New Issue
Block a user