poldek: poldek/pkgdir/pkgdir.c, poldek/pkgdir/pkgdir.h, poldek/pkg...
mis
mis at pld-linux.org
Sun Jun 24 13:48:12 CEST 2007
Author: mis Date: Sun Jun 24 11:48:12 2007 GMT
Module: poldek Tag: HEAD
---- Log message:
- improved remote repository reset handling (#28)
---- Files affected:
poldek/poldek/pkgdir:
pkgdir.c (1.48 -> 1.49) , pkgdir.h (1.36 -> 1.37) , pkgdir_dirindex.c (1.11 -> 1.12)
poldek/poldek/pkgdir/pndir:
digest.c (1.6 -> 1.7) , pndir.h (1.14 -> 1.15) , save.c (1.31 -> 1.32) , update.c (1.21 -> 1.22)
---- Diffs:
================================================================
Index: poldek/poldek/pkgdir/pkgdir.c
diff -u poldek/poldek/pkgdir/pkgdir.c:1.48 poldek/poldek/pkgdir/pkgdir.c:1.49
--- poldek/poldek/pkgdir/pkgdir.c:1.48 Sat Jun 23 21:11:22 2007
+++ poldek/poldek/pkgdir/pkgdir.c Sun Jun 24 13:48:07 2007
@@ -322,7 +322,7 @@
} else if (!rc && uprc == PKGDIR_UPRC_ERR_DESYNCHRONIZED) {
if (pkgdir->src && (pkgdir->src->flags & PKGSOURCE_AUTOUPA)) {
- msgn(0, _("%s: update failed, trying to update whole index..."),
+ msgn(0, _("%s: desynchronized index, trying to update whole index..."),
pkgdir_idstr(pkgdir));
rc = pkgdir_update_a(pkgdir->src);
} else {
@@ -940,8 +940,8 @@
n_assert(nerr == 0);
- /* XXX pdir must be uniqued by NEVR (is not MULTILIB-able), if not, it will break
- backward compat with 0.18.x series. */
+ /* XXX pdir must be uniqued by NEVR (is not MULTILIB-able), it will break
+ backward compat with 0.18.x series otherwise */
if (n_str_eq(type, "pdir"))
pdir_pkgdir_uniq(pkgdir);
@@ -964,11 +964,14 @@
}
create = 1;
- if ((diff = pkgdir_diff(orig, pkgdir)))
+ if ((diff = pkgdir_diff(orig, pkgdir))) {
diff->ts = pkgdir->ts;
- else if ((flags & PKGDIR_CREAT_IFORIGCHANGED))
+ pkgdir->flags |= PKGDIR_DIFFED;
+
+ } else if ((flags & PKGDIR_CREAT_IFORIGCHANGED)) {
create = 0; /* no difference -> do not create */
-
+ }
+
if (create) { /* save index */
if (!do_create(pkgdir, type, path, flags))
================================================================
Index: poldek/poldek/pkgdir/pkgdir.h
diff -u poldek/poldek/pkgdir/pkgdir.h:1.36 poldek/poldek/pkgdir/pkgdir.h:1.37
--- poldek/poldek/pkgdir/pkgdir.h:1.36 Fri Jun 22 00:28:35 2007
+++ poldek/poldek/pkgdir/pkgdir.h Sun Jun 24 13:48:07 2007
@@ -17,6 +17,7 @@
#define PKGDIR_PATCHED (1 << 4) /* patched */
#define PKGDIR_UNIQED (1 << 5) /* passed through pkgdir_uniq() */
#define PKGDIR_CHANGED (1 << 6) /* added/removed packages */
+#define PKGDIR_DIFFED (1 << 7) /* */
#define PKGDIR_VRFY_GPG (1 << 10) /* verify package GPG signatures */
#define PKGDIR_VRFY_PGP (1 << 11) /* verify package PGP signatures */
================================================================
Index: poldek/poldek/pkgdir/pkgdir_dirindex.c
diff -u poldek/poldek/pkgdir/pkgdir_dirindex.c:1.11 poldek/poldek/pkgdir/pkgdir_dirindex.c:1.12
--- poldek/poldek/pkgdir/pkgdir_dirindex.c:1.11 Sat Jun 23 02:34:49 2007
+++ poldek/poldek/pkgdir/pkgdir_dirindex.c Sun Jun 24 13:48:07 2007
@@ -433,7 +433,7 @@
if ((vlen = tndb_get(db, key, klen, val, *vsize)) == 0)
return NULL;
- n_assert(vlen < vsize);
+ n_assert(vlen < *vsize);
val[vlen] = '\0';
*vsize = vlen;
@@ -647,7 +647,7 @@
dirindex_path(path, sizeof(path), pkgdir);
mtime = poldek_util_mtime(path);
- n_assert(pkgdir->ts);
+ n_assert(pkgdir->ts > 0);
if (mtime == 0) /* not exists */
if (dirindex_create(pkgdir, path, NULL)) {
================================================================
Index: poldek/poldek/pkgdir/pndir/digest.c
diff -u poldek/poldek/pkgdir/pndir/digest.c:1.6 poldek/poldek/pkgdir/pndir/digest.c:1.7
--- poldek/poldek/pkgdir/pndir/digest.c:1.6 Sun May 15 17:51:19 2005
+++ poldek/poldek/pkgdir/pndir/digest.c Sun Jun 24 13:48:07 2007
@@ -42,8 +42,8 @@
#include "log.h"
#include "pndir.h"
-
const char *pndir_digest_ext = ".md";
+static const char *option_brandnew = "brand-new";
static int pndir_digest_read(struct pndir_digest *pdg, struct vfile *vfmd);
@@ -79,24 +79,6 @@
return pdg;
}
-
-int pndir_digest_fill(struct pndir_digest *pdg, char *mdbuf, int size)
-{
- int req_size;
-
- n_assert(*pdg->md == '\0');
-
- req_size = TNIDX_DIGEST_SIZE;
-
- if (size < req_size)
- return 0;
-
- memcpy(pdg->md, mdbuf, TNIDX_DIGEST_SIZE);
- pdg->md[TNIDX_DIGEST_SIZE] = '\0';
-
- return 1;
-}
-
void pndir_digest_init(struct pndir_digest *pdg)
{
memset(pdg, 0, sizeof(*pdg));
@@ -112,8 +94,6 @@
}
}
-
-
void pndir_digest_free(struct pndir_digest *pdg)
{
pndir_digest_destroy(pdg);
@@ -121,27 +101,53 @@
free(pdg);
}
+static int fill_digest(struct pndir_digest *pdg, char *mdbuf, int size)
+{
+ int req_size;
+
+ n_assert(*pdg->md == '\0');
+
+ req_size = TNIDX_DIGEST_SIZE;
+
+ if (size < req_size)
+ return 0;
+
+ memcpy(pdg->md, mdbuf, TNIDX_DIGEST_SIZE);
+ pdg->md[TNIDX_DIGEST_SIZE] = '\0';
+
+ return 1;
+}
+
int pndir_digest_readfd(struct pndir_digest *pdg, int fd, const char *path)
{
- char buf[TNIDX_DIGEST_SIZE];
- int md_size, req_size;
+ char buf[2 * TNIDX_DIGEST_SIZE]; /* +40bytes for params */
+ int nread, req_size;
if (lseek(fd, 0L, SEEK_SET) != 0) {
logn(LOGERR, "%s: lseek(0): %m", path);
return 0;
}
-
- md_size = read(fd, buf, sizeof(buf));
+ memset(buf, 0, sizeof(buf));
+ nread = read(fd, buf, sizeof(buf));
req_size = TNIDX_DIGEST_SIZE;
- if (md_size < req_size) {
- logn(LOGERR, _("%s: broken digest file (%d)"), path, md_size);
+ if (nread < req_size) {
+ logn(LOGERR, _("%s: broken digest file (%d)"), path, nread);
return 0;
}
+
+ if (!fill_digest(pdg, buf, nread))
+ return 0;
+
+ buf[nread] = '\0';
+ DBGF("read %s\n", buf);
- return pndir_digest_fill(pdg, buf, md_size);
+ if (strstr(&buf[TNIDX_DIGEST_SIZE], option_brandnew))
+ pdg->flags |= PNDIGEST_BRANDNEW;
+
+ return 1;
}
@@ -184,12 +190,16 @@
int pndir_digest_save(struct pndir_digest *pdg, const char *pathname,
- const char *srcnam)
+ const struct pkgdir *pkgdir)
{
char path[PATH_MAX];
struct vfile *vf;
- int n;
-
+ int n, brandnew = 0;
+
+ /* no patch was generated based on this pkgdir nor patch
+ applied to (client side) */
+ if ((pkgdir->flags & (PKGDIR_DIFFED | PKGDIR_PATCHED)) == 0)
+ brandnew = 1;
n = pndir_mkdigest_path(path, sizeof(path), pathname, pndir_digest_ext);
if (n <= 4) {
@@ -197,10 +207,14 @@
return 0;
}
- if ((vf = vfile_open_ul(path, VFT_STDIO, VFM_RW, srcnam)) == NULL)
+ if ((vf = vfile_open_ul(path, VFT_STDIO, VFM_RW, pkgdir->name)) == NULL)
return 0;
+ DBGF("brandnew %s %d\n", pkgdir_idstr(pkgdir), brandnew);
+
fprintf(vf->vf_stream, "%s", pdg->md);
+ if (brandnew)
+ fprintf(vf->vf_stream, " %s", option_brandnew);
vfile_close(vf);
return 1;
}
================================================================
Index: poldek/poldek/pkgdir/pndir/pndir.h
diff -u poldek/poldek/pkgdir/pndir/pndir.h:1.14 poldek/poldek/pkgdir/pndir/pndir.h:1.15
--- poldek/poldek/pkgdir/pndir/pndir.h:1.14 Thu Jun 21 18:47:45 2007
+++ poldek/poldek/pkgdir/pndir/pndir.h Sun Jun 24 13:48:07 2007
@@ -22,8 +22,11 @@
#define PNDIR_COMPRLEVEL 3
+#define PNDIGEST_BRANDNEW (1 << 0) /* no diffs for index */
struct pndir_digest {
struct vfile *vf;
+ unsigned flags;
+ char type[16]; /* sha1 so far */
char md[TNIDX_DIGEST_SIZE + 1];
};
@@ -64,15 +67,13 @@
void pndir_digest_init(struct pndir_digest *pdg);
void pndir_digest_destroy(struct pndir_digest *pdg);
-int pndir_digest_fill(struct pndir_digest *pdg, char *mdbuf, int size);
-
int pndir_digest_readfd(struct pndir_digest *pdg, int fd, const char *path);
//int pndir_digest_verify(struct pndir_digest *pdg, struct vfile *vf);
int pndir_digest_calc(struct pndir_digest *pdg, tn_array *keys);
int pndir_digest_calc_pkgs(struct pndir_digest *pdg, tn_array *pkgs);
int pndir_digest_save(struct pndir_digest *pdg, const char *pathname,
- const char *srcnam);
+ const struct pkgdir *pkgdir);
extern const char *pndir_packages_incdir;
extern const char *pndir_difftoc_suffix;
================================================================
Index: poldek/poldek/pkgdir/pndir/save.c
diff -u poldek/poldek/pkgdir/pndir/save.c:1.31 poldek/poldek/pkgdir/pndir/save.c:1.32
--- poldek/poldek/pkgdir/pndir/save.c:1.31 Sat Jun 23 21:08:40 2007
+++ poldek/poldek/pkgdir/pndir/save.c Sun Jun 24 13:48:07 2007
@@ -771,7 +771,7 @@
if (!pndir_digest_calc(&dg, keys))
nerr++;
- else if (!pndir_digest_save(&dg, paths.path, pkgdir->name))
+ else if (!pndir_digest_save(&dg, paths.path, pkgdir))
nerr++;
}
================================================================
Index: poldek/poldek/pkgdir/pndir/update.c
diff -u poldek/poldek/pkgdir/pndir/update.c:1.21 poldek/poldek/pkgdir/pndir/update.c:1.22
--- poldek/poldek/pkgdir/pndir/update.c:1.21 Wed Jun 20 10:25:32 2007
+++ poldek/poldek/pkgdir/pndir/update.c Sun Jun 24 13:48:07 2007
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2000 - 2005 Pawel A. Gajda <mis at k2.net.pl>
+ Copyright (C) 2000 - 2007 Pawel A. Gajda <mis at pld-linux.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2 as
@@ -58,65 +58,64 @@
}
+/*
+ fetch digest and compare it with local one
+ RET: 0 - outdated, 1 - up to date, -1 on error
+*/
static
int is_uptodate(const char *path, const struct pndir_digest *dg_local,
- struct pndir_digest *dg_remote, const char *pdir_name)
+ struct pndir_digest *dg, const char *pdir_name)
{
char mdpath[PATH_MAX], mdtmpath[PATH_MAX];
- struct pndir_digest remote_dg;
- int fd, n, rc = 0;
+ struct pndir_digest dg_remote;
+ int fd = 0, n, rc = 0;
const char *ext = pndir_digest_ext;
-
- if (dg_remote)
- pndir_digest_init(dg_remote);
+ if (dg) /* caller wants digest */
+ pndir_digest_init(dg);
- pndir_digest_init(&remote_dg);
+ pndir_digest_init(&dg_remote);
if (vf_url_type(path) & VFURL_LOCAL)
return 1;
-
- if (!(n = vf_mksubdir(mdtmpath, sizeof(mdtmpath), "tmpmd"))) {
- rc = -1;
- goto l_end;
- }
+ rc = -1;
+ if (!(n = vf_mksubdir(mdtmpath, sizeof(mdtmpath), "tmpmd")))
+ goto l_end;
+
pndir_mkdigest_path(mdpath, sizeof(mdpath), path, ext);
snprintf(&mdtmpath[n], sizeof(mdtmpath) - n, "/%s", n_basenam(mdpath));
unlink(mdtmpath);
mdtmpath[n] = '\0';
- if (!vf_fetch(mdpath, mdtmpath, 0, pdir_name)) {
- rc = -1;
+ if (!vf_fetch(mdpath, mdtmpath, 0, pdir_name))
goto l_end;
- }
mdtmpath[n] = '/';
-
- if ((fd = open(mdtmpath, O_RDONLY)) < 0 ||
- !pndir_digest_readfd(&remote_dg, fd, mdtmpath)) {
+ if ((fd = open(mdtmpath, O_RDONLY)) < 0)
+ goto l_end;
- close(fd);
- rc = -1;
+ if (!pndir_digest_readfd(&dg_remote, fd, mdtmpath))
goto l_end;
- }
- close(fd);
- rc = (memcmp(dg_local->md, &remote_dg.md, sizeof(remote_dg.md)) == 0);
+ close(fd);
+ fd = 0;
+
+ rc = (memcmp(dg_local->md, &dg_remote.md, sizeof(dg_remote.md)) == 0);
- if (!rc && dg_remote)
- memcpy(dg_remote, &remote_dg, sizeof(remote_dg));
+ if (rc == 0 && dg)
+ memcpy(dg, &dg_remote, sizeof(dg_remote));
l_end:
- pndir_digest_destroy(&remote_dg);
+ pndir_digest_destroy(&dg_remote);
+ if (fd > 0)
+ close(fd);
+
return rc;
}
-
-
-static
-int update_whole_idx(const struct source *src)
+static int update_whole_idx(const struct source *src)
{
struct pkgdir *pkgdir;
int rc = 0;
@@ -255,7 +254,11 @@
*uprc = PKGDIR_UPRC_ERR_UNKNOWN;
return 0;
- case 0:
+ case 0: /* diff updateable? */
+ if (dg_remote.flags & PNDIGEST_BRANDNEW) { /* nope */
+ *uprc = PKGDIR_UPRC_ERR_DESYNCHRONIZED;
+ return 0;
+ }
break;
default:
================================================================
---- CVS-web:
http://cvs.pld-linux.org/poldek/poldek/pkgdir/pkgdir.c?r1=1.48&r2=1.49&f=u
http://cvs.pld-linux.org/poldek/poldek/pkgdir/pkgdir.h?r1=1.36&r2=1.37&f=u
http://cvs.pld-linux.org/poldek/poldek/pkgdir/pkgdir_dirindex.c?r1=1.11&r2=1.12&f=u
http://cvs.pld-linux.org/poldek/poldek/pkgdir/pndir/digest.c?r1=1.6&r2=1.7&f=u
http://cvs.pld-linux.org/poldek/poldek/pkgdir/pndir/pndir.h?r1=1.14&r2=1.15&f=u
http://cvs.pld-linux.org/poldek/poldek/pkgdir/pndir/save.c?r1=1.31&r2=1.32&f=u
http://cvs.pld-linux.org/poldek/poldek/pkgdir/pndir/update.c?r1=1.21&r2=1.22&f=u
More information about the pld-cvs-commit
mailing list