int deref_stat (char const *name, struct stat *buf);
+size_t blocking_read (int fd, void *buf, size_t count);
+size_t blocking_write (int fd, void const *buf, size_t count);
+
extern int chdir_current;
extern int chdir_fd;
int chdir_arg (char const *dir);
static int
process_rawdata (size_t bytes, char *buffer)
{
- size_t status = safe_read (diff_handle, diff_buffer, bytes);
+ size_t status = blocking_read (diff_handle, diff_buffer, bytes);
if (status != bytes)
{
file_removed_diag (dir->orig_file_name, false, diag);
return;
}
- }
+ }
dumpdir_buffer = directory_contents (scan_directory (dir));
if (dumpdir_buffer)
void
diff_archive (void)
{
-
+
set_next_block_after (current_header);
/* Print the block from current_header and current_stat_info. */
_("Verification may fail to locate original files.")));
clear_directory_table ();
-
+
if (!diff_buffer)
diff_init ();
memset (blk->buffer + size_left, 0, BLOCKSIZE - count);
}
- count = (fd <= 0) ? bufsize : safe_read (fd, blk->buffer, bufsize);
+ count = (fd <= 0) ? bufsize : blocking_read (fd, blk->buffer, bufsize);
if (count == SAFE_READ_ERROR)
{
read_diag_details (st->orig_file_name,
case KEEP_OLD_FILES:
return RECOVER_NO;
-
+
case KEEP_NEWER_FILES:
if (file_newer_p (file_name, stp, ¤t_stat_info))
break;
if (written > size)
written = size;
errno = 0;
- count = full_write (fd, data_block->buffer, written);
+ count = blocking_write (fd, data_block->buffer, written);
size -= written;
set_next_block_after ((union block *)
return fstatat (chdir_fd, name, buf, fstatat_flags);
}
+/* Read from FD into the buffer BUF with COUNT bytes. Attempt to fill
+ BUF. Wait until input is available; this matters because files are
+ opened O_NONBLOCK for security reasons, and on some file systems
+ this can cause read to fail with errno == EAGAIN. Return the
+ actual number of bytes read, zero for EOF, or
+ SAFE_READ_ERROR upon error. */
+size_t
+blocking_read (int fd, void *buf, size_t count)
+{
+ size_t bytes = safe_read (fd, buf, count);
+
+#if defined F_SETFL && O_NONBLOCK
+ if (bytes == SAFE_READ_ERROR && errno == EAGAIN)
+ {
+ int flags = fcntl (fd, F_GETFL);
+ if (0 <= flags && flags & O_NONBLOCK
+ && fcntl (fd, F_SETFL, flags & ~O_NONBLOCK) != -1)
+ bytes = safe_read (fd, buf, count);
+ }
+#endif
+
+ return bytes;
+}
+
+/* Write to FD from the buffer BUF with COUNT bytes. Do a full write.
+ Wait until an output buffer is available; this matters because
+ files are opened O_NONBLOCK for security reasons, and on some file
+ systems this can cause write to fail with errno == EAGAIN. Return
+ the actual number of bytes written, setting errno if that is less
+ than COUNT. */
+size_t
+blocking_write (int fd, void const *buf, size_t count)
+{
+ size_t bytes = full_write (fd, buf, count);
+
+#if defined F_SETFL && O_NONBLOCK
+ if (bytes < count && errno == EAGAIN)
+ {
+ int flags = fcntl (fd, F_GETFL);
+ if (0 <= flags && flags & O_NONBLOCK
+ && fcntl (fd, F_SETFL, flags & ~O_NONBLOCK) != -1)
+ {
+ char const *buffer = buf;
+ bytes += full_write (fd, buffer + bytes, count - bytes);
+ }
+ }
+#endif
+
+ return bytes;
+}
+
/* Set FD's (i.e., assuming the working directory is PARENTFD, FILE's)
access time to ATIME. */
int
if (!tar_sparse_scan (file, scan_begin, NULL))
return false;
- while ((count = safe_read (fd, buffer, sizeof buffer)) != 0
+ while ((count = blocking_read (fd, buffer, sizeof buffer)) != 0
&& count != SAFE_READ_ERROR)
{
/* Analyze the block. */
return false;
}
set_next_block_after (blk);
- count = full_write (file->fd, blk->buffer, wrbytes);
+ count = blocking_write (file->fd, blk->buffer, wrbytes);
write_size -= count;
file->dumped_size += count;
mv_size_left (file->stat_info->archive_file_size - file->dumped_size);
off_t size = 0;
struct sp_array *map = file->stat_info->sparse_map;
char *save_file_name = file->stat_info->file_name;
-
+
#define COPY_STRING(b,dst,src) do \
{ \
char *endp = b->buffer + BLOCKSIZE; \