summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/archive_write_open_fd.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libarchive/archive_write_open_fd.c')
-rw-r--r--lib/libarchive/archive_write_open_fd.c51
1 files changed, 21 insertions, 30 deletions
diff --git a/lib/libarchive/archive_write_open_fd.c b/lib/libarchive/archive_write_open_fd.c
index b61ee08..87acf88 100644
--- a/lib/libarchive/archive_write_open_fd.c
+++ b/lib/libarchive/archive_write_open_fd.c
@@ -74,44 +74,35 @@ static int
file_open(struct archive *a, void *client_data)
{
struct write_fd_data *mine;
- struct stat st, *pst;
+ struct stat st;
- pst = NULL;
mine = (struct write_fd_data *)client_data;
+ if (fstat(mine->fd, &st) != 0) {
+ archive_set_error(a, errno, "Couldn't stat fd %d", mine->fd);
+ return (ARCHIVE_FATAL);
+ }
+
/*
- * If client hasn't explicitly set the last block handling,
- * then set it here: If the output is a block or character
- * device, pad the last block, otherwise leave it unpadded.
+ * If this is a regular file, don't add it to itself.
*/
- if (mine->fd >= 0 && a->bytes_in_last_block < 0) {
- /* Last block will be fully padded. */
- if (fstat(mine->fd, &st) == 0) {
- pst = &st;
- if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) ||
- S_ISFIFO(st.st_mode))
- archive_write_set_bytes_in_last_block(a, 0);
- else
- archive_write_set_bytes_in_last_block(a, 1);
- }
- }
+ if (S_ISREG(st.st_mode))
+ archive_write_set_skip_file(a, st.st_dev, st.st_ino);
- if (mine->fd == 1) {
- if (a->bytes_in_last_block < 0) /* Still default? */
+ /*
+ * If client hasn't explicitly set the last block handling,
+ * then set it here.
+ */
+ if (archive_write_get_bytes_in_last_block(a) < 0) {
+ /* If the output is a block or character device, fifo,
+ * or stdout, pad the last block, otherwise leave it
+ * unpadded. */
+ if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) ||
+ S_ISFIFO(st.st_mode) || (mine->fd == 1))
/* Last block will be fully padded. */
archive_write_set_bytes_in_last_block(a, 0);
- }
-
- if (mine->fd < 0) {
- archive_set_error(a, errno, "Failed to open");
- return (ARCHIVE_FATAL);
- }
-
- if (pst == NULL && fstat(mine->fd, &st) == 0)
- pst = &st;
- if (pst == NULL) {
- archive_set_error(a, errno, "Couldn't stat fd %d", mine->fd);
- return (ARCHIVE_FATAL);
+ else
+ archive_write_set_bytes_in_last_block(a, 1);
}
return (ARCHIVE_OK);
OpenPOWER on IntegriCloud