Change --metalink-file to --metalink. Support --quota w/ --metalink. Correct clean_range_res_data(). Add interoption availability checks for --metalink.

This commit is contained in:
Ilim Ugur 2012-08-17 22:53:47 +03:00
parent 87a2b8dcb6
commit ed8335aa76
4 changed files with 51 additions and 22 deletions

View File

@ -235,7 +235,7 @@ static struct cmdline_option option_data[] =
{ "local-encoding", 0, OPT_VALUE, "localencoding", -1 },
{ "max-redirect", 0, OPT_VALUE, "maxredirect", -1 },
#ifdef ENABLE_METALINK
{ "metalink-file", 0, OPT_VALUE, "metalink", -1 },
{ "metalink", 0, OPT_VALUE, "metalink", -1 },
#endif
{ "mirror", 'm', OPT_BOOLEAN, "mirror", -1 },
{ "no", 'n', OPT__NO, NULL, required_argument },
@ -1509,23 +1509,47 @@ outputting to a regular file.\n"));
}
#ifdef ENABLE_METALINK
/* TODO: Add all the options that causes undefined/harmful results when used
with option --metalink-file. */
if(opt.metalink_file)
{
if(opt.output_document)
/* --protocol-directories is the longest option among the ones checked below. */
char *temp_option = malloc(strlen("--protocol-directories"));
if(opt.user || opt.passwd || opt.http_user || opt.http_passwd ||
opt.ftp_user || opt.ftp_passwd || opt.ask_passwd)
{
fprintf (stderr, _("-O can not used with --metalink-file.\n"));
fprintf (stderr, _("Username and password information not needed to \
be specified when downloading from a metalink.\n"));
exit(1);
}
if(opt.base_href)
temp_option[0] = '\0';
if(opt.input_filename)
sprintf(temp_option, "-i");
else if(opt.output_document)
sprintf(temp_option, "-O");
else if(opt.base_href)
sprintf(temp_option, "--base");
else if(opt.force_html)
sprintf(temp_option, "--force-html");
else if(opt.always_rest)
sprintf(temp_option, "-c");
else if(opt.spider)
sprintf(temp_option, "-spider");
else if(opt.cut_dirs)
sprintf(temp_option, "--cut-dirs");
else if(opt.wait)
sprintf(temp_option, "-w");
else if(opt.waitretry != 10)
sprintf(temp_option, "--waitretry");
else if(opt.timestamping)
sprintf(temp_option, "--timestamping");
else if(opt.protocol_directories)
sprintf(temp_option, "--protocol-directories");
else if(opt.dirstruct)
sprintf(temp_option, "--force-directories");
if(temp_option[0])
{
fprintf (stderr, _("--base can not used with --metalink-file.\n"));
exit(1);
}
if(opt.force_html)
{
fprintf (stderr, _("--force-html can not used with --metalink-file.\n"));
fprintf (stderr, _("%s can not be used with --metalink.\n"), temp_option);
free(temp_option);
exit(1);
}
}

View File

@ -79,7 +79,7 @@ name_temp_files()
/* Merge the temporary files in which the chunks are stored to form the
resulting file(output). */
void
merge_temp_files(const char *output)
merge_temp_files(char *output)
{
FILE *out, *in;
int j, ret;
@ -161,10 +161,10 @@ fill_ranges_data(int num_of_resources, long long int file_size,
/* Free the resources array of each range allocated by fill_ranges_data(). */
void
clean_range_res_data(int num_of_resources)
clean_range_res_data()
{
int i;
for (i = 0; i < num_of_resources; ++i)
for (i = 0; i < opt.jobs; ++i)
free (ranges[i].resources);
}

View File

@ -60,7 +60,7 @@ void init_temp_files();
void name_temp_files();
void merge_temp_files(const char *);
void merge_temp_files(char *);
void delete_temp_files();
@ -70,7 +70,7 @@ void init_ranges();
int fill_ranges_data(int, long long int, long int);
void clean_range_res_data(int);
void clean_range_res_data();
void clean_ranges();

View File

@ -1067,8 +1067,8 @@ retrieve_from_file (const char *file, bool html, int *count)
if(opt.metalink_file && (metalink = metalink_context(input_file)))
{
int i, j, r, dt, url_err, retries;
int ret;
int i, j, r, url_err, retries;
int ret, dt = 0;
int ranges_covered, chunk_size, num_of_resources;
pthread_t thread;
sem_t retr_sem;
@ -1132,7 +1132,7 @@ retrieve_from_file (const char *file, bool html, int *count)
logprintf (LOG_NOTQUIET, "%s: %s.\n", thread_ctx[r].url, error);
xfree (error);
free(thread_ctx);
clean_range_res_data(num_of_resources);
clean_range_res_data();
clean_ranges ();
clean_temp_files ();
return URLERROR;
@ -1195,7 +1195,7 @@ retrieve_from_file (const char *file, bool html, int *count)
logprintf (LOG_NOTQUIET, "%s: %s.\n", thread_ctx[r].url, error);
xfree (error);
free(thread_ctx);
clean_range_res_data(num_of_resources);
clean_range_res_data();
clean_ranges ();
clean_temp_files ();
return URLERROR;
@ -1250,7 +1250,12 @@ retrieve_from_file (const char *file, bool html, int *count)
delete_temp_files();
clean_range_res_data(num_of_resources);
clean_range_res_data();
if (opt.quota && total_downloaded_bytes > opt.quota)
{
status = QUOTEXC;
break;
}
++i;
}