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