xbps_repo_close: only unlock the file lock if repo was opened as such.
If xbps_repo_open() was called with the lock arg set, xbps_repo_close() will now unlock the repo file lock, without the need to set it. This avoids the need to always unlock the file lock even if it wasn't locked previously. This also introduceds an ABI/API break, but this way it's cleaner.
This commit is contained in:
10
lib/repo.c
10
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);
|
||||
|
Reference in New Issue
Block a user