--- a/xmlsitemap.xmlsitemap.inc	2012-07-25 15:56:24.000000000 -0500
+++ b/xmlsitemap.xmlsitemap.inc.orig	2012-06-22 09:06:25.000000000 -0500
@@ -13,6 +13,7 @@
  * Extended class for writing XML sitemap files.
  */
 class XMLSitemapWriter extends XMLWriter {
+  protected $status = TRUE;
   protected $uri = NULL;
   protected $sitemapElementCount = 0;
   protected $linkCountFlush = 500;
@@ -133,6 +134,19 @@
     }
   }
 
+  /**
+   * Override of XMLWriter::flush() to track file writing status.
+   */
+  public function flush($empty = TRUE) {
+    $return = parent::flush($empty);
+    $this->status &= (bool) $return;
+    return $return;
+  }
+
+  public function getStatus() {
+    return $this->status;
+  }
+
   public function getURI() {
     return $this->uri;
   }
@@ -144,7 +158,7 @@
   public function endDocument() {
     $return = parent::endDocument();
 
-    if (!$return) {
+    if (!$this->getStatus()) {
       throw new XMLSitemapGenerationException(t('Unknown error occurred while writing to file @file.', array('@file' => $this->uri)));
     }
 
