core: Reuse more libgsystem API in utils
More code drain to libgsystem.
This commit is contained in:
parent
c9a840c659
commit
cd5fce713c
|
|
@ -1 +1 @@
|
||||||
Subproject commit ce441a7a7bd987265588674a11d62965e81bdf94
|
Subproject commit a2519612547354033f0d513a174f336896776fa8
|
||||||
|
|
@ -189,49 +189,3 @@ ot_util_fatal_gerror (GError *error)
|
||||||
g_assert (error != NULL);
|
g_assert (error != NULL);
|
||||||
ot_util_fatal_literal (error->message);
|
ot_util_fatal_literal (error->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ot_unix_close:
|
|
||||||
*
|
|
||||||
* Like close(), but uses #GError, and handles EINTR.
|
|
||||||
*/
|
|
||||||
gboolean
|
|
||||||
ot_unix_close (int fd, GError **error)
|
|
||||||
{
|
|
||||||
int result;
|
|
||||||
do
|
|
||||||
result = close (fd);
|
|
||||||
while (G_UNLIKELY (result != 0 && errno == EINTR));
|
|
||||||
if (result != 0)
|
|
||||||
{
|
|
||||||
ot_util_set_error_from_errno (error, errno);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ot_unix_open_noatime:
|
|
||||||
*
|
|
||||||
* Open a file for reading, using O_NOATIME if possible.
|
|
||||||
*/
|
|
||||||
gboolean
|
|
||||||
ot_unix_open_noatime (const char *path,
|
|
||||||
int *out_fd,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
#ifdef O_NOATIME
|
|
||||||
fd = g_open (path, O_RDONLY | O_NOATIME | O_CLOEXEC, 0);
|
|
||||||
if (fd == -1 && errno == EPERM)
|
|
||||||
#endif
|
|
||||||
fd = g_open (path, O_RDONLY | O_CLOEXEC, 0);
|
|
||||||
if (fd == -1)
|
|
||||||
{
|
|
||||||
ot_util_set_error_from_errno (error, errno);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
*out_fd = fd;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,6 @@ gboolean ot_unix_open (const char *path,
|
||||||
int *out_fd,
|
int *out_fd,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
gboolean ot_unix_close (int fd, GError **error);
|
|
||||||
|
|
||||||
gboolean ot_unix_open_noatime (const char *path, int *out_fd, GError **error);
|
gboolean ot_unix_open_noatime (const char *path, int *out_fd, GError **error);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
||||||
|
|
@ -109,19 +109,12 @@ ot_util_variant_map (GFile *src,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
const char *path = NULL;
|
|
||||||
ot_lvariant GVariant *ret_variant = NULL;
|
ot_lvariant GVariant *ret_variant = NULL;
|
||||||
GMappedFile *mfile = NULL;
|
GMappedFile *mfile = NULL;
|
||||||
int fd;
|
|
||||||
|
|
||||||
path = gs_file_get_path_cached (src);
|
mfile = gs_file_map_noatime (src, NULL, error);
|
||||||
if (!ot_unix_open_noatime (path, &fd, error))
|
|
||||||
goto out;
|
|
||||||
mfile = g_mapped_file_new_from_fd (fd, FALSE, error);
|
|
||||||
if (!mfile)
|
if (!mfile)
|
||||||
goto out;
|
goto out;
|
||||||
if (!ot_unix_close (fd, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret_variant = g_variant_new_from_data (type,
|
ret_variant = g_variant_new_from_data (type,
|
||||||
g_mapped_file_get_contents (mfile),
|
g_mapped_file_get_contents (mfile),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue