From 5847a115708909f63bc6187409ae4b27fe06f289 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 23 Jun 2011 00:06:50 +0200
Subject: [PATCH] xbps_fetch_file: remove local file if bigger than remote and
 refetch.

---
 lib/download.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/download.c b/lib/download.c
index 42e2a5e0..5c231334 100644
--- a/lib/download.c
+++ b/lib/download.c
@@ -233,11 +233,13 @@ xbps_fetch_file(const char *uri,
 		rv = -1;
 		goto out;
 	} else if (st.st_size > url_st.size) {
-		xbps_error_printf("Local file %s is greater than remote "
-		    "file!\n", filename);
-		errno = EFBIG;
-		rv = -1;
-		goto out;
+		/*
+		 * Remove local file if bigger than remote, and refetch the
+		 * whole shit again.
+		 */
+		xbps_warn_printf("Local file %s is greater than remote, "
+		    "removing local file and refetching...\n", filename);
+		(void)remove(destfile);
 	} else if (restart && url_st.mtime && url_st.size &&
 		   url_st.size == st.st_size && url_st.mtime == st.st_mtime) {
 		/* Local and remote size/mtime match, do nothing. */