diff options
Diffstat (limited to 'net-misc/snarf/files/snarf-unlink-empty.diff')
-rw-r--r-- | net-misc/snarf/files/snarf-unlink-empty.diff | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/net-misc/snarf/files/snarf-unlink-empty.diff b/net-misc/snarf/files/snarf-unlink-empty.diff new file mode 100644 index 000000000000..d9f4487839c4 --- /dev/null +++ b/net-misc/snarf/files/snarf-unlink-empty.diff @@ -0,0 +1,43 @@ +###################################################### +# Purpose: If the requested file isnt empty, and snarf created the file, unlink it. +# Author: Tavis Ormandy <taviso@gentoo.org> +# Date: 1/08/2003 +# Applies Against: Snarf-7.0+basename +################################### +diff -urN snarf-7.0.orig/http.c snarf-7.0/http.c +--- snarf-7.0.orig/http.c 2003-08-01 14:46:26.000000000 +0100 ++++ snarf-7.0/http.c 2003-08-01 14:44:02.000000000 +0100 +@@ -447,6 +447,10 @@ + cleanup: + free_http_header(header); + close(sock); fclose(out); ++ if ((rsrc->open_created) && (rsrc->outfile_size == 0) ++ && (retval == 0)) ++ if (unlink(rsrc->outfile)) ++ report(ERR, "unlink %s: %s", rsrc->outfile, strerror(errno)); + return retval; + + } +diff -urN snarf-7.0.orig/url.h snarf-7.0/url.h +--- snarf-7.0.orig/url.h 2003-08-01 14:46:26.000000000 +0100 ++++ snarf-7.0/url.h 2003-08-01 13:27:22.000000000 +0100 +@@ -25,6 +25,7 @@ + struct _UrlResource { + Url *url; + char *outfile; ++ unsigned int open_created; + char *proxy; + char *proxy_username; + char *proxy_password; +diff -urN snarf-7.0.orig/util.h snarf-7.0/util.h +--- snarf-7.0.orig/util.h 2000-08-09 01:12:25.000000000 +0100 ++++ snarf-7.0/util.h 2003-08-01 14:53:54.000000000 +0100 +@@ -53,7 +53,7 @@ + extern int debug_enabled; + + #define open_outfile(x) (((x)->outfile[0] == '-') ? stdout : real_open_outfile(x)) +-#define real_open_outfile(x) (((x)->options & OPT_RESUME && !((x)->options & OPT_NORESUME)) ? (fopen((x)->outfile, "a")) : (fopen((x)->outfile, "w"))) ++#define real_open_outfile(x) (((x)->open_created = (access ((x)->outfile, F_OK)) ? 1 : 0 ),((x)->options & OPT_RESUME && !((x)->options & OPT_NORESUME)) ? (fopen((x)->outfile, "a")) : (fopen((x)->outfile, "w"))) + + #define safe_free(x) if(x) free(x) + #define safe_strdup(x) ( (x) ? strdup(x) : NULL ) |