[vte/vte-next] [stream-file] Recover from a disk-full situation
- From: Behdad Esfahbod <behdad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-next] [stream-file] Recover from a disk-full situation
- Date: Fri, 27 Sep 2013 22:19:10 +0000 (UTC)
commit f9658031418802e6814c599c855abe90441200ca
Author: Behdad Esfahbod <behdad behdad org>
Date: Fri Sep 27 18:18:34 2013 -0400
[stream-file] Recover from a disk-full situation
src/vtestream-file.h | 38 +++++++++++++++++++++++++-------------
1 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/src/vtestream-file.h b/src/vtestream-file.h
index 0f7b720..fd80ccd 100644
--- a/src/vtestream-file.h
+++ b/src/vtestream-file.h
@@ -48,6 +48,19 @@ pwrite (int fd, char *data, gsize len, gsize offset)
}
#endif
+static void
+_xtruncate (gint fd, gsize offset)
+{
+ int ret;
+
+ if (G_UNLIKELY (!fd))
+ return;
+
+ do {
+ ret = ftruncate (fd, offset);
+ } while (ret == -1 && errno == EINTR);
+}
+
static gsize
_xpread (int fd, char *data, gsize len, gsize offset)
{
@@ -78,6 +91,7 @@ static void
_xpwrite (int fd, const char *data, gsize len, gsize offset)
{
gsize ret;
+ gboolean truncated = FALSE;
g_assert (fd || !len);
@@ -86,6 +100,17 @@ _xpwrite (int fd, const char *data, gsize len, gsize offset)
if (G_UNLIKELY (ret == (gsize) -1)) {
if (errno == EINTR)
continue;
+ else if (errno == EINVAL && !truncated)
+ {
+ /* Perhaps previous writes failed and now we are
+ * seeking past end of file. Try extending it
+ * and retry. This allows recovering from a
+ * "/tmp is full" error.
+ */
+ _xtruncate (fd, offset);
+ truncated = TRUE;
+ continue;
+ }
else
break;
}
@@ -97,19 +122,6 @@ _xpwrite (int fd, const char *data, gsize len, gsize offset)
}
}
-static void
-_xtruncate (gint fd, gsize offset)
-{
- int ret;
-
- if (G_UNLIKELY (!fd))
- return;
-
- do {
- ret = ftruncate (fd, offset);
- } while (ret == -1 && errno == EINTR);
-}
-
static gboolean
_xwrite_contents (gint fd, GOutputStream *output, GCancellable *cancellable, GError **error)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]