[pacman-dev] [PATCH 4/5] sync: check for necessary disk space for download

Dave Reisner d at falconindy.com
Sun Oct 16 14:59:16 EDT 2011


Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
 lib/libalpm/sync.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index cac4c8f..3c304a3 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -872,6 +872,31 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas)
 	}
 
 	if(files) {
+		/* check for necessary disk space for download */
+		if(handle->checkspace) {
+			off_t *file_sizes;
+			size_t num_files;
+			int idx, ret;
+
+			_alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space for download\n");
+
+			num_files = alpm_list_count(files);
+			CALLOC(file_sizes, num_files, sizeof(off_t), goto finish);
+
+			for(i = files, idx = 0; i; i = i->next, idx++) {
+				const struct dload_payload *payload = i->data;
+				file_sizes[idx] = payload->max_size;
+			}
+
+			ret = _alpm_check_downloadspace(handle, cachedir, num_files, file_sizes);
+			free(file_sizes);
+
+			if(ret != 0) {
+				errors++;
+				goto finish;
+			}
+		}
+
 		EVENT(handle, ALPM_EVENT_RETRIEVE_START, NULL, NULL);
 		for(i = files; i; i = i->next) {
 			struct dload_payload *payload = i->data;
@@ -899,7 +924,10 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas)
 				_alpm_log(handle, ALPM_LOG_WARNING, _("failed to retrieve some files\n"));
 			}
 		}
+	}
 
+finish:
+	if(files) {
 		alpm_list_free_inner(files, (alpm_list_fn_free)_alpm_dload_payload_reset);
 		FREELIST(files);
 	}
-- 
1.7.7



More information about the pacman-dev mailing list