summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2006-10-31 06:39:59 +0000
committerAaron Griffin <aaron@archlinux.org>2006-10-31 06:39:59 +0000
commitaf2fb3324a925af6caa9d53aacac92173fc47885 (patch)
treeb7abb647d27db75a1d937eea24cd5eccac6e5db8 /lib/libalpm/util.c
parent78c0badc9b3629c5156d4bd0733a3e9a1e4e92c6 (diff)
downloadpacman-af2fb3324a925af6caa9d53aacac92173fc47885.tar.xz
Numerous changes:
* Furthered the "lazy caching" to force the pkgcache to read nothing (INFRQ_NONE) by default. Anything requiring package data should now check the infolevel of each package and attempt to update it. This could be ironed out a bit more later (by using the front-end get_info function * Switched to libfetch. Drastic changes to the download code and the callback progress bar functions. Also fixed the return value of _alpm_downloadfiles_forreal. Downloading now supports http, ftp, https, and files urls, along with 'mtime's and numerous other fancy features from libfetch.
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c74
1 files changed, 43 insertions, 31 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 98f16406..2d34ac58 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -138,14 +138,14 @@ int _alpm_makepath(char *path)
strcat(full, ptr);
if(stat(full, &buf)) {
if(mkdir(full, 0755)) {
- free(orig);
+ FREE(orig);
umask(oldmask);
return(1);
}
}
}
}
- free(orig);
+ FREE(orig);
umask(oldmask);
return(0);
}
@@ -302,37 +302,36 @@ int _alpm_rmrf(char *path)
struct dirent *dp;
DIR *dirp;
char name[PATH_MAX];
+ struct stat st;
- 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) {
- sprintf(name, "%s/%s", path, dp->d_name);
- if(strcmp(dp->d_name, "..") && strcmp(dp->d_name, ".")) {
- errflag += _alpm_rmrf(name);
+ if(stat(path, &st) == 0) {
+ if(S_ISREG(st.st_mode)) {
+ if(!unlink(path)) {
+ return(0);
+ } else {
+ if(errno == ENOENT) {
+ return(0);
+ } else {
+ /* not a directory */
+ return(1);
}
}
- }
- closedir(dirp);
- if(rmdir(path)) {
- errflag++;
+ } else if(S_ISDIR(st.st_mode)) {
+ if((dirp = opendir(path)) == (DIR *)-1) {
+ return(1);
+ }
+ for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
+ if(dp->d_ino) {
+ sprintf(name, "%s/%s", path, dp->d_name);
+ if(strcmp(dp->d_name, "..") && strcmp(dp->d_name, ".")) {
+ errflag += _alpm_rmrf(name);
+ }
+ }
+ }
+ closedir(dirp);
+ if(rmdir(path)) {
+ errflag++;
+ }
}
return(errflag);
}
@@ -605,6 +604,7 @@ int _alpm_check_freespace(pmtrans_t *trans, pmlist_t **data)
return(0);
}
}
+#endif
/* match a string against a regular expression */
int _alpm_reg_match(char *string, char *pattern)
@@ -620,6 +620,18 @@ int _alpm_reg_match(char *string, char *pattern)
return(!(result));
}
-#endif
+/* convert a time_t to a string - buffer MUST be large enough for
+ * YYYYMMDDHHMMSS - 15 chars */
+void _alpm_time2string(time_t t, char *buffer)
+{
+ if(buffer) {
+ struct tm *lt;
+ lt = localtime(&t);
+ sprintf(buffer, "%4d%02d%02d%02d%02d%02d",
+ lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday,
+ lt->tm_hour, lt->tm_min, lt->tm_sec);
+ buffer[14] = '\0';
+ }
+}
/* vim: set ts=2 sw=2 noet: */