Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=85ea6c4b9b4cefbf4eba397c99e93a279a2f17c5

commit 85ea6c4b9b4cefbf4eba397c99e93a279a2f17c5
Author: Michel Hermier <[email protected]>
Date:   Mon Jun 9 08:23:03 2014 +0200

libpacman: Move _pacman_localpackage_remove to db/localdb.h.

diff --git a/lib/libpacman/db/localdb.cpp b/lib/libpacman/db/localdb.cpp
index 317ca20..d39495c 100644
--- a/lib/libpacman/db/localdb.cpp
+++ b/lib/libpacman/db/localdb.cpp
@@ -132,6 +132,96 @@ int LocalPackage::remove()
return(0);
}

+int _pacman_localpackage_remove(Package *pkg, pmtrans_t *trans, int howmany, 
int remain)
+{
+       pmlist_t *lp;
+       struct stat buf;
+       int position = 0;
+       Handle *handle = trans->m_handle;
+       char line[PATH_MAX+1];
+
+       int filenum = _pacman_list_count(pkg->files());
+       _pacman_log(PM_LOG_FLOW1, _("removing files"));
+
+       /* iterate through the list backwards, unlinking files */
+       for(lp = _pacman_list_last(pkg->files()); lp; lp = lp->prev) {
+               int nb = 0;
+               double percent = 0;
+               char *file = lp->data;
+               char *hash_orig = pkg->fileneedbackup(file);
+
+               if (position != 0) {
+                       percent = (double)position / filenum;
+               }
+               if(!_pacman_strempty(hash_orig)) {
+                       nb = 1;
+               }
+               FREE(hash_orig);
+               if(!nb && trans->m_type == PM_TRANS_TYPE_UPGRADE) {
+                       /* check noupgrade */
+                       if(_pacman_list_is_strin(file, handle->noupgrade)) {
+                               nb = 1;
+                       }
+               }
+               snprintf(line, PATH_MAX, "%s%s", handle->root, file);
+               if(lstat(line, &buf)) {
+                       _pacman_log(PM_LOG_DEBUG, _("file %s does not exist"), 
file);
+                       continue;
+               }
+               if(S_ISDIR(buf.st_mode)) {
+                       if(rmdir(line)) {
+                               /* this is okay, other packages are probably 
using it. */
+                               _pacman_log(PM_LOG_DEBUG, _("keeping directory 
%s"), file);
+                       } else {
+                               _pacman_log(PM_LOG_FLOW2, _("removing directory 
%s"), file);
+                       }
+               } else {
+                       /* check the "skip list" before removing the file.
+                        * see the big comment block in db_find_conflicts() for 
an
+                        * explanation. */
+                       int skipit = 0;
+                       pmlist_t *j;
+                       for(j = trans->skiplist; j; j = j->next) {
+                               if(!strcmp(file, (char*)j->data)) {
+                                       skipit = 1;
+                               }
+                       }
+                       if(skipit) {
+                               _pacman_log(PM_LOG_FLOW2, _("skipping removal 
of %s as it has moved to another package"),
+                                               file);
+                       } else {
+                               /* if the file is flagged, back it up to 
.pacsave */
+                               if(nb) {
+                                       if(trans->m_type == 
PM_TRANS_TYPE_UPGRADE) {
+                                               /* we're upgrading so just 
leave the file as is. pacman_add() will handle it */
+                                       } else {
+                                               if(!(trans->flags & 
PM_TRANS_FLAG_NOSAVE)) {
+                                                       char newpath[PATH_MAX];
+                                                       snprintf(newpath, 
PATH_MAX, "%s.pacsave", line);
+                                                       rename(line, newpath);
+                                                       
_pacman_log(PM_LOG_WARNING, _("%s saved as %s"), line, newpath);
+                                               } else {
+                                                       
_pacman_log(PM_LOG_FLOW2, _("unlinking %s"), file);
+                                                       if(unlink(line)) {
+                                                               
_pacman_log(PM_LOG_ERROR, _("cannot remove file %s"), file);
+                                                       }
+                                               }
+                                       }
+                               } else {
+                                       _pacman_log(PM_LOG_FLOW2, _("unlinking 
%s"), file);
+                                       /* Need at here because we count only 
real unlinked files ? */
+                                       PROGRESS(trans, 
PM_TRANS_PROGRESS_REMOVE_START, pkg->name(), (int)(percent * 100), howmany, 
howmany - remain + 1);
+                                       position++;
+                                       if(unlink(line)) {
+                                               _pacman_log(PM_LOG_ERROR, 
_("cannot remove file %s"), file);
+                                       }
+                               }
+                       }
+               }
+       }
+       return 0;
+}
+
LocalDatabase::LocalDatabase(libpacman::Handle *handle, const char *treename)
: Database(handle, treename)
{
diff --git a/lib/libpacman/db/localdb.h b/lib/libpacman/db/localdb.h
index 3f7e6b9..28bcfb8 100644
--- a/lib/libpacman/db/localdb.h
+++ b/lib/libpacman/db/localdb.h
@@ -72,6 +72,8 @@ private:

}

+int _pacman_localpackage_remove(libpacman::Package *pkg, pmtrans_t *trans, int 
howmany, int remain);
+
#endif /* _PACMAN_LOCALDB_H */

/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/trans.cpp b/lib/libpacman/trans.cpp
index 700a75a..379f94f 100644
--- a/lib/libpacman/trans.cpp
+++ b/lib/libpacman/trans.cpp
@@ -28,6 +28,7 @@
#include "trans.h"

#include "db/fakedb.h"
+#include "db/localdb.h"
#include "db/localdb_files.h"
#include "package/fpmpackage.h"
#include "conflict.h"
@@ -1313,97 +1314,6 @@ int _pacman_fpmpackage_install(Package *pkg, 
pmtranstype_t type, pmtrans_t *tran
}

static
-int _pacman_localpackage_remove(Package *pkg, pmtrans_t *trans, int howmany, 
int remain)
-{
-       pmlist_t *lp;
-       struct stat buf;
-       int position = 0;
-       Handle *handle = trans->m_handle;
-       char line[PATH_MAX+1];
-
-                       int filenum = _pacman_list_count(pkg->files());
-                       _pacman_log(PM_LOG_FLOW1, _("removing files"));
-
-                       /* iterate through the list backwards, unlinking files 
*/
-                       for(lp = _pacman_list_last(pkg->files()); lp; lp = 
lp->prev) {
-                               int nb = 0;
-                               double percent = 0;
-                               char *file = lp->data;
-                               char *hash_orig = pkg->fileneedbackup(file);
-
-                               if (position != 0) {
-                               percent = (double)position / filenum;
-                               }
-                               if(!_pacman_strempty(hash_orig)) {
-                                       nb = 1;
-                               }
-                               FREE(hash_orig);
-                               if(!nb && trans->m_type == 
PM_TRANS_TYPE_UPGRADE) {
-                                       /* check noupgrade */
-                                       if(_pacman_list_is_strin(file, 
handle->noupgrade)) {
-                                               nb = 1;
-                                       }
-                               }
-                               snprintf(line, PATH_MAX, "%s%s", handle->root, 
file);
-                               if(lstat(line, &buf)) {
-                                       _pacman_log(PM_LOG_DEBUG, _("file %s 
does not exist"), file);
-                                       continue;
-                               }
-                               if(S_ISDIR(buf.st_mode)) {
-                                       if(rmdir(line)) {
-                                               /* this is okay, other packages 
are probably using it. */
-                                               _pacman_log(PM_LOG_DEBUG, 
_("keeping directory %s"), file);
-                                       } else {
-                                               _pacman_log(PM_LOG_FLOW2, 
_("removing directory %s"), file);
-                                       }
-                               } else {
-                                       /* check the "skip list" before 
removing the file.
-                                        * see the big comment block in 
db_find_conflicts() for an
-                                        * explanation. */
-                                       int skipit = 0;
-                                       pmlist_t *j;
-                                       for(j = trans->skiplist; j; j = 
j->next) {
-                                               if(!strcmp(file, 
(char*)j->data)) {
-                                                       skipit = 1;
-                                               }
-                                       }
-                                       if(skipit) {
-                                               _pacman_log(PM_LOG_FLOW2, 
_("skipping removal of %s as it has moved to another package"),
-                                                       file);
-                                       } else {
-                                               /* if the file is flagged, back 
it up to .pacsave */
-                                               if(nb) {
-                                                       if(trans->m_type == 
PM_TRANS_TYPE_UPGRADE) {
-                                                               /* we're 
upgrading so just leave the file as is. pacman_add() will handle it */
-                                                       } else {
-                                                               
if(!(trans->flags & PM_TRANS_FLAG_NOSAVE)) {
-                                                                       char 
newpath[PATH_MAX];
-                                                                       
snprintf(newpath, PATH_MAX, "%s.pacsave", line);
-                                                                       
rename(line, newpath);
-                                                                       
_pacman_log(PM_LOG_WARNING, _("%s saved as %s"), line, newpath);
-                                                               } else {
-                                                                       
_pacman_log(PM_LOG_FLOW2, _("unlinking %s"), file);
-                                                                       
if(unlink(line)) {
-                                                                               
_pacman_log(PM_LOG_ERROR, _("cannot remove file %s"), file);
-                                                                       }
-                                                               }
-                                                       }
-                                               } else {
-                                                       
_pacman_log(PM_LOG_FLOW2, _("unlinking %s"), file);
-                                                       /* Need at here because 
we count only real unlinked files ? */
-                                                       PROGRESS(trans, 
PM_TRANS_PROGRESS_REMOVE_START, pkg->name(), (int)(percent * 100), howmany, 
howmany - remain + 1);
-                                                       position++;
-                                                       if(unlink(line)) {
-                                                               
_pacman_log(PM_LOG_ERROR, _("cannot remove file %s"), file);
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-       return 0;
-}
-
-static
int _pacman_cachedpkg_check_integrity(Package *spkg, __pmtrans_t *trans, 
pmlist_t **data)
{
char str[PATH_MAX], pkgname[PATH_MAX];
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to