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