core: More cleanup of GIO utility API

This commit is contained in:
Colin Walters committed 2011-11-18 08:43:47 -05:00
1 parent 231f7ed76c
commit 9cf15ed151
4 files changed
+29 -73

No files matched your search

+8 -51
View File
@@ -30,13 +30,13 @@
#include "otutil.h"
gboolean
ot_util_ensure_directory (const char *path, gboolean with_parents, GError **error)
ot_gfile_ensure_directory (GFile *dir,
gboolean with_parents,
GError **error)
{
GFile *dir;
GError *temp_error = NULL;
gboolean ret = FALSE;
dir = ot_gfile_new_for_path (path);
if (with_parents)
ret = g_file_make_directory_with_parents (dir, NULL, &temp_error);
else
@@ -54,33 +54,15 @@ ot_util_ensure_directory (const char *path, gboolean with_parents, GError **erro
ret = TRUE;
out:
g_clear_object (&dir);
return ret;
}
char *
ot_util_get_file_contents_utf8 (const char *path,
GError **error)
{
GFile *file = NULL;
char *ret = NULL;
file = ot_gfile_new_for_path (path);
if (!ot_util_gfile_load_contents_utf8 (file, NULL, &ret, NULL, error))
goto out;
out:
g_clear_object (&file);
return ret;
}
gboolean
ot_util_gfile_load_contents_utf8 (GFile *file,
GCancellable *cancellable,
char **contents_out,
char **etag_out,
GError **error)
ot_gfile_load_contents_utf8 (GFile *file,
char **contents_out,
char **etag_out,
GCancellable *cancellable,
GError **error)
{
char *ret_contents = NULL;
char *ret_etag = NULL;
@@ -115,31 +97,6 @@ ot_util_gfile_load_contents_utf8 (GFile *file,
return ret;
}
GInputStream *
ot_util_read_file_noatime (GFile *file, GCancellable *cancellable, GError **error)
{
GInputStream *ret = NULL;
int fd;
int flags = O_RDONLY;
const char *path = NULL;
path = ot_gfile_get_path_cached (file);
#ifdef O_NOATIME
flags |= O_NOATIME;
#endif
fd = open (path, flags);
if (fd < 0)
{
ot_util_set_error_from_errno (error, errno);
goto out;
}
ret = (GInputStream*)g_unix_input_stream_new (fd, TRUE);
out:
return ret;
}
/* Like g_file_new_for_path, but only do local stuff, not GVFS */
GFile *
ot_gfile_new_for_path (const char *path)
+6 -10
View File
@@ -33,17 +33,13 @@ const char *ot_gfile_get_path_cached (GFile *file);
const char *ot_gfile_get_basename_cached (GFile *file);
gboolean ot_util_ensure_directory (const char *path, gboolean with_parents, GError **error);
gboolean ot_gfile_ensure_directory (GFile *dir, gboolean with_parents, GError **error);
char * ot_util_get_file_contents_utf8 (const char *path, GError **error);
gboolean ot_util_gfile_load_contents_utf8 (GFile *file,
GCancellable *cancellable,
char **contents_out,
char **etag_out,
GError **error);
GInputStream *ot_util_read_file_noatime (GFile *file, GCancellable *cancellable, GError **error);
gboolean ot_gfile_load_contents_utf8 (GFile *file,
char **contents_out,
char **etag_out,
GCancellable *cancellable,
GError **error);
G_END_DECLS