summaryrefslogtreecommitdiff
path: root/rsync
Side-by-side diff
Diffstat (limited to 'rsync') (more/less context) (show whitespace changes)
-rw-r--r--rsync/buf.c2
-rw-r--r--rsync/job.c1
2 files changed, 3 insertions, 0 deletions
diff --git a/rsync/buf.c b/rsync/buf.c
index 2814583..c978fff 100644
--- a/rsync/buf.c
+++ b/rsync/buf.c
@@ -51,147 +51,149 @@
#include "rsync.h"
#include "trace.h"
#include "buf.h"
#include "util.h"
/**
* File IO buffer sizes.
*/
int rs_inbuflen = 16000, rs_outbuflen = 16000;
struct rs_filebuf {
FILE *f;
char *buf;
size_t buf_len;
};
rs_filebuf_t *rs_filebuf_new(FILE *f, size_t buf_len)
{
rs_filebuf_t *pf = rs_alloc_struct(rs_filebuf_t);
pf->buf = rs_alloc(buf_len, "file buffer");
pf->buf_len = buf_len;
pf->f = f;
return pf;
}
void rs_filebuf_free(rs_filebuf_t *fb)
{
if ( fb->buf )
free ( fb->buf );
rs_bzero(fb, sizeof *fb);
free(fb);
}
/*
* If the stream has no more data available, read some from F into
* BUF, and let the stream use that. On return, SEEN_EOF is true if
* the end of file has passed into the stream.
*/
rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf,
void *opaque)
{
+ job=job;
int len;
rs_filebuf_t *fb = (rs_filebuf_t *) opaque;
FILE *f = fb->f;
/* This is only allowed if either the buf has no input buffer
* yet, or that buffer could possibly be BUF. */
if (buf->next_in != NULL) {
assert(buf->avail_in <= fb->buf_len);
assert(buf->next_in >= fb->buf);
assert(buf->next_in <= fb->buf + fb->buf_len);
} else {
assert(buf->avail_in == 0);
}
if (buf->eof_in || (buf->eof_in = feof(f))) {
rs_trace("seen end of file on input");
buf->eof_in = 1;
return RS_DONE;
}
if (buf->avail_in)
/* Still some data remaining. Perhaps we should read
anyhow? */
return RS_DONE;
len = fread(fb->buf, 1, fb->buf_len, f);
if (len < 0) {
if (ferror(f)) {
rs_error("error filling buf from file: %s",
strerror(errno));
return RS_IO_ERROR;
} else {
rs_error("no error bit, but got %d return when trying to read",
len);
return RS_IO_ERROR;
}
}
buf->avail_in = len;
buf->next_in = fb->buf;
return RS_DONE;
}
/*
* The buf is already using BUF for an output buffer, and probably
* contains some buffered output now. Write this out to F, and reset
* the buffer cursor.
*/
rs_result rs_outfilebuf_drain(rs_job_t *job, rs_buffers_t *buf, void *opaque)
{
+ job=job;
int present;
rs_filebuf_t *fb = (rs_filebuf_t *) opaque;
FILE *f = fb->f;
/* This is only allowed if either the buf has no output buffer
* yet, or that buffer could possibly be BUF. */
if (buf->next_out == NULL) {
assert(buf->avail_out == 0);
buf->next_out = fb->buf;
buf->avail_out = fb->buf_len;
return RS_DONE;
}
assert(buf->avail_out <= fb->buf_len);
assert(buf->next_out >= fb->buf);
assert(buf->next_out <= fb->buf + fb->buf_len);
present = buf->next_out - fb->buf;
if (present > 0) {
int result;
assert(present > 0);
result = fwrite(fb->buf, 1, present, f);
if (present != result) {
rs_error("error draining buf to file: %s",
strerror(errno));
return RS_IO_ERROR;
}
buf->next_out = fb->buf;
buf->avail_out = fb->buf_len;
}
return RS_DONE;
}
/**
* Default copy implementation that retrieves a part of a stdio file.
*/
rs_result rs_file_copy_cb(void *arg, off_t pos, size_t *len, void **buf)
{
int got;
FILE *f = (FILE *) arg;
diff --git a/rsync/job.c b/rsync/job.c
index 680982d..36f39f0 100644
--- a/rsync/job.c
+++ b/rsync/job.c
@@ -49,96 +49,97 @@
#include "stream.h"
#include "util.h"
#include "sumset.h"
#include "job.h"
#include "trace.h"
static const int rs_job_tag = 20010225;
static rs_result rs_job_work(rs_job_t *job, rs_buffers_t *buffers);
rs_job_t * rs_job_new(char const *job_name, rs_result (*statefn)(rs_job_t *))
{
rs_job_t *job;
job = rs_alloc_struct(rs_job_t);
job->job_name = job_name;
job->dogtag = rs_job_tag;
job->statefn = statefn;
job->stats.op = job_name;
rs_trace("start %s job", job_name);
return job;
}
void rs_job_check(rs_job_t *job)
{
assert(job->dogtag == rs_job_tag);
}
rs_result rs_job_free(rs_job_t *job)
{
rs_bzero(job, sizeof *job);
free(job);
return RS_DONE;
}
static rs_result rs_job_s_complete(rs_job_t *job)
{
+ job = job;
rs_fatal("should not be reached");
return RS_INTERNAL_ERROR;
}
static rs_result rs_job_complete(rs_job_t *job, rs_result result)
{
rs_job_check(job);
job->statefn = rs_job_s_complete;
job->final_result = result;
if (result != RS_DONE) {
rs_error("%s job failed: %s", job->job_name, rs_strerror(result));
} else {
rs_trace("%s job complete", job->job_name);
}
if (result == RS_DONE && !rs_tube_is_idle(job))
/* Processing is finished, but there is still some data
* waiting to get into the output buffer. */
return RS_BLOCKED;
else
return result;
}
/**
* \brief Run a ::rs_job_t state machine until it blocks
* (::RS_BLOCKED), returns an error, or completes (::RS_COMPLETE).
*
* \return The ::rs_result that caused iteration to stop.
*
* \param ending True if there is no more data after what's in the
* input buffer. The final block checksum will run across whatever's
* in there, without trying to accumulate anything else.
*/
rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers)
{
rs_result result;
rs_long_t orig_in, orig_out;
orig_in = buffers->avail_in;
orig_out = buffers->avail_out;
result = rs_job_work(job, buffers);
if (result == RS_BLOCKED || result == RS_DONE)