snarf-unlink-empty.diff 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. diff -urN snarf-7.0.orig/http.c snarf-7.0/http.c
  2. --- snarf-7.0.orig/http.c 2003-08-01 14:46:26.000000000 +0100
  3. +++ snarf-7.0/http.c 2003-08-01 14:44:02.000000000 +0100
  4. @@ -447,6 +447,10 @@
  5. cleanup:
  6. free_http_header(header);
  7. close(sock); fclose(out);
  8. + if ((rsrc->open_created) && (rsrc->outfile_size == 0)
  9. + && (retval == 0))
  10. + if (unlink(rsrc->outfile))
  11. + report(ERR, "unlink %s: %s", rsrc->outfile, strerror(errno));
  12. return retval;
  13. }
  14. diff -urN snarf-7.0.orig/url.h snarf-7.0/url.h
  15. --- snarf-7.0.orig/url.h 2003-08-01 14:46:26.000000000 +0100
  16. +++ snarf-7.0/url.h 2003-08-01 13:27:22.000000000 +0100
  17. @@ -25,6 +25,7 @@
  18. struct _UrlResource {
  19. Url *url;
  20. char *outfile;
  21. + unsigned int open_created;
  22. char *proxy;
  23. char *proxy_username;
  24. char *proxy_password;
  25. diff -urN snarf-7.0.orig/util.h snarf-7.0/util.h
  26. --- snarf-7.0.orig/util.h 2000-08-09 01:12:25.000000000 +0100
  27. +++ snarf-7.0/util.h 2003-08-01 14:53:54.000000000 +0100
  28. @@ -53,7 +53,7 @@
  29. extern int debug_enabled;
  30. #define open_outfile(x) (((x)->outfile[0] == '-') ? stdout : real_open_outfile(x))
  31. -#define real_open_outfile(x) (((x)->options & OPT_RESUME && !((x)->options & OPT_NORESUME)) ? (fopen((x)->outfile, "a")) : (fopen((x)->outfile, "w")))
  32. +#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")))
  33. #define safe_free(x) if(x) free(x)
  34. #define safe_strdup(x) ( (x) ? strdup(x) : NULL )