[pacman-dev] [PATCH] Remove rmrf function from frontend
Laszlo Papp
djszapi2 at gmail.com
Sat Oct 24 14:11:02 EDT 2009
* The alpm_rmrf function is available from the api, which does the
same as this function did, with a small sanity check.
* It was worth to establish alpm_rmrf for _alpm_rmrf for pacman frontend
as a wrapper to be able to use it in the future or for other frontend, so the
function declaration was deleted in the frontend, and the new alpm_rmrf
wrapper function was established for future usage with SYMEXPORT modifier.
Signed-off-by: Laszlo Papp <djszapi at archlinux.us>
---
What about this approach ?
lib/libalpm/alpm.h | 2 ++
lib/libalpm/util.c | 14 +++++++++++++-
src/pacman/sync.c | 2 +-
src/pacman/util.c | 43 -------------------------------------------
src/pacman/util.h | 1 -
5 files changed, 16 insertions(+), 46 deletions(-)
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index c433b73..3e24fd3 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -467,6 +467,8 @@ const char *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict);
/* checksums */
char *alpm_compute_md5sum(const char *name);
+int alpm_rmrf(char *path);
+
/*
* Errors
*/
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index d910809..1340da9 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -79,6 +79,18 @@ char* strsep(char** str, const char* delims)
}
#endif
+
+/** does the same thing as 'rm -rf'
+ * @param path name of the file to delete
+ */
+int SYMEXPORT alpm_rmrf(char *path)
+{
+ ALPM_LOG_FUNC;
+
+ ASSERT(path != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ return(_alpm_rmrf(path));
+}
+
int _alpm_makepath(const char *path)
{
return(_alpm_makepath_mode(path, 0755));
@@ -315,7 +327,7 @@ int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int
st = archive_entry_stat(entry);
entryname = archive_entry_pathname(entry);
-
+
if(S_ISREG(st->st_mode)) {
archive_entry_set_perm(entry, 0644);
} else if(S_ISDIR(st->st_mode)) {
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index a2ef616..0164ca9 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -90,7 +90,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
continue;
}
- if(rmrf(path)) {
+ if(alpm_rmrf(path)) {
pm_fprintf(stderr, PM_LOG_ERROR,
_("could not remove repository directory\n"));
closedir(dir);
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 1143bef..9adc0e5 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -99,49 +99,6 @@ int getcols(void)
return 0;
}
-/* does the same thing as 'rm -rf' */
-int rmrf(const char *path)
-{
- int errflag = 0;
- struct dirent *dp;
- DIR *dirp;
-
- if(!unlink(path)) {
- return(0);
- } else {
- if(errno == ENOENT) {
- return(0);
- } else if(errno == EPERM) {
- /* fallthrough */
- } else if(errno == EISDIR) {
- /* fallthrough */
- } else if(errno == ENOTDIR) {
- return(1);
- } else {
- /* not a directory */
- return(1);
- }
-
- if((dirp = opendir(path)) == (DIR *)-1) {
- return(1);
- }
- for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
- if(dp->d_ino) {
- char name[PATH_MAX];
- sprintf(name, "%s/%s", path, dp->d_name);
- if(strcmp(dp->d_name, "..") && strcmp(dp->d_name, ".")) {
- errflag += rmrf(name);
- }
- }
- }
- closedir(dirp);
- if(rmdir(path)) {
- errflag++;
- }
- return(errflag);
- }
-}
-
/** Parse the basename of a program from a path.
* Grabbed from the uClibc source.
* @param path path to parse basename from
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 7a8c39d..30e5996 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -41,7 +41,6 @@ int trans_init(pmtransflag_t flags);
int trans_release(void);
int needs_root(void);
int getcols(void);
-int rmrf(const char *path);
char *mbasename(const char *path);
char *mdirname(const char *path);
void indentprint(const char *str, int indent);
--
1.6.5
More information about the pacman-dev
mailing list