mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
gpg: Let --fetch-key return an exit code on failure.
* g10/keyserver.c (keyserver_fetch): Return an error code. * g10/gpg.c (main) <aFetchKeys>: Return 1 in case of no data. -- GnuPG-bug-id: 5376
This commit is contained in:
parent
b90c55fa66
commit
5fe4b97887
@ -4699,12 +4699,14 @@ main (int argc, char **argv)
|
||||
for( ; argc; argc--, argv++ )
|
||||
append_to_strlist2( &sl, *argv, utf8_strings );
|
||||
rc = keyserver_fetch (ctrl, sl, opt.key_origin);
|
||||
free_strlist (sl);
|
||||
if(rc)
|
||||
{
|
||||
write_status_failure ("fetch-keys", rc);
|
||||
log_error ("key fetch failed: %s\n",gpg_strerror (rc));
|
||||
if (gpg_err_code (rc) == GPG_ERR_NO_DATA)
|
||||
g10_exit (1); /* In this case return 1 and not 2. */
|
||||
}
|
||||
free_strlist(sl);
|
||||
break;
|
||||
|
||||
case aExportSecret:
|
||||
|
@ -1667,6 +1667,8 @@ keyserver_fetch (ctrl_t ctrl, strlist_t urilist, int origin)
|
||||
strlist_t sl;
|
||||
estream_t datastream;
|
||||
unsigned int save_options = opt.keyserver_options.import_options;
|
||||
int any_success = 0;
|
||||
gpg_error_t firsterr = 0;
|
||||
|
||||
/* Switch on fast-import, since fetch can handle more than one
|
||||
import and we don't want each set to rebuild the trustdb.
|
||||
@ -1690,13 +1692,25 @@ keyserver_fetch (ctrl_t ctrl, strlist_t urilist, int origin)
|
||||
|
||||
import_print_stats (stats_handle);
|
||||
import_release_stats_handle (stats_handle);
|
||||
any_success = 1;
|
||||
}
|
||||
else
|
||||
log_info (_("WARNING: unable to fetch URI %s: %s\n"),
|
||||
sl->d, gpg_strerror (err));
|
||||
{
|
||||
log_info (_("WARNING: unable to fetch URI %s: %s\n"),
|
||||
sl->d, gpg_strerror (err));
|
||||
if (!firsterr)
|
||||
firsterr = err;
|
||||
}
|
||||
es_fclose (datastream);
|
||||
}
|
||||
|
||||
if (!urilist)
|
||||
err = gpg_error (GPG_ERR_NO_NAME);
|
||||
else if (any_success)
|
||||
err = 0;
|
||||
else
|
||||
err = firsterr;
|
||||
|
||||
opt.keyserver_options.import_options = save_options;
|
||||
|
||||
/* If the original options didn't have fast import, and the trustdb
|
||||
@ -1704,7 +1718,7 @@ keyserver_fetch (ctrl_t ctrl, strlist_t urilist, int origin)
|
||||
if (!(opt.keyserver_options.import_options&IMPORT_FAST))
|
||||
check_or_update_trustdb (ctrl);
|
||||
|
||||
return 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user