xbps-repo: remove repo index file locking, it's unreliable under NFS.
This commit is contained in:
parent
a037b89042
commit
3c379ff78e
3
NEWS
3
NEWS
@ -26,9 +26,6 @@ xbps-0.17 (???):
|
|||||||
|
|
||||||
$ xbps-repo index-clean /path/to/repo
|
$ xbps-repo index-clean /path/to/repo
|
||||||
|
|
||||||
File locking has been implemented for these targets to only allow a client
|
|
||||||
to update the index files.
|
|
||||||
|
|
||||||
xbps-0.16.5 (2012-07-14):
|
xbps-0.16.5 (2012-07-14):
|
||||||
|
|
||||||
* xbps.conf: remove obsolete remote repositories.
|
* xbps.conf: remove obsolete remote repositories.
|
||||||
|
@ -3,7 +3,7 @@ TOPDIR = ../..
|
|||||||
|
|
||||||
BIN = xbps-repo
|
BIN = xbps-repo
|
||||||
OBJS = main.o index.o show.o find-files.o list.o
|
OBJS = main.o index.o show.o find-files.o list.o
|
||||||
OBJS += index-files.o index-lock.o clean.o common.o
|
OBJS += index-files.o clean.o common.o
|
||||||
OBJS += remove-obsoletes.o
|
OBJS += remove-obsoletes.o
|
||||||
OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o
|
OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o
|
||||||
OBJS += ../xbps-bin/state_cb.o ../xbps-bin/list.o
|
OBJS += ../xbps-bin/state_cb.o ../xbps-bin/list.o
|
||||||
|
@ -39,13 +39,13 @@ repo_index_files_clean(struct xbps_handle *xhp, const char *repodir)
|
|||||||
{
|
{
|
||||||
prop_object_t obj;
|
prop_object_t obj;
|
||||||
prop_array_t idx, idxfiles, obsoletes;
|
prop_array_t idx, idxfiles, obsoletes;
|
||||||
char *plist, *plistf, *plistf_lock, *pkgver, *str;
|
char *plist, *plistf, *pkgver, *str;
|
||||||
const char *p, *arch, *ipkgver, *iarch;
|
const char *p, *arch, *ipkgver, *iarch;
|
||||||
size_t x, i;
|
size_t x, i;
|
||||||
int rv = 0, fdlock;
|
int rv = 0;
|
||||||
bool flush = false;
|
bool flush = false;
|
||||||
|
|
||||||
plist = plistf = plistf_lock = pkgver = str = NULL;
|
plist = plistf = pkgver = str = NULL;
|
||||||
idx = idxfiles = obsoletes = NULL;
|
idx = idxfiles = obsoletes = NULL;
|
||||||
|
|
||||||
/* Internalize index-files.plist if found */
|
/* Internalize index-files.plist if found */
|
||||||
@ -55,20 +55,12 @@ repo_index_files_clean(struct xbps_handle *xhp, const char *repodir)
|
|||||||
free(plistf);
|
free(plistf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Acquire exclusive file lock */
|
|
||||||
if ((fdlock = acquire_repo_lock(plistf, &plistf_lock)) == -1) {
|
|
||||||
free(plistf);
|
|
||||||
prop_object_release(idxfiles);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Internalize index.plist */
|
/* Internalize index.plist */
|
||||||
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL) {
|
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL) {
|
||||||
rv = EINVAL;
|
rv = EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if ((idx = prop_array_internalize_from_zfile(plist)) == NULL) {
|
if ((idx = prop_array_internalize_from_zfile(plist)) == NULL) {
|
||||||
release_repo_lock(&plistf_lock, fdlock);
|
|
||||||
rv = EINVAL;
|
rv = EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -131,8 +123,6 @@ repo_index_files_clean(struct xbps_handle *xhp, const char *repodir)
|
|||||||
prop_array_count(idxfiles));
|
prop_array_count(idxfiles));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
release_repo_lock(&plistf_lock, fdlock);
|
|
||||||
|
|
||||||
if (obsoletes)
|
if (obsoletes)
|
||||||
prop_object_release(obsoletes);
|
prop_object_release(obsoletes);
|
||||||
if (idx)
|
if (idx)
|
||||||
@ -155,13 +145,13 @@ repo_index_files_add(struct xbps_handle *xhp, int argc, char **argv)
|
|||||||
prop_dictionary_t pkgprops, pkg_filesd, pkgd;
|
prop_dictionary_t pkgprops, pkg_filesd, pkgd;
|
||||||
prop_array_t files, pkg_cffiles, pkg_files, pkg_links;
|
prop_array_t files, pkg_cffiles, pkg_files, pkg_links;
|
||||||
const char *binpkg, *pkgver, *arch;
|
const char *binpkg, *pkgver, *arch;
|
||||||
char *plist, *repodir, *p, *plist_lock;
|
char *plist, *repodir, *p;
|
||||||
size_t x;
|
size_t x;
|
||||||
int i, fdlock = -1, rv = 0;
|
int i, rv = 0;
|
||||||
bool found, flush;
|
bool found, flush;
|
||||||
|
|
||||||
found = flush = false;
|
found = flush = false;
|
||||||
plist = plist_lock = repodir = p = NULL;
|
plist = repodir = p = NULL;
|
||||||
obj = fileobj = NULL;
|
obj = fileobj = NULL;
|
||||||
pkgprops = pkg_filesd = pkgd = NULL;
|
pkgprops = pkg_filesd = pkgd = NULL;
|
||||||
files = NULL;
|
files = NULL;
|
||||||
@ -175,13 +165,6 @@ repo_index_files_add(struct xbps_handle *xhp, int argc, char **argv)
|
|||||||
rv = ENOMEM;
|
rv = ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
/* Acquire exclusive file lock or wait for it.
|
|
||||||
*/
|
|
||||||
if ((fdlock = acquire_repo_lock(plist, &plist_lock)) == -1) {
|
|
||||||
free(p);
|
|
||||||
free(plist);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* Internalize index-files.plist if found and process argv.
|
* Internalize index-files.plist if found and process argv.
|
||||||
*/
|
*/
|
||||||
@ -365,8 +348,6 @@ repo_index_files_add(struct xbps_handle *xhp, int argc, char **argv)
|
|||||||
prop_array_count(idxfiles));
|
prop_array_count(idxfiles));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
release_repo_lock(&plist_lock, fdlock);
|
|
||||||
|
|
||||||
if (p)
|
if (p)
|
||||||
free(p);
|
free(p);
|
||||||
if (plist)
|
if (plist)
|
||||||
|
@ -1,103 +0,0 @@
|
|||||||
/*-
|
|
||||||
* Copyright (c) 2012 Juan Romero Pardines.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <libgen.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include <xbps_api.h>
|
|
||||||
#include "defs.h"
|
|
||||||
|
|
||||||
int
|
|
||||||
acquire_repo_lock(const char *plist, char **plist_lock)
|
|
||||||
{
|
|
||||||
int try = 0, fd = -1;
|
|
||||||
|
|
||||||
*plist_lock = xbps_xasprintf("%s.lock", plist);
|
|
||||||
assert(*plist_lock);
|
|
||||||
|
|
||||||
fd = open(*plist_lock, O_RDWR);
|
|
||||||
if (fd == -1) {
|
|
||||||
if (errno == ENOENT) {
|
|
||||||
fd = creat(*plist_lock, 0640);
|
|
||||||
if (fd == -1) {
|
|
||||||
fprintf(stderr, "Failed to create "
|
|
||||||
"repository file lock: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Failed to open repository "
|
|
||||||
"file lock: %s\n", strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Acquire the the exclusive file lock or wait until
|
|
||||||
* it's available.
|
|
||||||
*/
|
|
||||||
#define WAIT_SECONDS 30
|
|
||||||
while (lockf(fd, F_TLOCK, 0) < 0) {
|
|
||||||
if (errno == EAGAIN || errno == EACCES) {
|
|
||||||
if (++try < WAIT_SECONDS) {
|
|
||||||
fprintf(stderr,"Repository index file "
|
|
||||||
"is busy! retrying in 1 sec...\n");
|
|
||||||
sleep(1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(stderr, "Failed to acquire repository "
|
|
||||||
"file lock in %d seconds!\n", WAIT_SECONDS);
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
release_repo_lock(char **plist_lock, int fd)
|
|
||||||
{
|
|
||||||
assert(*plist_lock);
|
|
||||||
|
|
||||||
if (fd == -1)
|
|
||||||
return;
|
|
||||||
if (lockf(fd, F_ULOCK, 0) == -1) {
|
|
||||||
fprintf(stderr, "failed to unlock file lock: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
close(fd);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
unlink(*plist_lock);
|
|
||||||
free(*plist_lock);
|
|
||||||
}
|
|
@ -46,29 +46,22 @@ repo_index_clean(struct xbps_handle *xhp, const char *repodir)
|
|||||||
prop_array_t array;
|
prop_array_t array;
|
||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t pkgd;
|
||||||
const char *filen, *pkgver, *arch;
|
const char *filen, *pkgver, *arch;
|
||||||
char *plist, *plist_lock;
|
char *plist;
|
||||||
size_t i, idx = 0;
|
size_t i, idx = 0;
|
||||||
int fdlock, rv = 0;
|
int rv = 0;
|
||||||
bool flush = false;
|
bool flush = false;
|
||||||
|
|
||||||
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL)
|
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((fdlock = acquire_repo_lock(plist, &plist_lock)) == -1) {
|
|
||||||
free(plist);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
array = prop_array_internalize_from_zfile(plist);
|
array = prop_array_internalize_from_zfile(plist);
|
||||||
if (array == NULL) {
|
if (array == NULL) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
xbps_error_printf("xbps-repo: cannot read `%s': %s\n",
|
xbps_error_printf("xbps-repo: cannot read `%s': %s\n",
|
||||||
plist, strerror(errno));
|
plist, strerror(errno));
|
||||||
free(plist);
|
free(plist);
|
||||||
release_repo_lock(&plist_lock, fdlock);
|
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
release_repo_lock(&plist_lock, fdlock);
|
|
||||||
free(plist);
|
free(plist);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -104,7 +97,6 @@ again:
|
|||||||
out:
|
out:
|
||||||
free(plist);
|
free(plist);
|
||||||
prop_object_release(array);
|
prop_object_release(array);
|
||||||
release_repo_lock(&plist_lock, fdlock);
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -123,8 +115,7 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv)
|
|||||||
const char *arch, *oldarch;
|
const char *arch, *oldarch;
|
||||||
char *sha256, *filen, *repodir, *buf, *buf2;
|
char *sha256, *filen, *repodir, *buf, *buf2;
|
||||||
char *tmpfilen = NULL, *tmprepodir = NULL, *plist = NULL;
|
char *tmpfilen = NULL, *tmprepodir = NULL, *plist = NULL;
|
||||||
char *plist_lock = NULL;
|
int i, ret = 0, rv = 0;
|
||||||
int i, ret = 0, rv = 0, fdlock = -1;
|
|
||||||
bool flush = false;
|
bool flush = false;
|
||||||
|
|
||||||
if ((tmprepodir = strdup(argv[1])) == NULL) {
|
if ((tmprepodir = strdup(argv[1])) == NULL) {
|
||||||
@ -137,12 +128,6 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv)
|
|||||||
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL)
|
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Acquire exclusive file lock */
|
|
||||||
if ((fdlock = acquire_repo_lock(plist, &plist_lock)) == -1) {
|
|
||||||
rv = fdlock;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((idx = prop_array_internalize_from_zfile(plist)) == NULL) {
|
if ((idx = prop_array_internalize_from_zfile(plist)) == NULL) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
xbps_error_printf("xbps-repo: cannot read `%s': %s\n",
|
xbps_error_printf("xbps-repo: cannot read `%s': %s\n",
|
||||||
@ -329,8 +314,6 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv)
|
|||||||
printf("index: %u packages registered.\n", prop_array_count(idx));
|
printf("index: %u packages registered.\n", prop_array_count(idx));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
release_repo_lock(&plist_lock, fdlock);
|
|
||||||
|
|
||||||
if (tmprepodir)
|
if (tmprepodir)
|
||||||
free(tmprepodir);
|
free(tmprepodir);
|
||||||
if (plist)
|
if (plist)
|
||||||
|
Loading…
Reference in New Issue
Block a user