diff options
author | Dan McGee <dan@archlinux.org> | 2008-06-16 02:15:36 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2008-06-16 05:52:27 +0200 |
commit | 29bf6814f74096e5d8ea22058e638eb362717b8a (patch) | |
tree | 1b608ba8071c1c7e52808a4b178ba8225ef6d2b1 /lib/libalpm/be_files.c | |
parent | 7ff5a917fd0a91cd03ba61419a57053e4ae17e92 (diff) | |
download | pacman-29bf6814f74096e5d8ea22058e638eb362717b8a.tar.gz pacman-29bf6814f74096e5d8ea22058e638eb362717b8a.tar.xz |
Use access() instead of stat() when possible
We were using the stat() system call in quite a few places when we didn't
actually need anything the stat struct returned- we were simply checking for
file existence. access() will be more efficient in those cases.
Before (strace pacman -Ss pacman):
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
33.16 0.005987 0 19016 stat64
After:
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
34.85 0.003863 0 12633 1 access
7.95 0.000881 0 6391 7 stat64
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/be_files.c')
-rw-r--r-- | lib/libalpm/be_files.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index 12c60b24..f5d4e826 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -355,7 +355,6 @@ static char *get_pkgpath(pmdb_t *db, pmpkg_t *info) int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) { FILE *fp = NULL; - struct stat buf; char path[PATH_MAX]; char line[513]; char *pkgpath = NULL; @@ -393,7 +392,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) pkgpath = get_pkgpath(db, info); - if(stat(pkgpath, &buf)) { + if(access(pkgpath, F_OK)) { /* directory doesn't exist or can't be opened */ _alpm_log(PM_LOG_DEBUG, "cannot find '%s-%s' in db '%s'\n", info->name, info->version, db->treename); @@ -631,7 +630,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) /* INSTALL */ if(inforeq & INFRQ_SCRIPTLET) { snprintf(path, PATH_MAX, "%sinstall", pkgpath); - if(!stat(path, &buf)) { + if(access(path, F_OK) == 0) { info->scriptlet = 1; } } |