commit 498dcbe29da26a487a52a6052491bf8a00c482c2
parent 9452571567c5c993801c230dae2aa2a5de13bd0c
Author: ukai <ukai>
Date:   Fri, 10 Jan 2003 16:42:14 +0000
[w3m-dev 03629] delete tmp file
* etc.c (tempfname): always file to delete
* file.c (xface2xpm): no need fileToDelete
	(readHeader): ditto
	(loadGeneralFile): ditto
	(loadHTMLBuffer): ditto
	(loadHTMLString): ditto
	(loadGopherDir): ditto
	(loadImageBuffer): ditto
	(doExternal): rewrite
	(doFileSave): no need fileToDelete
	(uncompress_stream): ditto
* fm.h (CurrentPid): added
* image.c (getImage): cache->touch to delete
* local.c (setLocalCookie): use CurrentPid
	(localcgi_post): fileToDelete
* main.c (main): CurrentPid
	(pipeBuf): no need fileToDelete
	(query_from_followform): CurrentPid
	(vmSrc): no need fileToDelete
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat:
7 files changed, 35 insertions(+), 38 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,5 +1,28 @@
 2003-01-11  Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
 
+	* [w3m-dev 03629] delete tmp file
+	* etc.c (tempfname): always file to delete
+	* file.c (xface2xpm): no need fileToDelete
+		(readHeader): ditto
+		(loadGeneralFile): ditto
+		(loadHTMLBuffer): ditto
+		(loadHTMLString): ditto
+		(loadGopherDir): ditto
+		(loadImageBuffer): ditto
+		(doExternal): rewrite
+		(doFileSave): no need fileToDelete
+		(uncompress_stream): ditto
+	* fm.h (CurrentPid): added
+	* image.c (getImage): cache->touch to delete
+	* local.c (setLocalCookie): use CurrentPid
+		(localcgi_post): fileToDelete
+	* main.c (main): CurrentPid
+		(pipeBuf): no need fileToDelete
+		(query_from_followform): CurrentPid
+		(vmSrc): no need fileToDelete
+
+2003-01-11  Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+
 	* [w3m-dev 03628] Re: Error occured while reset
 	* file.c (doExternal): bufp = NULL, return 1
 		(uncompress_stream): tempfname fileToDelete
diff --git a/etc.c b/etc.c
@@ -7,11 +7,6 @@
 #include "hash.h"
 #include "terms.h"
 
-#ifdef HAVE_GETCWD		/* ??? ukai */
-#include <unistd.h>
-#include <sys/param.h>
-#endif				/* HAVE_GETCWD */
-
 #include <sys/types.h>
 #include <time.h>
 #if defined(HAVE_WAITPID) || defined(HAVE_WAIT3)
@@ -1517,7 +1512,8 @@ tmpfname(int type, char *ext)
     tmpf = Sprintf("%s/w3m%s%d-%d%s",
 		   rc_dir,
 		   tmpf_base[type],
-		   (int)getpid(), tmpf_seq[type]++, (ext) ? ext : "");
+		   CurrentPid, tmpf_seq[type]++, (ext) ? ext : "");
+    pushText(fileToDelete, tmpf->ptr);
     return tmpf;
 }
 
diff --git a/file.c b/file.c
@@ -543,7 +543,6 @@ xface2xpm(char *xface)
     pclose(f);
     if (stat(xpm, &st))
 	return NULL;
-    pushText(fileToDelete, xpm);
     if (!st.st_size)
 	return NULL;
     return xpm;
@@ -579,7 +578,6 @@ readHeader(URLFile *uf, Buffer *newBuf, int thru, ParsedURL *pu)
 
     if (thru && !newBuf->header_source) {
 	Str tmpf = tmpfname(TMPF_DFL, NULL);
-	pushText(fileToDelete, tmpf->ptr);
 	src = fopen(tmpf->ptr, "w");
 	if (src)
 	    newBuf->header_source = tmpf->ptr;
@@ -1537,7 +1535,6 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer,
 		if (ftpdir && ftpdir->length > 0) {
 		    FILE *src;
 		    tmp = tmpfname(TMPF_SRC, ".html");
-		    pushText(fileToDelete, tmp->ptr);
 		    src = fopen(tmp->ptr, "w");
 		    if (src) {
 			Strfputs(ftpdir, src);
@@ -1593,7 +1590,6 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer,
 		if (group && group->length > 0) {
 		    FILE *src;
 		    tmp = tmpfname(TMPF_SRC, ".html");
-		    pushText(fileToDelete, tmp->ptr);
 		    src = fopen(tmp->ptr, "w");
 		    if (src) {
 			Strfputs(group, src);
@@ -6091,7 +6087,6 @@ loadHTMLBuffer(URLFile *f, Buffer *newBuf)
     if (newBuf->sourcefile == NULL &&
 	(f->scheme != SCM_LOCAL || newBuf->mailcap)) {
 	tmp = tmpfname(TMPF_SRC, ".html");
-	pushText(fileToDelete, tmp->ptr);
 	src = fopen(tmp->ptr, "w");
 	if (src)
 	    newBuf->sourcefile = tmp->ptr;
@@ -6586,7 +6581,6 @@ loadHTMLString(Str page)
 
     if (w3m_dump & DUMP_FRAME) {
 	tmp = tmpfname(TMPF_SRC, ".html");
-	pushText(fileToDelete, tmp->ptr);
 	src = fopen(tmp->ptr, "w");
 	if (src)
 	    newBuf->sourcefile = tmp->ptr;
@@ -6713,7 +6707,6 @@ loadGopherDir(URLFile *uf, Buffer *volatile newBuf)
     file = tmpfname(TMPF_SRC, ".html");
     src = fopen(file->ptr, "w");
     newBuf->sourcefile = file->ptr;
-    pushText(fileToDelete, file->ptr);
 
     init_stream(&f, SCM_LOCAL, newStrStream(tmp));
     loadHTMLstream(&f, newBuf, src, TRUE);
@@ -6893,7 +6886,6 @@ loadImageBuffer(URLFile *uf, Buffer *newBuf)
     tmpf = tmpfname(TMPF_SRC, ".html");
     src = fopen(tmpf->ptr, "w");
     newBuf->mailcap_source = tmpf->ptr;
-    pushText(fileToDelete, tmpf->ptr);
 
     init_stream(&f, SCM_LOCAL, newStrStream(tmp));
     loadHTMLstream(&f, newBuf, src, TRUE);
@@ -7338,26 +7330,18 @@ doExternal(URLFile uf, char *path, char *type, Buffer **bufp,
     struct mailcap *mcap;
     int mc_stat;
     Buffer *buf = NULL;
-    char *header, *src = NULL;
+    char *header, *src = NULL, *ext = uf.ext;
 
     if (!(mcap = searchExtViewer(type)))
 	return 0;
 
-    tmpf = tmpfname(TMPF_DFL, NULL);
-
     if (mcap->nametemplate) {
-	Str tmp =
-	    unquote_mailcap(mcap->nametemplate, NULL, tmpf->ptr, NULL, NULL);
-	if (Strncmp(tmpf, tmp, tmpf->length) == 0) {
-	    tmpf = tmp;
-	    goto _save;
-	}
-    }
-    if (uf.ext && *uf.ext) {
-	Strcat_charp(tmpf, uf.ext);
+	tmpf = unquote_mailcap(mcap->nametemplate, NULL, "", NULL, NULL);
+	if (tmpf->ptr[0] == '.')
+	    ext = tmpf->ptr;
     }
+    tmpf = tmpfname(TMPF_DFL, (ext && *ext) ? ext : NULL);
 
-  _save:
     if (IStype(uf.stream) != IST_ENCODED)
 	uf.stream = newEncodedStream(uf.stream, uf.encoding);
     header = checkHeader(defaultbuf, "Content-Type:");
@@ -7371,7 +7355,6 @@ doExternal(URLFile uf, char *path, char *type, Buffer **bufp,
     }
 #endif
 
-    pushText(fileToDelete, tmpf->ptr);
 #ifdef HAVE_SETPGRP
     if (!(mcap->flags & (MAILCAP_HTMLOUTPUT | MAILCAP_COPIOUSOUTPUT)) &&
 	!(mcap->flags & MAILCAP_NEEDSTERMINAL) && BackgroundExtViewer) {
@@ -7543,7 +7526,6 @@ _doFileCopy(char *tmpf, char *defstr, int download)
 	if (f)
 	    fclose(f);
 #endif
-	pushText(fileToDelete, lock);
 	flush_tty();
 	pid = fork();
 	if (!pid) {
@@ -7646,7 +7628,6 @@ doFileSave(URLFile uf, char *defstr)
 	if (f)
 	    fclose(f);
 #endif
-	pushText(fileToDelete, lock);
 	flush_tty();
 	pid = fork();
 	if (!pid) {
@@ -7790,7 +7771,6 @@ uncompress_stream(URLFile *uf, char **src)
 
     if (uf->scheme != SCM_LOCAL) {
 	tmpf = tmpfname(TMPF_DFL, ext)->ptr;
-	pushText(fileToDelete, tmpf);
 	if (save2tmp(*uf, tmpf) < 0) {
 	    UFclose(uf);
 	    return;
diff --git a/fm.h b/fm.h
@@ -829,6 +829,7 @@ global char *cgi_bin init(NULL);
 global char *index_file init(NULL);
 
 global char *CurrentDir;
+global int CurrentPid;
 /*
 global Buffer *Currentbuf;
 global Buffer *Firstbuf;
diff --git a/image.c b/image.c
@@ -518,8 +518,6 @@ getImage(Image * image, ParsedURL *current, int flag)
 	cache->width = image->width;
 	cache->height = image->height;
 	putHash_sv(image_hash, key->ptr, (void *)cache);
-	pushText(fileToDelete, cache->file);
-	pushText(fileToDelete, cache->touch);
     }
     if (flag != IMG_FLAG_SKIP) {
 	if (cache->loaded == IMG_FLAG_UNLOADED) {
diff --git a/local.c b/local.c
@@ -30,7 +30,7 @@ setLocalCookie()
     char hostname[256];
     gethostname(hostname, 256);
 
-    Local_cookie = Sprintf("%d.%ld@%s", getpid(), lrand48(), hostname);
+    Local_cookie = Sprintf("%d.%ld@%s", CurrentPid, lrand48(), hostname);
     set_environ("LOCAL_COOKIE", Local_cookie->ptr);
 }
 
@@ -400,7 +400,6 @@ localcgi_post(char *uri, char *qstr, FormList *request, char *referer)
     f1 = fopen(tmp1->ptr, "w");
     if (f1 == NULL)
 	return NULL;
-    pushText(fileToDelete, tmp1->ptr);
     if ((pid = localcgi_popen_r(&f))) {
 	fclose(f1);
 	return pid > 0 ? f : NULL;
diff --git a/main.c b/main.c
@@ -5,6 +5,7 @@
 #include <setjmp.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <unistd.h>
 #include <fcntl.h>
 #if defined(HAVE_WAITPID) || defined(HAVE_WAIT3)
 #include <sys/wait.h>
@@ -380,6 +381,7 @@ main(int argc, char **argv, char **envp)
     load_argc = 0;
 
     CurrentDir = currentdir();
+    CurrentPid = (int)getpid();
     BookmarkFile = NULL;
     rc_dir = expandName(RC_DIR);
     i = strlen(rc_dir);
@@ -1868,7 +1870,6 @@ pipeBuf(void)
     }
     saveBuffer(Currentbuf, f);
     fclose(f);
-    pushText(fileToDelete, tmpf);
     buf = getpipe(myExtCommand(cmd, tmpf, TRUE)->ptr);
     if (buf == NULL) {
 	disp_message("Execution failed", TRUE);
@@ -3051,7 +3052,7 @@ query_from_followform(Str *query, FormItemList *fi, int multipart)
 	}
 	fi->parent->body = (*query)->ptr;
 	fi->parent->boundary =
-	    Sprintf("------------------------------%d%ld%ld%ld", getpid(),
+	    Sprintf("------------------------------%d%ld%ld%ld", CurrentPid,
 		    fi->parent, fi->parent->body, fi->parent->boundary)->ptr;
     }
     *query = Strnew();
@@ -4395,7 +4396,6 @@ vwSrc(void)
 	    !strcasecmp(Currentbuf->type, "text/plain")) {
 	    FILE *f;
 	    Str tmpf = tmpfname(TMPF_SRC, NULL);
-	    pushText(fileToDelete, tmpf->ptr);
 	    f = fopen(tmpf->ptr, "w");
 	    if (f == NULL)
 		return;