summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2003-09-07 23:11:37 +0000
committerLennart Poettering <lennart@poettering.net>2003-09-07 23:11:37 +0000
commit17fac7f2c92df794b88648a95bea6796621dbe83 (patch)
treef50baaf521f683a24e3de98141643863fab74af1 /src
parent411862e81940e9eaea542ae1c4a04cca5e5b88a3 (diff)
Many fixes, primarily documentation
git-svn-id: file:///home/lennart/svn/public/syrep/trunk@32 07ea20a6-d2c5-0310-9e02-9ef735347d72
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am5
-rw-r--r--src/context.c104
-rw-r--r--src/makepatch.c8
-rw-r--r--src/merge.c8
-rw-r--r--src/package.c37
-rw-r--r--src/package.h2
-rw-r--r--src/syrep.c4
-rw-r--r--src/util.c17
8 files changed, 141 insertions, 44 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 3386f58..078fe48 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,7 +16,6 @@
# along with syrep; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
bin_PROGRAMS = syrep
syrep_SOURCES = cache.c cache.h \
@@ -44,9 +43,10 @@ syrep_SOURCES = cache.c cache.h \
EXTRA_DIST = syrep.ggo
MAINTAINERCLEANFILES =
BUILT_SOURCES =
+CLEANFILES =
if USE_GENGETOPT
-MAINTAINERCLEANFILES += cmdline.c cmdline.h
+CLEANFILES += cmdline.c cmdline.h
BUILT_SOURCES += cmdline.c cmdline.h
endif
@@ -66,6 +66,7 @@ cmdline.c cmdline.h: syrep.ggo Makefile
endif
if USE_SUBVERSION
+
svn-revision.h: Makefile
if test -d "$(top_srcdir)/.svn" ; then \
if REV=`svn info "$(top_srcdir)" | grep ^Revision | cut -f2 -d" "` 2> /dev/null ; then \
diff --git a/src/context.c b/src/context.c
index b0cfc78..677704d 100644
--- a/src/context.c
+++ b/src/context.c
@@ -98,6 +98,7 @@ struct syrep_db_context* db_context_open(const char *filename, int force) {
struct syrep_db_context *c = NULL;
const char* path;
FILE *f;
+ int k;
if (!(c = malloc(sizeof(struct syrep_db_context))))
goto fail;
@@ -107,7 +108,11 @@ struct syrep_db_context* db_context_open(const char *filename, int force) {
if (!(c->package = package_open(filename, force)))
goto fail;
- path = package_get_item(c->package, "timestamp", 1);
+ if ((k = package_get_item(c->package, "timestamp", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
if ((f = fopen(path, "r"))) {
if (fscanf(f, "%i", &c->timestamp) != 1)
c->timestamp = 0;
@@ -117,14 +122,22 @@ struct syrep_db_context* db_context_open(const char *filename, int force) {
if (!c->timestamp)
c->timestamp = time(NULL);
- path = package_get_item(c->package, "version", 1);
+ if ((k = package_get_item(c->package, "version", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
if ((f = fopen(path, "r"))) {
if (fscanf(f, "%u", &c->version) != 1)
c->version = 0;
fclose(f);
}
- path = package_get_item(c->package, "origin", 1);
+ if ((k = package_get_item(c->package, "origin", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
if ((f = fopen(path, "r"))) {
char hn[256];
if (fgets(hn, sizeof(hn), f)) {
@@ -150,35 +163,75 @@ struct syrep_db_context* db_context_open(const char *filename, int force) {
}
/* Creating database id_meta */
- if (!(c->db_id_meta = open_db(package_get_item(c->package, "id_meta", 1), 0, 0)))
+ if ((k = package_get_item(c->package, "id_meta", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
+ if (!(c->db_id_meta = open_db(path, 0, 0)))
goto fail;
/* Creating database md_nrecno */
- if (!(c->db_md_nrecno = open_db(package_get_item(c->package, "md_nrecno", 1), 1, 0)))
+ if ((k = package_get_item(c->package, "md_nrecno", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
+ if (!(c->db_md_nrecno = open_db(path, 1, 0)))
goto fail;
/* Creating database nrecno_md */
- if (!(c->db_nrecno_md = open_db(package_get_item(c->package, "nrecno_md", 1), 1, 0)))
+ if ((k = package_get_item(c->package, "nrecno_md", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
+ if (!(c->db_nrecno_md = open_db(path, 1, 0)))
goto fail;
/* Creating database nrecno_lastmd */
- if (!(c->db_nrecno_lastmd = open_db(package_get_item(c->package, "nrecno_lastmd", 1), 0, 0)))
+ if ((k = package_get_item(c->package, "nrecno_lastmd", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
+ if (!(c->db_nrecno_lastmd = open_db(path, 0, 0)))
goto fail;
/* Creating database md_lastnrecno */
- if (!(c->db_md_lastnrecno = open_db(package_get_item(c->package, "md_lastnrecno", 1), 0, 0)))
+ if ((k = package_get_item(c->package, "md_lastnrecno", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
+ if (!(c->db_md_lastnrecno = open_db(path, 0, 0)))
goto fail;
/* Creating database version_timestamp */
- if (!(c->db_version_timestamp = open_db(package_get_item(c->package, "version_timestamp", 1), 0, 0)))
+ if ((k = package_get_item(c->package, "version_timestamp", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
+ if (!(c->db_version_timestamp = open_db(path, 0, 0)))
goto fail;
/* Creating database nhash_nrecno */
- if (!(c->db_nhash_nrecno = open_db(package_get_item(c->package, "nhash_nrecno", 1), 1, 0)))
+ if ((k = package_get_item(c->package, "nhash_nrecno", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
+ if (!(c->db_nhash_nrecno = open_db(path, 1, 0)))
goto fail;
/* Creating database nrecno_name */
- if (!(c->db_nrecno_name = open_db(package_get_item(c->package, "nrecno_name", 1), 0, 1)))
+ if ((k = package_get_item(c->package, "nrecno_name", 1, &path)) < 0)
+ goto fail;
+
+ assert(k);
+
+ if (!(c->db_nrecno_name = open_db(path, 0, 1)))
goto fail;
return c;
@@ -192,6 +245,8 @@ fail:
int db_context_save(struct syrep_db_context *c, const char *filename) {
FILE *f;
+ int k;
+ const char *path;
assert(c && c->package);
if (c->db_id_meta)
@@ -217,20 +272,41 @@ int db_context_save(struct syrep_db_context *c, const char *filename) {
if (c->db_nrecno_name)
c->db_nrecno_name->sync(c->db_nrecno_name, 0);
+
+ /* Saving timestamp info */
- if (!(f = fopen(package_get_item(c->package, "timestamp", 1), "w+")))
+ if ((k = package_get_item(c->package, "timestamp", 1, &path)) < 0)
+ return -1;
+
+ assert(k);
+
+ if (!(f = fopen(path, "w+")))
return -1;
fprintf(f, "%i\n", c->timestamp);
fclose(f);
- if (!(f = fopen(package_get_item(c->package, "version", 1), "w+")))
+ /* Save version info */
+
+ if ((k = package_get_item(c->package, "version", 1, &path)) < 0)
+ return -1;
+
+ assert(k);
+
+ if (!(f = fopen(path, "w+")))
return -1;
fprintf(f, "%u\n", c->version);
fclose(f);
- if (!(f = fopen(package_get_item(c->package, "origin", 1), "w+")))
+ /* Save origin info */
+
+ if ((k = package_get_item(c->package, "origin", 1, &path)) < 0)
+ return -1;
+
+ assert(k);
+
+ if (!(f = fopen(path, "w+")))
return -1;
fprintf(f, "%s\n", c->origin);
diff --git a/src/makepatch.c b/src/makepatch.c
index 278cd38..3de8860 100644
--- a/src/makepatch.c
+++ b/src/makepatch.c
@@ -40,7 +40,7 @@ static int cb(DB *ddb, struct syrep_name *name, struct diff_entry *de, void *p)
struct syrep_nrecno nrecno;
char path[PATH_MAX+1];
char d[SYREP_DIGESTLENGTH*2+1];
- int f;
+ int f, k;
assert(ddb && name && de && p);
@@ -77,14 +77,16 @@ static int cb(DB *ddb, struct syrep_name *name, struct diff_entry *de, void *p)
snprintf(path, sizeof(path), "%s/%s", cb_info->root, name->path);
- if (!package_get_item(cb_info->c1->package, d, 0)) {
+ if ((k = package_get_item(cb_info->c1->package, d, 0, NULL)) < 0)
+ return -1;
+
+ if (!k) {
if (args.verbose_flag)
fprintf(stderr, "Adding %s (%s) to patch.\n", name->path, d);
if (package_add_file(cb_info->c1->package, d, path) < 0)
return -1;
-
}
return 0;
diff --git a/src/merge.c b/src/merge.c
index 206e2d9..01e1981 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -61,7 +61,7 @@ static int conflict_phase(DB *ddb, struct syrep_name *name, struct diff_entry *d
if ((f1 = get_current_md_by_nrecno(cb_info->c1, &nrecno1, &md1)) < 0)
return -1;
- if ((f2 = get_nrecno_by_name(cb_info->c2, name, &nrecno1, 0)) < 0)
+ if ((f2 = get_nrecno_by_name(cb_info->c2, name, &nrecno2, 0)) < 0)
return -1;
if (f2)
@@ -236,8 +236,12 @@ static int copy_phase(DB *ddb, struct syrep_name *name, struct diff_entry *de, v
} else {
const char* a;
+ int k;
- if ((a = package_get_item(cb_info->c1->package, d, 0))) {
+ if ((k = package_get_item(cb_info->c1->package, d, 0, &a)) < 0)
+ return -1;
+
+ if (k) {
fprintf(stderr, "COPY: Copying file <%s> from patch.\n", name->path);
if (makeprefixpath(path, 0777) < 0)
diff --git a/src/package.c b/src/package.c
index 3d23306..9496742 100644
--- a/src/package.c
+++ b/src/package.c
@@ -717,42 +717,57 @@ finish:
return r;
}
-const char *package_get_item(struct package* p, const char *name, int c) {
+int package_get_item(struct package* p, const char *name, int c, const char ** fn) {
struct package_item *i;
char path[PATH_MAX];
assert(p && name);
for (i = p->items; i; i = i->next)
- if (!strncmp(name, i->name, PACKAGE_ITEMNAMELEN))
- return i->path;
+ if (!strncmp(name, i->name, PACKAGE_ITEMNAMELEN)) {
+ if (fn)
+ *fn = i->path;
+
+ return 1;
+ }
for (;;) {
int r;
if ((r = read_item(p)) < 0)
- return NULL;
+ return -1;
- if (r == 0)
+ if (!r)
break;
assert(p->last);
- if (!strncmp(name, p->last->name, PACKAGE_ITEMNAMELEN))
- return p->last->path;
+ if (!strncmp(name, p->last->name, PACKAGE_ITEMNAMELEN)) {
+ if (fn)
+ *fn = p->last->path;
+
+ return 1;
+ }
}
if (!c)
- return NULL;
+ return 0;
snprintf(path, sizeof(path), "%s/%i", p->base, p->count++);
if (!(i = item_new(name, path, 1))) {
unlink(path);
- return NULL;
+ return -1;
}
-
+
append_item(p, i);
+
+ assert(i);
+
+ assert(fn);
- return i->path;
+ if (fn)
+ *fn = i->path;
+
+ return 1;
}
int package_add_file(struct package *p, const char *name, const char *fn) {
diff --git a/src/package.h b/src/package.h
index 9279659..42486ad 100644
--- a/src/package.h
+++ b/src/package.h
@@ -33,7 +33,7 @@ struct package;
struct package* package_open(const char *fn, int force);
void package_remove(struct package *p);
int package_save(struct package *p, const char *fn);
-const char *package_get_item(struct package* p, const char *name, int c);
+int package_get_item(struct package* p, const char *name, int c, char const ** fn);
int package_add_file(struct package *p, const char *name, const char *fn);
int package_foreach(struct package *p, int (*cb) (struct package *p, const char *name, const char *path, void *u), void *u);
diff --git a/src/syrep.c b/src/syrep.c
index 724f08a..e65dc1c 100644
--- a/src/syrep.c
+++ b/src/syrep.c
@@ -473,9 +473,9 @@ static void free_args(void) {
static int help(const char *argv0) {
fprintf(stderr,
- "%s -- Synchronize Repositories\n\n"
+ "%s -- Synchronize File Repositories\n\n"
- "Usage: %s [options] <command> [argument...]\n\n"
+ "Usage: %s [options...] <command> [arguments...]\n\n"
"General options:\n"
" -v --verbose Enable verbose operation\n"
diff --git a/src/util.c b/src/util.c
index 18f8fa4..ffc5dc3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -18,8 +18,6 @@
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***/
-#define USE_SENDFILE
-
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
@@ -230,15 +228,20 @@ int copy_fd(int sfd, int dfd, off_t l) {
static size_t psize = 0;
#ifdef USE_SENDFILE
- if (!copy_fd_sendfile(sfd, dfd, l))
+ if (copy_fd_sendfile(sfd, dfd, l) == 0)
return 0;
+
+ if (errno == ENOSPC)
+ return -1;
#endif
//fprintf(stderr, "copy_fd(%u)\n", l);
if (psize == 0)
- psize = sysconf(_SC_PAGESIZE);
+ psize = (off_t) sysconf(_SC_PAGESIZE);
+ assert(psize > 0);
+
sp = dp = MAP_FAILED;
if (l > BUFSIZE) {
@@ -346,10 +349,8 @@ int copy_fd(int sfd, int dfd, off_t l) {
fprintf(stderr, "mmap(): %s\n", strerror(errno));
return -1;
}
-
}
-
} else if (dp == MAP_FAILED) { /* copy mmap to fd */
for (;;) {
@@ -386,7 +387,6 @@ int copy_fd(int sfd, int dfd, off_t l) {
}
}
-
} else { /* copy mmap to mmap */
for (;;) {
@@ -421,6 +421,7 @@ int copy_fd(int sfd, int dfd, off_t l) {
mdfo = (dfo/psize)*psize;
dm = m+(dfo-mdfo);
if ((dp = mmap(NULL, dm, PROT_READ|PROT_WRITE, MAP_SHARED, dfd, mdfo)) == MAP_FAILED) {
+ munmap(sp, sm);
fprintf(stderr, "mmap(): %s\n", strerror(errno));
return -1;
}
@@ -640,7 +641,6 @@ int question(const char *text, const char *replies) {
}
}
-
finish:
fputc('\r', stderr);
@@ -649,7 +649,6 @@ finish:
fclose(f);
return r;
-
}