[OE-core] [PATCH 2/2] cve-check-tool: report progress when downloading CVE database

2016-09-26 Thread André Draszik
We add a patch to report the progress, and at the same time
inform bitbake that progress can be extracted via the simple
'percent' progress handler.

Signed-off-by: André Draszik 
---
 .../cve-check-tool/cve-check-tool_5.6.4.bb |   2 +
 ...ogress-in-percent-when-downloading-CVE-db.patch | 132 +
 2 files changed, 134 insertions(+)
 create mode 100644 
meta/recipes-devtools/cve-check-tool/files/0001-print-progress-in-percent-when-downloading-CVE-db.patch

diff --git a/meta/recipes-devtools/cve-check-tool/cve-check-tool_5.6.4.bb 
b/meta/recipes-devtools/cve-check-tool/cve-check-tool_5.6.4.bb
index 5bb22d1..1baadea 100644
--- a/meta/recipes-devtools/cve-check-tool/cve-check-tool_5.6.4.bb
+++ b/meta/recipes-devtools/cve-check-tool/cve-check-tool_5.6.4.bb
@@ -8,6 +8,7 @@ LIC_FILES_CHKSUM = 
"file://LICENSE;md5=e8c1458438ead3c34974bc0be3a03ed6"
 
 SRC_URI = 
"https://github.com/ikeydoherty/${BPN}/releases/download/v${PV}/${BP}.tar.xz \
file://check-for-malloc_trim-before-using-it.patch \
+   file://0001-print-progress-in-percent-when-downloading-CVE-db.patch 
\
   "
 
 SRC_URI[md5sum] = "c5f4247140fc9be3bf41491d31a34155"
@@ -48,5 +49,6 @@ do_populate_cve_db() {
 
 addtask populate_cve_db after do_populate_sysroot
 do_populate_cve_db[nostamp] = "1"
+do_populate_cve_db[progress] = "percent"
 
 BBCLASSEXTEND = "native nativesdk"
diff --git 
a/meta/recipes-devtools/cve-check-tool/files/0001-print-progress-in-percent-when-downloading-CVE-db.patch
 
b/meta/recipes-devtools/cve-check-tool/files/0001-print-progress-in-percent-when-downloading-CVE-db.patch
new file mode 100644
index 000..ac85962
--- /dev/null
+++ 
b/meta/recipes-devtools/cve-check-tool/files/0001-print-progress-in-percent-when-downloading-CVE-db.patch
@@ -0,0 +1,132 @@
+From 9dc7e787295801aaecfa744b222d58df6b1f48c2 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Andr=C3=A9=20Draszik?= 
+Date: Mon, 26 Sep 2016 12:12:41 +0100
+Subject: [PATCH] print progress in percent when downloading CVE db
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Upstream-Status: Pending
+Signed-off-by: André Draszik 
+---
+ src/library/fetch.c | 27 ++-
+ src/library/fetch.h |  2 +-
+ src/update.c| 15 +++
+ 3 files changed, 38 insertions(+), 6 deletions(-)
+
+diff --git a/src/library/fetch.c b/src/library/fetch.c
+index 06d4b30..cce8e8f 100644
+--- a/src/library/fetch.c
 b/src/library/fetch.c
+@@ -37,13 +37,36 @@ static size_t write_func(void *ptr, size_t size, size_t 
nmemb, struct fetch_t *f
+ return fwrite(ptr, size, nmemb, f->f);
+ }
+ 
+-FetchStatus fetch_uri(const char *uri, const char *target, bool verbose)
++struct percent_t {
++unsigned long start;
++unsigned long end;
++};
++
++static int progress_callback_new(void *ptr, curl_off_t dltotal, curl_off_t 
dlnow, curl_off_t ultotal, curl_off_t ulnow)
++{
++(void) ultotal;
++(void) ulnow;
++
++struct percent_t *percent = (struct percent_t *) ptr;
++
++if (dltotal && percent) {
++long diff = percent->end - percent->start;
++if (diff) {
++fprintf(stderr,"completed: %lu%%\r", percent->start + 
(diff * dlnow / dltotal));
++}
++}
++
++return 0;
++}
++
++FetchStatus fetch_uri(const char *uri, const char *target, bool verbose, 
unsigned long start_percent, unsigned long end_percent)
+ {
+ FetchStatus ret = FETCH_STATUS_FAIL;
+ CURLcode res;
+ struct stat st;
+ CURL *curl = NULL;
+ struct fetch_t *f = NULL;
++struct percent_t percent = { .start = start_percent, .end = 
end_percent };
+ 
+ curl = curl_easy_init();
+ if (!curl) {
+@@ -67,6 +90,8 @@ FetchStatus fetch_uri(const char *uri, const char *target, 
bool verbose)
+ }
+ if (verbose) {
+ (void)curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
++(void)curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &percent);
++(void)curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, 
progress_callback_new);
+ }
+ res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, 
(curl_write_callback)write_func);
+ if (res != CURLE_OK) {
+diff --git a/src/library/fetch.h b/src/library/fetch.h
+index 70c3779..70aecb7 100644
+--- a/src/library/fetch.h
 b/src/library/fetch.h
+@@ -28,7 +28,7 @@ typedef enum {
+  * @param verbose Whether to be verbose
+  * @return A FetchStatus, indicating the operation taken
+  */
+-FetchStatus fetch_uri(const char *uri, const char *target, bool verbose);
++FetchStatus fetch_uri(const char *uri, const char *target, bool verbose, 
unsigned long this_percent, unsigned long next_percent);
+ 
+ /**
+  * Attempt to extract the given gzipped file
+diff --git a/src/update.c b/src/update.c
+index 30fbe96..cd04512 100644
+--- a/src/update.c
 b/src/upda

Re: [OE-core] [PATCH 2/2] cve-check-tool: report progress when downloading CVE database

2016-09-28 Thread Burton, Ross
On 26 September 2016 at 16:42, André Draszik  wrote:

> ++static int progress_callback_new(void *ptr, curl_off_t dltotal,
> curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
> ++{
> ++(void) ultotal;
> ++(void) ulnow;
> ++
> ++struct percent_t *percent = (struct percent_t *) ptr;
> ++
> ++if (dltotal && percent) {
> ++long diff = percent->end - percent->start;
> ++if (diff) {
> ++fprintf(stderr,"completed: %lu%%\r",
> percent->start + (diff * dlnow / dltotal));
> ++}
> ++}
> ++
> ++return 0;
> ++}
>

This fails on the autobuilder cluster:

| ../../cve-check-tool-5.6.4/src/library/fetch.c: In function
'progress_callback_new':
| ../../cve-check-tool-5.6.4/src/library/fetch.c:55:54: error: format '%lu'
expects argument of type 'long unsigned int', but argument 3 has type
'curl_off_t {aka long long int}' [-Werror=format=]
|  fprintf(stderr,"completed: %lu%%\r",
percent->start + (diff * dlnow / dltotal));
|   ^

Ross
-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


Re: [OE-core] [PATCH 2/2] cve-check-tool: report progress when downloading CVE database

2016-09-28 Thread André Draszik
Ups, sorry for that... :-(

Should I send a patch against master-next, or against master?

a.

On Mi, 2016-09-28 at 11:54 +0100, Burton, Ross wrote:
> On 26 September 2016 at 16:42, André Draszik  wrote:
> 
> > 
> > ++static int progress_callback_new(void *ptr, curl_off_t dltotal,
> > curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
> > ++{
> > ++(void) ultotal;
> > ++(void) ulnow;
> > ++
> > ++struct percent_t *percent = (struct percent_t *) ptr;
> > ++
> > ++if (dltotal && percent) {
> > ++long diff = percent->end - percent->start;
> > ++if (diff) {
> > ++fprintf(stderr,"completed: %lu%%\r",
> > percent->start + (diff * dlnow / dltotal));
> > ++}
> > ++}
> > ++
> > ++return 0;
> > ++}
> > 
> 
> This fails on the autobuilder cluster:
> 
> > 
> > ../../cve-check-tool-5.6.4/src/library/fetch.c: In function
> 'progress_callback_new':
> > 
> > ../../cve-check-tool-5.6.4/src/library/fetch.c:55:54: error: format
> > '%lu'
> expects argument of type 'long unsigned int', but argument 3 has type
> 'curl_off_t {aka long long int}' [-Werror=format=]
> > 
> >  fprintf(stderr,"completed: %lu%%\r",
> percent->start + (diff * dlnow / dltotal));
> > 
> >   ^
> 
> Ross
-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


Re: [OE-core] [PATCH 2/2] cve-check-tool: report progress when downloading CVE database

2016-09-28 Thread Burton, Ross
On 28 September 2016 at 12:56, André Draszik  wrote:

> Ups, sorry for that... :-(
>
> Should I send a patch against master-next, or against master?
>

Happens to the best of us :)   Edit your patch and resend it against master.

Ross
-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core