Avoid ext4 auto_da_alloc flush on close.
authorRichard W.M. Jones <rjones@redhat.com>
Tue, 22 Oct 2013 21:14:34 +0000 (22:14 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 22 Oct 2013 21:14:34 +0000 (22:14 +0100)
Avoid annoying ext4 auto_da_alloc which causes a flush on close unless
we are very careful about not truncating the file when it has zero
size.  (Thanks Eric Sandeen)

pxzcat.c

index 4ab8689..80a8820 100644 (file)
--- a/pxzcat.c
+++ b/pxzcat.c
@@ -165,9 +165,18 @@ xzfile_uncompress (const char *filename, const char *outputfile,
   size = lzma_index_uncompressed_size (idx);
   debug ("uncompressed size = %" PRIu64 " bytes", size);
 
+  /* Avoid annoying ext4 auto_da_alloc which causes a flush on close
+   * unless we are very careful about not truncating the file when it
+   * has zero size.  (Thanks Eric Sandeen)
+   */
+  unlink (outputfile);
+
   ofd = open (outputfile, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY, 0644);
   if (ofd == -1)
     error (EXIT_FAILURE, errno, "open: %s", outputfile);
+  /* See above about auto_da_alloc. */
+  write (ofd, " ", 1);
+
   if (ftruncate (ofd, size) == -1)
     error (EXIT_FAILURE, errno, "ftruncate: %s", outputfile);