1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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 )
|