[vte/vte-0-34] [stream-file] Recover from a disk-full situation



commit a43839c166da7cc0a89bd7eb0b78b991bdff5471
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 6d2371e..c11a315 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]