Blame SOURCES/tar-1.28-vfatTruncate.patch

681352
From 90f446f9b04ab820a99b9408e68c01dc6b57056c Mon Sep 17 00:00:00 2001
681352
From: rpm-build <rpm-build>
681352
Date: Mon, 28 Jul 2014 08:10:10 +0200
681352
Subject: [PATCH 2/9] vfat-like FS & sparse (still downstream)
681352
681352
Fix extracting sparse files to a file system like vfat, when
681352
ftruncate may fail to grow the size of a file.  Still downstram,
681352
(do we need this now? ftruncate & vfat works is now OK).
681352
681352
Resolves: #179507
681352
681352
Upstream bugreport:
681352
http://lists.gnu.org/archive/html/bug-tar/2006-02/msg00000.html
681352
681352
---
681352
 src/system.c | 19 ++++++++++++++++++-
681352
 1 file changed, 18 insertions(+), 1 deletion(-)
681352
681352
diff --git a/src/system.c b/src/system.c
681352
index 9414233..37e9a3e 100644
681352
--- a/src/system.c
681352
+++ b/src/system.c
681352
@@ -243,8 +243,25 @@ sys_compare_links (struct stat *link_data, struct stat *stat_data)
681352
 int
681352
 sys_truncate (int fd)
681352
 {
681352
+  struct stat st;
681352
   off_t pos = lseek (fd, (off_t) 0, SEEK_CUR);
681352
-  return pos < 0 ? -1 : ftruncate (fd, pos);
681352
+
681352
+  if ( pos < 0) 
681352
+    return -1;
681352
+
681352
+  if ( ftruncate(fd, pos) && errno == EPERM ) {
681352
+    /* wrapper around ftruncate:
681352
+     * ftruncate may fail to grow the size of a file with some OS and filesystem
681352
+     * combinations. Linux and vfat/fat is one example. If this is the case do
681352
+     * a write to grow the file to the desired length.
681352
+     */
681352
+    if( (fstat( fd, &st ) == -1) || 
681352
+        (st.st_size >= pos)  ||
681352
+        (lseek( fd, pos - 1, SEEK_SET) == (off_t)-1) ||
681352
+        (write( fd, "\0", 1) == -1) )
681352
+	return -1;
681352
+  }
681352
+  return 0;
681352
 }
681352
 
681352
 /* Return nonzero if NAME is the name of a regular file, or if the file
681352
-- 
681352
1.9.3
681352