aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Woodward2009-10-17 17:16:32 -0400
committerJason Woodward2009-10-17 17:16:32 -0400
commitc77c20ebbf4e80986b433cd7c5a601fc11a48485 (patch)
tree17a6ef8fd962a2036a568a3b6a6e131235aa29e4 /src
parentde850b9fe3c773cf553457c9dea49f0a6c45253a (diff)
downloadslapt-get-c77c20ebbf4e80986b433cd7c5a601fc11a48485.tar.gz
* modified disk checking mechanism so that the working directory filesystem0.10.2b
is checked for downloads and then / is checked for the uncompressed size. This is not 100% ideal since /usr may be on another filestem but it should make Tadgy slightly happier. Added slapt_disk_space_check to public API.
Diffstat (limited to 'src')
-rw-r--r--src/common.c24
-rw-r--r--src/common.h1
-rw-r--r--src/transaction.c42
3 files changed, 34 insertions, 33 deletions
diff --git a/src/common.c b/src/common.c
index 6da830b..5d79731 100644
--- a/src/common.c
+++ b/src/common.c
@@ -356,3 +356,27 @@ const char *slapt_priority_to_str(SLAPT_PRIORITY_T priority)
};
}
+
+SLAPT_BOOL_T slapt_disk_space_check (const char *path,double space_needed)
+{
+ struct statvfs statvfs_buf;
+
+ if (space_needed < 0)
+ return SLAPT_TRUE;
+
+ space_needed *= 1024;
+
+ if (statvfs(path, &statvfs_buf) != 0) {
+
+ if (errno)
+ perror("statvfs");
+
+ return SLAPT_FALSE;
+ } else {
+ if (statvfs_buf.f_bavail < (space_needed / statvfs_buf.f_bsize))
+ return SLAPT_FALSE;
+ }
+
+ return SLAPT_TRUE;
+}
+
diff --git a/src/common.h b/src/common.h
index c92dc24..0390e45 100644
--- a/src/common.h
+++ b/src/common.h
@@ -72,3 +72,4 @@ __inline void *slapt_calloc(size_t n,size_t s);
const char *slapt_strerror(slapt_code_t code);
/* return human readable priority */
const char *slapt_priority_to_str(SLAPT_PRIORITY_T priority);
+SLAPT_BOOL_T slapt_disk_space_check (const char *path,double space_needed);
diff --git a/src/transaction.c b/src/transaction.c
index 7c26d3f..fb3d9e9 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -26,7 +26,6 @@ static void queue_add_upgrade(slapt_queue_t *t, slapt_pkg_upgrade_t *p);
static void queue_free(slapt_queue_t *t);
static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg);
-static int disk_space(const slapt_rc_config *global_config,double space_needed);
slapt_transaction_t *slapt_init_transaction(void)
{
@@ -235,7 +234,6 @@ int slapt_handle_transaction (const slapt_rc_config *global_config,
/* only show this if we are going to do download something */
if (tran->upgrade_pkgs->pkg_count > 0 || tran->install_pkgs->pkg_count > 0) {
- double space_needed = 0;
/* how much we need to download */
double need_to_download_size = download_size - already_download_size;
@@ -244,13 +242,6 @@ int slapt_handle_transaction (const slapt_rc_config *global_config,
if (need_to_download_size < 0)
need_to_download_size = 0;
- space_needed += need_to_download_size;
-
- /* if we are not just downloading, consider the uncompressed size */
- if (global_config->download_only == SLAPT_FALSE) {
- space_needed += uncompressed_size;
- }
-
if (already_download_size > 0) {
printf(gettext("Need to get %.1f%s/%.1f%s of archives.\n"),
(need_to_download_size > 1024) ? need_to_download_size / (double)1024
@@ -266,13 +257,21 @@ int slapt_handle_transaction (const slapt_rc_config *global_config,
);
}
- if (disk_space(global_config,space_needed) != 0) {
+ /* check we have enough space to download to our working dir */
+ if (slapt_disk_space_check (global_config->working_dir,need_to_download_size) == SLAPT_FALSE) {
printf(
gettext("You don't have enough free space in %s\n"),
global_config->working_dir
);
exit(EXIT_FAILURE);
}
+ /* check that we have enough space in the root filesystem */
+ if (global_config->download_only == SLAPT_FALSE) {
+ if (slapt_disk_space_check ("/", uncompressed_size) == SLAPT_FALSE) {
+ printf(gettext("You don't have enough free space in %s\n"),"/");
+ exit(EXIT_FAILURE);
+ }
+ }
}
@@ -941,29 +940,6 @@ static void add_suggestion(slapt_transaction_t *tran, slapt_pkg_info_t *pkg)
}
-static int disk_space (const slapt_rc_config *global_config,double space_needed)
-{
- struct statvfs statvfs_buf;
-
- space_needed *= 1024;
-
- if (space_needed < 0)
- return 0;
-
- if (statvfs(global_config->working_dir,&statvfs_buf) != 0) {
-
- if (errno)
- perror("statvfs");
-
- return 1;
- } else {
- if (statvfs_buf.f_bfree < (space_needed / statvfs_buf.f_bsize))
- return 1;
- }
-
- return 0;
-}
-
int slapt_search_transaction_by_pkg(slapt_transaction_t *tran,
slapt_pkg_info_t *pkg)
{