Let qemubuilder cache downloaded debs.
Junichi Uekawa
dancer at netfort.gr.jp
Mon Nov 19 09:29:55 UTC 2012
At Tue, 16 Oct 2012 13:17:08 +0200,
Werner Mahr wrote:
>
> commit 272927a92e751505c6b94d3ecd464eddde7ce1d3
> Author: Vollstrecker <amule at vollstreckernet.de>
> Date: Tue Oct 16 13:13:03 2012 +0200
>
> Added usage of apt-cache and fixed buildplace getting //
>
> diff --git a/parameter.c b/parameter.c
> index d38f953..b621d54 100644
> --- a/parameter.c
> +++ b/parameter.c
> @@ -169,6 +169,10 @@ int load_config_file(const char* config, pbuilderconfig* pc)
> {
> pc->http_proxy=strdup(delim);
> }
> + else if (!strcmp(buf, "APTCACHE"))
> + {
> + pc->apt_cache=strdup(delim);
> + }
> }
> }
>
> @@ -216,6 +220,7 @@ int cpbuilder_dumpconfig(pbuilderconfig* pc)
> DUMPSTR(debbuildopts);
> DUMPINT(binary_arch);
> DUMPSTR(http_proxy);
> + DUMPSTR(apt_cache);
> DUMPSTRARRAY(inputfile);
> DUMPSTRARRAY(outputfile);
>
> @@ -271,6 +276,7 @@ int parse_parameter(int ac, char** av,
> {"outputfile", required_argument, 0, 0},
> {"architecture", required_argument, 0, 0},
> {"http-proxy", required_argument, 0, 0},
> + {"aptcache", required_argument, 0, 0},
>
> /* cowbuilder specific options */
> {"no-cowdancer-update", no_argument, 0, 0},
> @@ -487,6 +493,14 @@ int parse_parameter(int ac, char** av,
> /* pass it for cowbuilder */
> PASS_TO_PBUILDER_WITH_PARAM
> }
> + else if (!strcmp(long_options[index_point].name,"aptcache"))
> + {
> + /* this is for qemubuilder */
> + pc.apt_cache=strdup(optarg);
> +
> + /* pass it for cowbuilder */
> + PASS_TO_PBUILDER_WITH_PARAM
> + }
> else if (!strcmp(long_options[index_point].name,"debbuildopts"))
> {
> /* this is for qemubuilder */
> @@ -528,10 +542,20 @@ int parse_parameter(int ac, char** av,
> else
> {
> char* buildplace_ = pc.buildplace;
> + char* last_char;
> mkdir(buildplace_,0777); /* create if it does not exist */
> /* Bug: 573126 This adds '//' if buildplace already ends with / */
> - asprintf(&(pc.buildplace), "%s/%s.%i",
> + asprintf(&last_char, "%c", buildplace_[strlen(buildplace_)-1]);
why are you doing a strdup here? last_char isn't freed anywhere.
if (buildplace_[strlen(buildplace_)-1] == '/')
would be more reasonable, no?
something like:
asprintf(&(pc.buildplace), "%s%s%s.%i",
buildplace_,
(buildplace_[strlen(buildplace_)-1] == '/')?"/":""
keyword, (int)getpid());
is probably better but I don't know if it's worth the change.
> + if (!strcmp(last_char, "/"))
> + {
> + asprintf(&(pc.buildplace), "%s%s.%i",
> + buildplace_, keyword, (int)getpid());
> + }
> + else
> + {
> + asprintf(&(pc.buildplace), "%s/%s.%i",
> buildplace_, keyword, (int)getpid());
> + }
> free(buildplace_);
> }
>
> diff --git a/parameter.h b/parameter.h
> index bc72b3a..a64749e 100644
> --- a/parameter.h
> +++ b/parameter.h
> @@ -41,6 +41,7 @@ typedef struct pbuilderconfig
> char* debbuildopts;
> int binary_arch;
> char* http_proxy;
> + char* apt_cache;
>
> /* files to be copied into the chroot,
> and copied out of the chroot */
> diff --git a/qemubuilder.c b/qemubuilder.c
> index b3a40a4..e2ef1dc 100755
> --- a/qemubuilder.c
> +++ b/qemubuilder.c
> @@ -407,6 +407,8 @@ static int run_second_stage_script
> char* workblockdevicepath=NULL;
> char* cowdevpath=NULL;
> char* timestring;
> + char* obtaincache;
> + char* savecache;
> int ret=1;
> FILE* f;
> int i;
> @@ -479,7 +481,10 @@ static int run_second_stage_script
>
> /* do I not need to copy /etc/pbuilderrc, and ~/.pbuilderrc to inside chroot? */
> /* TODO: hooks probably need copying here. */
> - /* TODO: recover aptcache */
> +
> + printf("Obtaining the cached apt archive contents\n");
> + asprintf(&obtaincache, "cp -ar %s %s/aptcache/", pc->apt_cache, pc->buildplace);
> + system(obtaincache);
>
> if(hostcommand1)
> {
> @@ -515,6 +520,10 @@ static int run_second_stage_script
> /* after-run */
> loop_mount(workblockdevicepath, pc->buildplace);
> printf(" -> running post-run process\n");
> + printf("Copying back the cached apt archive contents\n");
> + mkdir(pc->apt_cache,0777);
> + asprintf(&savecache, "cp -a %s/aptcache/*.deb %s", pc->buildplace, pc->apt_cache);
> + system(savecache);
where do you free savecache?
> if(hostcommand2)
> {
> printf("running host command: %s\n", hostcommand2);
> @@ -840,7 +849,9 @@ int cpbuilder_build(const struct pbuilderconfig* pc, const char* dscfile)
>
> asprintf(&commandline,
> /* TODO: executehooks D: */
> + "cp -a $PBUILDER_MOUNTPOINT/aptcache/* /var/cache/apt/archives/\n"
> "/usr/lib/pbuilder/pbuilder-satisfydepends --control $PBUILDER_MOUNTPOINT/*.dsc --internal-chrootexec 'chroot . ' %s \n"
> + "cp -a /var/cache/apt/archives/* $PBUILDER_MOUNTPOINT/aptcache/\n"
> "cd $PBUILDER_MOUNTPOINT; /usr/bin/dpkg-source -x $(basename %s) \n"
> "echo ' -> Building the package'\n"
> /* TODO: executehooks A: */
>
More information about the Pbuilder-maint
mailing list