[ostree/wip/error-handling: 2/2] Give more descriptive errors on some file operations
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/error-handling: 2/2] Give more descriptive errors on some file operations
- Date: Wed, 18 Jul 2012 14:34:39 +0000 (UTC)
commit 612061a1a1124b92f84ee3dad604a3266e9b6ba0
Author: Sam Thursfield <sam thursfield codethink co uk>
Date: Fri Jul 13 17:22:15 2012 +0100
Give more descriptive errors on some file operations
src/libostree/ostree-core.c | 12 ++++++------
src/libotutil/ot-unix-utils.c | 28 ++++++++++++++++++++++++++++
src/libotutil/ot-unix-utils.h | 2 ++
3 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 2d61b18..a6736ed 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -1084,7 +1084,7 @@ ostree_create_file_from_input (GFile *dest_file,
{
if (mkdir (ot_gfile_get_path_cached (dest_file), mode) < 0)
{
- ot_util_set_error_from_errno (error, errno);
+ ot_util_set_error_from_errno_full (error, errno, "Unable to make directory at %s: ", ot_gfile_get_path_cached (dest_file));
goto out;
}
}
@@ -1109,7 +1109,7 @@ ostree_create_file_from_input (GFile *dest_file,
const char *target = g_file_info_get_attribute_byte_string (finfo, "standard::symlink-target");
if (symlink (target, dest_path) < 0)
{
- ot_util_set_error_from_errno (error, errno);
+ ot_util_set_error_from_errno_full (error, errno, "Unable to create link %s to file %s: ", target, dest_path);
goto out;
}
}
@@ -1118,7 +1118,7 @@ ostree_create_file_from_input (GFile *dest_file,
guint32 dev = g_file_info_get_attribute_uint32 (finfo, "unix::rdev");
if (mknod (dest_path, mode, dev) < 0)
{
- ot_util_set_error_from_errno (error, errno);
+ ot_util_set_error_from_errno_full (error, errno, "Unable to make device node at %s: ", dest_path);
goto out;
}
}
@@ -1126,7 +1126,7 @@ ostree_create_file_from_input (GFile *dest_file,
{
if (mkfifo (dest_path, mode) < 0)
{
- ot_util_set_error_from_errno (error, errno);
+ ot_util_set_error_from_errno_full (error, errno, "Unable to make pipe at %s: ", dest_path);
goto out;
}
}
@@ -1144,7 +1144,7 @@ ostree_create_file_from_input (GFile *dest_file,
if (lchown (dest_path, uid, gid) < 0)
{
- ot_util_set_error_from_errno (error, errno);
+ ot_util_set_error_from_errno_full (error, errno, "Unable to set owner of %s: ", dest_path);
goto out;
}
}
@@ -1153,7 +1153,7 @@ ostree_create_file_from_input (GFile *dest_file,
{
if (chmod (dest_path, mode) < 0)
{
- ot_util_set_error_from_errno (error, errno);
+ ot_util_set_error_from_errno_full (error, errno, "Unable to set mode of %s: ", dest_path);
goto out;
}
}
diff --git a/src/libotutil/ot-unix-utils.c b/src/libotutil/ot-unix-utils.c
index ee8f039..fc6abc7 100644
--- a/src/libotutil/ot-unix-utils.c
+++ b/src/libotutil/ot-unix-utils.c
@@ -32,6 +32,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
+#include <stdarg.h>
gboolean
ot_util_spawn_pager (GOutputStream **out_stream,
@@ -172,6 +173,33 @@ ot_util_set_error_from_errno (GError **error,
}
void
+ot_util_set_error_from_errno_full (GError **error,
+ gint saved_errno,
+ const gchar *format,
+ ...)
+{
+ va_list args;
+ GString *message;
+
+ va_start (args, format);
+
+ message = g_string_new (NULL);
+ g_string_vprintf (message, format, args);
+ g_string_append (message, g_strerror (saved_errno));
+
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ g_io_error_from_errno (saved_errno),
+ message->str);
+
+ g_string_free (message, TRUE);
+
+ va_end (args);
+
+ errno = saved_errno;
+}
+
+void
ot_util_fatal_literal (const char *msg)
{
g_printerr ("%s\n", msg);
diff --git a/src/libotutil/ot-unix-utils.h b/src/libotutil/ot-unix-utils.h
index 58dd59b..2ff99f5 100644
--- a/src/libotutil/ot-unix-utils.h
+++ b/src/libotutil/ot-unix-utils.h
@@ -49,6 +49,8 @@ gboolean ot_util_path_split_validate (const char *path, GPtrArray **out_componen
void ot_util_set_error_from_errno (GError **error, gint saved_errno);
+void ot_util_set_error_from_errno_full (GError **error, gint saved_errno, const gchar *format, ...);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]