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