mirror of
https://github.com/mirror/wget.git
synced 2025-03-14 20:00:15 +08:00
Generate random temp file names.
This commit is contained in:
parent
e37ea16957
commit
2807c5c56d
@ -11,12 +11,10 @@
|
||||
#include "url.h"
|
||||
|
||||
int
|
||||
spawn_thread (struct s_thread_ctx *thread_ctx, char * name, int index, int resource)
|
||||
spawn_thread (struct s_thread_ctx *thread_ctx, int index, int resource)
|
||||
{
|
||||
static pthread_t thread;
|
||||
|
||||
sprintf(thread_ctx[index].file, TEMP_PREFIX "%s.%d", name, index);
|
||||
|
||||
thread_ctx[index].url_parsed = url_parse (thread_ctx[index].url,
|
||||
&(thread_ctx[index].url_err), thread_ctx[index].i, true);
|
||||
if(!thread_ctx[index].url_parsed)
|
||||
@ -63,7 +61,7 @@ segmented_retrieve_url (void *arg)
|
||||
}
|
||||
|
||||
void
|
||||
merge_temp_files(const char **inputs, const char *output, int numfiles)
|
||||
merge_temp_files(char **inputs, const char *output, int numfiles)
|
||||
{
|
||||
FILE *out, *in;
|
||||
int j, ret;
|
||||
@ -86,7 +84,7 @@ merge_temp_files(const char **inputs, const char *output, int numfiles)
|
||||
}
|
||||
|
||||
void
|
||||
delete_temp_files(const char **files, int numfiles)
|
||||
delete_temp_files(char **files, int numfiles)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
|
@ -38,8 +38,6 @@ as that of the covered work. */
|
||||
#include "iri.h"
|
||||
#include "url.h"
|
||||
|
||||
#define TEMP_PREFIX "temp_"
|
||||
|
||||
#define MIN_CHUNK_SIZE 2048
|
||||
|
||||
struct s_thread_ctx
|
||||
@ -58,14 +56,14 @@ struct s_thread_ctx
|
||||
uerr_t status;
|
||||
};
|
||||
|
||||
int spawn_thread (struct s_thread_ctx*, char *, int, int);
|
||||
int spawn_thread (struct s_thread_ctx*, int, int);
|
||||
|
||||
int collect_thread (sem_t *, struct s_thread_ctx *);
|
||||
|
||||
static void * segmented_retrieve_url (void *);
|
||||
|
||||
void merge_temp_files(const char **, const char *, int);
|
||||
void merge_temp_files(char **, const char *, int);
|
||||
|
||||
void delete_temp_files(const char **, int);
|
||||
void delete_temp_files(char **, int);
|
||||
|
||||
#endif /* MULTI_H */
|
||||
|
31
src/retr.c
31
src/retr.c
@ -1017,7 +1017,7 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
if(opt.metalink_file)
|
||||
{
|
||||
/*GSoC wget*/
|
||||
char *file_name, **files;
|
||||
char *temp, **files;
|
||||
FILE *file1, *file2;
|
||||
int i, j, r, index, dt, url_err, retries;
|
||||
int ret, N_THREADS = opt.jobs > 0 ? opt.jobs : 1;
|
||||
@ -1069,12 +1069,15 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
|
||||
/* Assign temporary file names. */
|
||||
for (j = 0; j < N_THREADS; ++j)
|
||||
files[j] = malloc(strlen("temp_") + strlen(file->name)
|
||||
+ (sizeof ".")-1 + (N_THREADS/10 + 1) + sizeof "");
|
||||
|
||||
/* To make sure temporary files in which the segments are downloaded
|
||||
do not become corrupt, as wget appends while writing into files. */
|
||||
delete_temp_files(files, N_THREADS);
|
||||
{
|
||||
files[j] = malloc(L_tmpnam * sizeof(char));
|
||||
temp = tmpnam(files[j]);
|
||||
if(!temp)
|
||||
{
|
||||
logprintf (LOG_VERBOSE, "Temp file name could not be assigned.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
sem_init (&retr_sem, 0, 0);
|
||||
j = ranges_covered = 0;
|
||||
@ -1097,7 +1100,7 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
thread_ctx[r].url = resource->url;
|
||||
thread_ctx[r].retr_sem = &retr_sem;
|
||||
|
||||
ret = spawn_thread (thread_ctx, file->name, r, j);
|
||||
ret = spawn_thread (thread_ctx, r, j);
|
||||
if (ret)
|
||||
{
|
||||
char *error = url_error (thread_ctx[r].url, thread_ctx[r].url_err);
|
||||
@ -1155,7 +1158,7 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
(thread_ctx[r].range)->bytes_covered = 0;
|
||||
}
|
||||
--ranges_covered;
|
||||
ret = spawn_thread (thread_ctx, file->name, r, j);
|
||||
ret = spawn_thread (thread_ctx, r, j);
|
||||
if (ret)
|
||||
{
|
||||
char *error = url_error (thread_ctx[r].url, thread_ctx[r].url_err);
|
||||
@ -1180,7 +1183,7 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
|
||||
if (status != RETROK)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, "Downloading %s failed. Chunk %d could not be downloaded from any of the URLs listed in metalink file.\n", file->name, r);
|
||||
logprintf (LOG_VERBOSE, "Downloading %s failed. Chunk %d could not be downloaded from any of the URLs listed in metalink file.\n", file->name, r);
|
||||
|
||||
/* Unlike downloads with invalid hash values, failed download
|
||||
should only be retried if the error causing failure is not
|
||||
@ -1190,7 +1193,7 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
if(retries < opt.n_retries)
|
||||
{
|
||||
--i;
|
||||
logprintf (LOG_NOTQUIET, "Retrying to download(%s). (TRY #%d)\n",
|
||||
logprintf (LOG_VERBOSE, "Retrying to download(%s). (TRY #%d)\n",
|
||||
file->name, ++retries + 1);
|
||||
}
|
||||
}
|
||||
@ -1204,16 +1207,16 @@ retrieve_from_file (const char *file, bool html, int *count)
|
||||
if(!res)
|
||||
{
|
||||
++*count;
|
||||
logprintf (LOG_NOTQUIET, "Verifying(%s) succeeded.\n",
|
||||
logprintf (LOG_VERBOSE, "Verifying(%s) succeeded.\n",
|
||||
file->name);
|
||||
}
|
||||
else if(res < 0)
|
||||
{
|
||||
logprintf (LOG_NOTQUIET, "Verifying(%s) failed.\n", file->name);
|
||||
logprintf (LOG_VERBOSE, "Verifying(%s) failed.\n", file->name);
|
||||
if(retries < opt.n_retries)
|
||||
{
|
||||
--i;
|
||||
logprintf (LOG_NOTQUIET, "Retrying to download(%s). (TRY #%d)\n", file->name, ++retries + 1);
|
||||
logprintf (LOG_VERBOSE, "Retrying to download(%s). (TRY #%d)\n", file->name, ++retries + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user