diff --git a/bin/xbps-rindex/index-add.c b/bin/xbps-rindex/index-add.c index 4da652b5..22e6f669 100644 --- a/bin/xbps-rindex/index-add.c +++ b/bin/xbps-rindex/index-add.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012-2014 Juan Romero Pardines. + * Copyright (c) 2012-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -216,7 +216,7 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force out: if (repo) - xbps_repo_close(repo, true); + xbps_repo_close(repo); if (tmprepodir) free(tmprepodir); diff --git a/bin/xbps-rindex/index-clean.c b/bin/xbps-rindex/index-clean.c index 9d90e649..86189fbd 100644 --- a/bin/xbps-rindex/index-clean.c +++ b/bin/xbps-rindex/index-clean.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012-2014 Juan Romero Pardines. + * Copyright (c) 2012-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -155,7 +155,7 @@ index_clean(struct xbps_handle *xhp, const char *repodir) xbps_dictionary_count(idx)); out: - xbps_repo_close(repo, true); + xbps_repo_close(repo); if (idx) xbps_object_release(idx); if (idxmeta) diff --git a/bin/xbps-rindex/remove-obsoletes.c b/bin/xbps-rindex/remove-obsoletes.c index 2ece1d2e..d9375765 100644 --- a/bin/xbps-rindex/remove-obsoletes.c +++ b/bin/xbps-rindex/remove-obsoletes.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012-2014 Juan Romero Pardines. + * Copyright (c) 2012-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -154,7 +154,7 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir) (void)closedir(dirp); rv = xbps_array_foreach_cb_multi(xhp, array, NULL, cleaner_cb, repo); - xbps_repo_close(repo, false); + xbps_repo_close(repo); xbps_object_release(array); return rv; diff --git a/bin/xbps-rindex/sign.c b/bin/xbps-rindex/sign.c index 6efea04a..80798ebf 100644 --- a/bin/xbps-rindex/sign.c +++ b/bin/xbps-rindex/sign.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2013-2014 Juan Romero Pardines. + * Copyright (c) 2013-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -302,7 +302,7 @@ out: rsa = NULL; } if (repo) { - xbps_repo_close(repo, true); + xbps_repo_close(repo); } return rv ? -1 : 0; } diff --git a/include/xbps.h.in b/include/xbps.h.in index 3329632e..27735ea2 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -48,7 +48,7 @@ * * This header documents the full API for the XBPS Library. */ -#define XBPS_API_VERSION "20150110-1" +#define XBPS_API_VERSION "20150111" #ifndef XBPS_VERSION #define XBPS_VERSION "UNSET" @@ -1257,6 +1257,7 @@ struct xbps_repo { * @private */ int fd; + bool is_locked; /** * var is_remote * @@ -1418,9 +1419,8 @@ struct xbps_repo *xbps_repo_open(struct xbps_handle *xhp, const char *url, bool * Closes a repository object and releases resources. * * @param[in] repo The repository object to close. - * @param[in] lock Set it to true to release the POSIX file lock. */ -void xbps_repo_close(struct xbps_repo *repo, bool lock); +void xbps_repo_close(struct xbps_repo *repo); /** * diff --git a/lib/repo.c b/lib/repo.c index ca4be72c..b02e00a9 100644 --- a/lib/repo.c +++ b/lib/repo.c @@ -225,10 +225,12 @@ xbps_repo_open(struct xbps_handle *xhp, const char *url, bool lock) /* * Open the repository archive. */ - if (lock) + if (lock) { repo->fd = open(repofile, O_RDWR); - else + repo->is_locked = true; + } else { repo->fd = open(repofile, O_RDONLY); + } if (repo->fd == -1) { int rv = errno; @@ -252,7 +254,7 @@ out: } void -xbps_repo_close(struct xbps_repo *repo, bool lock) +xbps_repo_close(struct xbps_repo *repo) { assert(repo); @@ -267,7 +269,7 @@ xbps_repo_close(struct xbps_repo *repo, bool lock) xbps_object_release(repo->idxmeta); repo->idxmeta = NULL; } - if (lock && lockf(repo->fd, F_ULOCK, 0) == -1) + if (repo->is_locked && lockf(repo->fd, F_ULOCK, 0) == -1) xbps_dbg_printf(repo->xhp, "[repo] failed to unlock %s: %s\n", repo->uri, strerror(errno)); close(repo->fd); diff --git a/lib/rpool.c b/lib/rpool.c index a8a61a95..5f64719e 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -98,7 +98,7 @@ xbps_rpool_release(struct xbps_handle *xhp _unused) while ((repo = SIMPLEQ_FIRST(&rpool_queue))) { SIMPLEQ_REMOVE(&rpool_queue, repo, xbps_repo, entries); - xbps_repo_close(repo, true); + xbps_repo_close(repo); free(repo); } if (xhp->repositories)