This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=cf6060588dd3305cb159d45aa361e78777344153 commit cf6060588dd3305cb159d45aa361e78777344153 Author: Guillem Jover <[email protected]> AuthorDate: Sun Apr 19 17:23:34 2020 +0200 u-a: Add general purpose non-failing functions for admin directory access This will make possible to apply different logic to the administrative directory access and to the filesystem access. --- debian/changelog | 2 ++ utils/update-alternatives.c | 27 +++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 275ed5823..383ce62e1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -119,6 +119,8 @@ dpkg (1.20.1) UNRELEASED; urgency=medium - update-alternatives: Parametrize option names in output strings. - update-alternatives: Move logging function close to output functions. - update-alternatives: Move argument parsing functions close to main(). + - update-alternatives: Add general purpose non-failing functions for + administrative directory access. * Build system: - Handle .git being a plain file when getting the dpkg tree version. - Add debian/changelog as a Changes file to the CPAN distribution. diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c index 3006457d0..e36a6263e 100644 --- a/utils/update-alternatives.c +++ b/utils/update-alternatives.c @@ -462,6 +462,29 @@ rename_mv(const char *src, const char *dst) return false; } +static void +xrename(const char *src, const char *dst) +{ + if (!rename_mv(src, dst)) + syserr(_("unable to install '%.250s' as '%.250s'"), src, dst); +} + +static void DPKG_ATTR_PRINTF(1) +xunlink_args(const char *fmt, ...) +{ + va_list args; + char *path; + + va_start(args, fmt); + path = xvasprintf(fmt, args); + va_end(args); + + if (unlink(path) < 0 && errno != ENOENT) + syserr(_("unable to remove '%s'"), path); + + free(path); +} + static int make_path(const char *pathname, mode_t mode) { @@ -1452,7 +1475,7 @@ alternative_save(struct alternative *a) syserr(_("unable to close file '%s'"), ctx.filename); /* Put in place atomically. */ - checked_mv(filenew, file); + xrename(filenew, file); free(filenew); free(file); @@ -1888,7 +1911,7 @@ alternative_remove_files(struct alternative *a) checked_rm_args("%s/%s", altdir, sl->name); } /* Drop admin file */ - checked_rm_args("%s/%s", admdir, a->master_name); + xunlink_args("%s/%s", admdir, a->master_name); } static const char * -- Dpkg.Org's dpkg

