summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-01-11 15:39:52 -0600
committerDan McGee <dan@archlinux.org>2012-01-18 22:10:06 -0600
commitb3612e9cc198f198b3806efa461bf6fc04dd4502 (patch)
tree85d6018836a02c4ed4cb1211d3ec73d34a2259c9 /lib
parent6e8ca48cbb22c328deab56b1740be04ea7ddba6e (diff)
Allow UseDelta option to specify a delta ratio
Rework the frontend and backend to allow passing a ratio value in for UseDelta rather than having a hardcoded #define-d 0.7 value always used. This is useful for those with fast connections, who would likely benefit from tuning this ratio to lower values; it is also useful for general testing purposes. The libalpm API changes for this, but we do support the old config file format with a no-value 'UseDelta' option; in this case we simply use the old default of 0.7. We clamp the ratio values to a sane range between 0.0 and 2.0, allowing ratios above 1.0 for testing purposes. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/alpm.h4
-rw-r--r--lib/libalpm/delta.c3
-rw-r--r--lib/libalpm/delta.h3
-rw-r--r--lib/libalpm/handle.c12
-rw-r--r--lib/libalpm/handle.h2
-rw-r--r--lib/libalpm/sync.c4
6 files changed, 15 insertions, 13 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 95c817ea..9ffdebc5 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -535,8 +535,8 @@ const char *alpm_option_get_arch(alpm_handle_t *handle);
/** Sets the targeted architecture. */
int alpm_option_set_arch(alpm_handle_t *handle, const char *arch);
-int alpm_option_get_usedelta(alpm_handle_t *handle);
-int alpm_option_set_usedelta(alpm_handle_t *handle, int usedelta);
+double alpm_option_get_deltaratio(alpm_handle_t *handle);
+int alpm_option_set_deltaratio(alpm_handle_t *handle, double ratio);
int alpm_option_get_checkspace(alpm_handle_t *handle);
int alpm_option_set_checkspace(alpm_handle_t *handle, int checkspace);
diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
index 726f03c0..e3acc666 100644
--- a/lib/libalpm/delta.c
+++ b/lib/libalpm/delta.c
@@ -264,7 +264,8 @@ static alpm_list_t *find_unused(alpm_list_t *deltas, const char *to, off_t quota
alpm_list_t SYMEXPORT *alpm_pkg_unused_deltas(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- return find_unused(pkg->deltas, pkg->filename, pkg->size * MAX_DELTA_RATIO);
+ return find_unused(pkg->deltas, pkg->filename,
+ pkg->size * pkg->handle->deltaratio);
}
/** @} */
diff --git a/lib/libalpm/delta.h b/lib/libalpm/delta.h
index 1173ddfe..37f208b0 100644
--- a/lib/libalpm/delta.h
+++ b/lib/libalpm/delta.h
@@ -30,9 +30,6 @@ alpm_delta_t *_alpm_delta_dup(const alpm_delta_t *delta);
off_t _alpm_shortest_delta_path(alpm_handle_t *handle, alpm_list_t *deltas,
const char *to, alpm_list_t **path);
-/* max percent of package size to download deltas */
-#define MAX_DELTA_RATIO 0.7
-
#endif /* _ALPM_DELTA_H */
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 8e2e3c73..2187dca9 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -43,6 +43,7 @@ alpm_handle_t *_alpm_handle_new(void)
alpm_handle_t *handle;
CALLOC(handle, 1, sizeof(alpm_handle_t), return NULL);
+ handle->deltaratio = 0.0;
return handle;
}
@@ -252,10 +253,10 @@ const char SYMEXPORT *alpm_option_get_arch(alpm_handle_t *handle)
return handle->arch;
}
-int SYMEXPORT alpm_option_get_usedelta(alpm_handle_t *handle)
+double SYMEXPORT alpm_option_get_deltaratio(alpm_handle_t *handle)
{
CHECK_HANDLE(handle, return -1);
- return handle->usedelta;
+ return handle->deltaratio;
}
int SYMEXPORT alpm_option_get_checkspace(alpm_handle_t *handle)
@@ -597,10 +598,13 @@ int SYMEXPORT alpm_option_set_arch(alpm_handle_t *handle, const char *arch)
return 0;
}
-int SYMEXPORT alpm_option_set_usedelta(alpm_handle_t *handle, int usedelta)
+int SYMEXPORT alpm_option_set_deltaratio(alpm_handle_t *handle, double ratio)
{
CHECK_HANDLE(handle, return -1);
- handle->usedelta = usedelta;
+ if(ratio < 0.0 || ratio > 2.0) {
+ RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1);
+ }
+ handle->deltaratio = ratio;
return 0;
}
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index a64c5c9e..a090ae42 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -88,8 +88,8 @@ struct __alpm_handle_t {
/* options */
char *arch; /* Architecture of packages we should allow */
+ double deltaratio; /* Download deltas if possible; a ratio value */
int usesyslog; /* Use syslog instead of logfile? */ /* TODO move to frontend */
- int usedelta; /* Download deltas if possible */
int checkspace; /* Check disk space before installing */
alpm_siglevel_t siglevel; /* Default signature verification level */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 49a3f42d..6967b49b 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -318,13 +318,13 @@ static int compute_download_size(alpm_pkg_t *newpkg)
/* tell the caller that we have a partial */
ret = 1;
- } else if(handle->usedelta) {
+ } else if(handle->deltaratio > 0.0) {
off_t dltsize;
dltsize = _alpm_shortest_delta_path(handle, newpkg->deltas,
newpkg->filename, &newpkg->delta_path);
- if(newpkg->delta_path && (dltsize < newpkg->size * MAX_DELTA_RATIO)) {
+ if(newpkg->delta_path && (dltsize < newpkg->size * handle->deltaratio)) {
_alpm_log(handle, ALPM_LOG_DEBUG, "using delta size\n");
size = dltsize;
} else {