Blame SOURCES/tar-1.15.1-vfatTruncate.patch

a4d85a
diff --git a/src/system.c b/src/system.c
a4d85a
index ba4ac2d..ea88cd6 100644
a4d85a
--- a/src/system.c
a4d85a
+++ b/src/system.c
a4d85a
@@ -231,8 +231,25 @@ sys_compare_links (struct stat *link_data, struct stat *stat_data)
a4d85a
 int
a4d85a
 sys_truncate (int fd)
a4d85a
 {
a4d85a
+  struct stat st;
a4d85a
   off_t pos = lseek (fd, (off_t) 0, SEEK_CUR);
a4d85a
-  return pos < 0 ? -1 : ftruncate (fd, pos);
a4d85a
+
a4d85a
+  if ( pos < 0) 
a4d85a
+    return -1;
a4d85a
+
a4d85a
+  if ( ftruncate(fd, pos) && errno == EPERM ) {
a4d85a
+    /* wrapper around ftruncate:
a4d85a
+     * ftruncate may fail to grow the size of a file with some OS and filesystem
a4d85a
+     * combinations. Linux and vfat/fat is one example. If this is the case do
a4d85a
+     * a write to grow the file to the desired length.
a4d85a
+     */
a4d85a
+    if( (fstat( fd, &st ) == -1) || 
a4d85a
+        (st.st_size >= pos)  ||
a4d85a
+        (lseek( fd, pos - 1, SEEK_SET) == (off_t)-1) ||
a4d85a
+        (write( fd, "\0", 1) == -1) )
a4d85a
+	return -1;
a4d85a
+  }
a4d85a
+  return 0;
a4d85a
 }
a4d85a
 
a4d85a
 /* Return nonzero if NAME is the name of a regular file, or if the file