Blame SOURCES/tar-1.28-vfatTruncate.patch

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