tar/tar-1.15.1-vfatTruncate.patch
Pavel Raiskup 98b687cc8b spec/patches: little bit of reorganization
* re-create patches against latest release (to avoid fuzzy offset warnings
  during patching)
* remove old xattr patch (up2date upstream patch will be added in next
  commit)
* remove some old patches which are not needed against 1.26 tarball now
* add more verbose comments for patches

Version: 2:1.26-17
2013-02-19 13:18:19 +01:00

32 lines
965 B
Diff

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