fix extracting sparse files to a filesystem like vfat, when ftruncate may

fail to grow the size of a file.(#179507)
This commit is contained in:
Peter Vrabec 2006-02-06 11:17:45 +00:00
parent 415b3f9707
commit 6c5016002f
2 changed files with 36 additions and 1 deletions

View File

@ -0,0 +1,29 @@
--- tar-1.15.1/src/system.c.vfatTruncate 2004-09-06 07:31:00.000000000 -0400
+++ tar-1.15.1/src/system.c 2006-02-03 14:40:51.000000000 -0500
@@ -272,8 +272,25 @@
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

View File

@ -1,7 +1,7 @@
Summary: A GNU file archiving program.
Name: tar
Version: 1.15.1
Release: 11.1
Release: 12
License: GPL
Group: Applications/Archiving
URL: http://www.gnu.org/software/tar/
@ -16,6 +16,7 @@ Patch11: tar-1.15.1-lseek.patch
Patch12: tar-1.15.1-sparseTotals.patch
Patch13: tar-1.15.1-newerOption.patch
Patch14: tar-1.15.1-padCorrectly.patch
Patch15: tar-1.15.1-vfatTruncate.patch
Prereq: info
BuildRequires: autoconf automake gzip
@ -43,6 +44,7 @@ the rmt package.
%patch12 -p1 -b .sparseTotals
%patch13 -p1 -b .newerOption
%patch14 -p1 -b .padCorrectly
%patch15 -p1 -b .vfatTruncate
%build
@ -113,6 +115,10 @@ fi
%{_infodir}/tar.info*
%changelog
* Mon Feb 06 2006 Peter Vrabec <pvrabec@redhat.com> 1.15.1-12
- fix extracting sparse files to a filesystem like vfat,
when ftruncate may fail to grow the size of a file.(#179507)
* Fri Dec 09 2005 Jesse Keating <jkeating@redhat.com>
- rebuilt