FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-24-2011, 11:22 PM
Allan McRae
 
Default Do not replicate files list when removing packages

This saves replicating the list of files in a package that is being
removed which can be quite large.

Signed-off-by: Allan McRae <allan@archlinux.org>
---

The tradeoff here is a slightly less readable loop, but duplicating that list
just struck me as wasteful.

lib/libalpm/remove.c | 41 +++++++++++++++++++++++------------------
1 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index cc6daea..2d75a84 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -285,8 +285,7 @@ static void unlink_file(pmhandle_t *handle, pmpkg_t *info, const char *filename,
int _alpm_upgraderemove_package(pmhandle_t *handle,
pmpkg_t *oldpkg, pmpkg_t *newpkg)
{
- alpm_list_t *skip_remove, *b;
- alpm_list_t *newfiles, *lp;
+ alpm_list_t *skip_remove, *b, *lp;
size_t filenum=0;
alpm_list_t *files = alpm_pkg_get_files(oldpkg);
const char *pkgname = alpm_pkg_get_name(oldpkg);
@@ -329,11 +328,15 @@ int _alpm_upgraderemove_package(pmhandle_t *handle,
_alpm_log(handle, PM_LOG_DEBUG, "removing %ld files
", (unsigned long)filenum);

/* iterate through the list backwards, unlinking files */
- newfiles = alpm_list_reverse(files);
- for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
- unlink_file(handle, oldpkg, lp->data, skip_remove, 0);
+ if(files) {
+ alpm_list_t *last = alpm_list_last(files);
+ lp = last;
+ do {
+ unlink_file(handle, oldpkg, lp->data, skip_remove, 0);
+ lp = lp->prev;
+ } while (lp != last);
}
- alpm_list_free(newfiles);
+
FREELIST(skip_remove);

db:
@@ -390,7 +393,6 @@ int _alpm_remove_packages(pmhandle_t *handle)

if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
alpm_list_t *files = alpm_pkg_get_files(info);
- alpm_list_t *newfiles;
size_t filenum=0;

for(lp = files; lp; lp = lp->next) {
@@ -409,18 +411,21 @@ int _alpm_remove_packages(pmhandle_t *handle)
pkg_count, (pkg_count - targcount + 1));

/* iterate through the list backwards, unlinking files */
- newfiles = alpm_list_reverse(files);
- for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
- int percent;
- unlink_file(handle, info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
-
- /* update progress bar after each file */
- percent = (position * 100) / filenum;
- PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
- percent, pkg_count, (pkg_count - targcount + 1));
- position++;
+ if(files) {
+ alpm_list_t *last = alpm_list_last(files);
+ lp = last;
+ do {
+ int percent;
+ unlink_file(handle, info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
+
+ /* update progress bar after each file */
+ percent = (position * 100) / filenum;
+ PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
+ percent, pkg_count, (pkg_count - targcount + 1));
+ position++;
+ lp = lp->prev;
+ } while (lp != last);
}
- alpm_list_free(newfiles);
}

/* set progress to 100% after we finish unlinking files */
--
1.7.5.4
 
Old 07-03-2011, 12:26 AM
Allan McRae
 
Default Do not replicate files list when removing packages

This saves replicating the potentially large list of files in a package
that is being removed.

Signed-off-by: Allan McRae <allan@archlinux.org>
---
lib/libalpm/remove.c | 12 +++---------
1 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 86571a4..48adf04 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -285,8 +285,7 @@ static void unlink_file(alpm_handle_t *handle, alpm_pkg_t *info, const char *fil
int _alpm_upgraderemove_package(alpm_handle_t *handle,
alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
{
- alpm_list_t *skip_remove, *b;
- alpm_list_t *newfiles, *lp;
+ alpm_list_t *skip_remove, *b, *lp;
size_t filenum = 0;
alpm_list_t *files = alpm_pkg_get_files(oldpkg);
const char *pkgname = alpm_pkg_get_name(oldpkg);
@@ -329,11 +328,9 @@ int _alpm_upgraderemove_package(alpm_handle_t *handle,
_alpm_log(handle, PM_LOG_DEBUG, "removing %ld files
", (unsigned long)filenum);

/* iterate through the list backwards, unlinking files */
- newfiles = alpm_list_reverse(files);
- for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
+ for(lp = alpm_list_last(files); lp; lp = alpm_list_previous(files, lp)) {
unlink_file(handle, oldpkg, lp->data, skip_remove, 0);
}
- alpm_list_free(newfiles);
FREELIST(skip_remove);

db:
@@ -390,7 +387,6 @@ int _alpm_remove_packages(alpm_handle_t *handle)

if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
alpm_list_t *files = alpm_pkg_get_files(info);
- alpm_list_t *newfiles;
size_t filenum = 0;

for(lp = files; lp; lp = lp->next) {
@@ -409,8 +405,7 @@ int _alpm_remove_packages(alpm_handle_t *handle)
pkg_count, (pkg_count - targcount + 1));

/* iterate through the list backwards, unlinking files */
- newfiles = alpm_list_reverse(files);
- for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
+ for(lp = alpm_list_last(files); lp; lp = alpm_list_previous(files, lp)) {
int percent;
unlink_file(handle, info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);

@@ -420,7 +415,6 @@ int _alpm_remove_packages(alpm_handle_t *handle)
percent, pkg_count, (pkg_count - targcount + 1));
position++;
}
- alpm_list_free(newfiles);
}

/* set progress to 100% after we finish unlinking files */
--
1.7.6
 

Thread Tools




All times are GMT. The time now is 10:12 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org