package w3m tag 185006 patch thanks On Sun, Mar 16, 2003 at 01:24:00PM +0000, [EMAIL PROTECTED] wrote: > Package: w3m > Version: 0.3-2.4 > > If you try to download the target of a link (using the 'a' key) > and the disk you try to save it on is full, then w3m seems to > silently truncate the file (but it still downloads all the data > from the network anyway!). It should tell the user that the > download has failed, and stop transferring data if it can > (maybe it can't, don't know enough HTTP to be sure). > Here is a patch which solves the problem by: If there is a short write in save2tmp stop trying and return with a error code. In the main program examine the return code of child processes on SIGCHLD. If an error occured say so in the Download List Panel.
Regards, -- Karsten Schölzel | Email: [EMAIL PROTECTED] Väderleden 9 4:98 | Jabber: [EMAIL PROTECTED] 97633 Luleå | VoIP: sip:[EMAIL PROTECTED] Sweden | sip:[EMAIL PROTECTED] | Tel: +4918015855857712
If there is a short write in save2tmp stop trying and return with a error code. In the main program examine the return code of child processes on SIGCHLD. If an error occured say so in the Download List Panel. --- commit 98910a9b3becd2a69de8f81ca28299e3367de371 tree 26ffa4b3acdb2def605f40fbc4fade6cc9f8ac39 parent 23fc8c7f9cec2e5800c7ce4046b0a6e055619cfa author Karsten Schoelzel <[EMAIL PROTECTED]> Tue, 09 May 2006 22:29:25 +0200 committer Karsten Schoelzel <[EMAIL PROTECTED]> Tue, 09 May 2006 22:29:25 +0200 file.c | 14 ++++++++++++-- fm.h | 1 + main.c | 29 +++++++++++++++++++---------- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/file.c b/file.c index e531934..9b51be4 100644 --- a/file.c +++ b/file.c @@ -7552,7 +7552,13 @@ save2tmp(URLFile uf, char *tmpf) { Str buf = Strnew_size(SAVE_BUF_SIZE); while (UFread(&uf, buf, SAVE_BUF_SIZE)) { - Strfputs(buf, ff); + if (Strfputs(buf, ff) != buf->length) { + bcopy(env_bak, AbortLoading, sizeof(JMP_BUF)); + TRAP_OFF; + fclose(ff); + current_content_length = 0; + return -2; + } linelen += buf->length; showProgress(&linelen, &trbyte); } @@ -7878,16 +7884,20 @@ doFileSave(URLFile uf, char *defstr) flush_tty(); pid = fork(); if (!pid) { + int err; if (uf.content_encoding != CMP_NOCOMPRESS) { uncompress_stream(&uf, &tmpf); if (tmpf) unlink(tmpf); } setup_child(FALSE, 0, UFfileno(&uf)); - if (!save2tmp(uf, p) && PreserveTimestamp && uf.modtime != -1) + err = save2tmp(uf, p); + if (err == 0 && PreserveTimestamp && uf.modtime != -1) setModtime(p, uf.modtime); UFclose(&uf); unlink(lock); + if (err != 0) + exit(1); exit(0); } addDownloadList(pid, uf.url, p, lock, current_content_length); diff --git a/fm.h b/fm.h index 8b8244b..1e35252 100644 --- a/fm.h +++ b/fm.h @@ -508,6 +508,7 @@ typedef struct _DownloadList { clen_t size; time_t time; int ok; + int err; struct _DownloadList *next; struct _DownloadList *prev; } DownloadList; diff --git a/main.c b/main.c index 98d783e..c7a776e 100644 --- a/main.c +++ b/main.c @@ -312,21 +312,26 @@ static void sig_chld(int signo) { int p_stat; -#ifdef HAVE_WAITPID pid_t pid; +#ifdef HAVE_WAITPID while ((pid = waitpid(-1, &p_stat, WNOHANG)) > 0) { - ; - } #elif HAVE_WAIT3 - int pid; - while ((pid = wait3(&p_stat, WNOHANG, NULL)) > 0) { - ; - } #else - wait(&p_stat); + if ((pid = wait(&p_stat)) > 0) { #endif + DownloadList *d; + + if (WIFEXITED(p_stat)) { + for (d = FirstDL; d != NULL; d = d->next) { + if (d->pid == pid) { + d->err = WEXITSTATUS(p_stat); + break; + } + } + } + } mySignal(SIGCHLD, sig_chld); return; } @@ -6293,6 +6298,7 @@ addDownloadList(pid_t pid, char *url, ch d->size = size; d->time = time(0); d->ok = FALSE; + d->err = 0; d->next = NULL; d->prev = LastDL; if (LastDL) @@ -6360,7 +6366,8 @@ DownloadListBuffer(void) if (!stat(d->save, &st)) { size = st.st_size; if (d->ok) { - d->size = size; + if (!d->err) + d->size = size; duration = st.st_mtime - d->time; } } @@ -6400,7 +6407,9 @@ DownloadListBuffer(void) if (d->ok) { Strcat(src, Sprintf("<input type=submit name=ok%d value=OK>", d->pid)); - if (size < d->size) + if (d->err) + Strcat_charp(src, " Error while saving file"); + else if (size < d->size) Strcat_charp(src, " Download incompleted"); else Strcat_charp(src, " Download completed");