[pacman-dev] [PATCH 1/2] add libarchive compatability object
This allows us to support both libarchive 2.8.x as well as 3.x without deprecation warnings on compile. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Decided to just do this since libarchive 3.x has been a little scary from a stability standpoint. Compile tested on both 3.1.1 and 3.0.4. lib/libalpm/Makefile.am | 1 + lib/libalpm/libarchive-compat.c | 65 +++++++++++++++++++++++++++++++++++++++++ lib/libalpm/libarchive-compat.h | 33 +++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 lib/libalpm/libarchive-compat.c create mode 100644 lib/libalpm/libarchive-compat.h diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am index 5cf66b9..55fec9c 100644 --- a/lib/libalpm/Makefile.am +++ b/lib/libalpm/Makefile.am @@ -44,6 +44,7 @@ libalpm_la_SOURCES = \ graph.h graph.c \ group.h group.c \ handle.h handle.c \ + libarchive-compat.h libarchive-compat.c \ log.h log.c \ package.h package.c \ pkghash.h pkghash.c \ diff --git a/lib/libalpm/libarchive-compat.c b/lib/libalpm/libarchive-compat.c new file mode 100644 index 0000000..56af2e1 --- /dev/null +++ b/lib/libalpm/libarchive-compat.c @@ -0,0 +1,65 @@ +/* + * libarchive-compat.c + * + * Copyright (c) 2013 Pacman Development Team <pacman-dev@archlinux.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdint.h> + +#include "libarchive-compat.h" + +int _alpm_archive_read_free(struct archive *archive) { +#if ARCHIVE_VERSION_NUMBER >= 3000000 + return archive_read_free(archive); +#else + return archive_read_finish(archive); +#endif +} + +int64_t _alpm_archive_compressed_ftell(struct archive *archive) { +#if ARCHIVE_VERSION_NUMBER >= 3000000 + return archive_filter_bytes(archive, -1); +#else + return archive_position_compressed(archive); +#endif +} + +int _alpm_archive_read_open_file(struct archive *archive, + const char *filename, size_t block_size) { +#if ARCHIVE_VERSION_NUMBER >= 3000000 + return archive_read_open_filename(archive, filename, block_size); +#else + return archive_read_open_file(archive, filename, block_size); +#endif +} + +int _alpm_archive_filter_code(struct archive *archive) { +#if ARCHIVE_VERSION_NUMBER >= 3000000 + return archive_filter_code(archive, 0); +#else + return archive_compression(archive); +#endif +} + +int _alpm_archive_read_support_filter_all(struct archive *archive) { +#if ARCHIVE_VERSION_NUMBER >= 3000000 + return archive_read_support_filter_all(archive); +#else + return archive_read_support_compression_all(archive); +#endif +} + +/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/libarchive-compat.h b/lib/libalpm/libarchive-compat.h new file mode 100644 index 0000000..a1b379e --- /dev/null +++ b/lib/libalpm/libarchive-compat.h @@ -0,0 +1,33 @@ +/* + * libarchive-compat.h + * + * Copyright (c) 2013 Pacman Development Team <pacman-dev@archlinux.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef _LIBARCHIVE_H +#define _LIBARCHIVE_H + +#include <archive.h> + +int _alpm_archive_read_free(struct archive *archive); +int64_t _alpm_archive_compressed_ftell(struct archive *archive); +int _alpm_archive_read_open_file(struct archive *archive, + const char *filename, size_t block_size); +int _alpm_archive_filter_code(struct archive *archive); +int _alpm_archive_read_support_filter_all(struct archive *archive); + +#endif /* _LIBARCHIVE_H */ + +/* vim: set ts=2 sw=2 noet: */ -- 1.8.1.1
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- lib/libalpm/add.c | 7 ++++--- lib/libalpm/be_local.c | 7 ++++--- lib/libalpm/be_package.c | 11 ++++++----- lib/libalpm/be_sync.c | 5 +++-- lib/libalpm/util.c | 7 ++++--- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 9b67813..a828435 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -37,6 +37,7 @@ #include "alpm.h" #include "alpm_list.h" #include "handle.h" +#include "libarchive-compat.h" #include "trans.h" #include "util.h" #include "log.h" @@ -555,7 +556,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, if(chdir(handle->root) != 0) { _alpm_log(handle, ALPM_LOG_ERROR, _("could not change directory to %s (%s)\n"), handle->root, strerror(errno)); - archive_read_finish(archive); + _alpm_archive_read_free(archive); CLOSE(fd); ret = -1; goto cleanup; @@ -577,7 +578,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, /* Using compressed size for calculations here, as newpkg->isize is not * exact when it comes to comparing to the ACTUAL uncompressed size * (missing metadata sizes) */ - int64_t pos = archive_position_compressed(archive); + int64_t pos = _alpm_archive_compressed_ftell(archive); percent = (pos * 100) / newpkg->size; if(percent >= 100) { percent = 100; @@ -597,7 +598,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, /* extract the next file from the archive */ errors += extract_single_file(handle, archive, entry, newpkg, oldpkg); } - archive_read_finish(archive); + _alpm_archive_read_free(archive); CLOSE(fd); /* restore the old cwd if we have it */ diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 0f60b6d..564e109 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -35,6 +35,7 @@ /* libalpm */ #include "db.h" #include "alpm_list.h" +#include "libarchive-compat.h" #include "log.h" #include "util.h" #include "alpm.h" @@ -241,11 +242,11 @@ static struct archive *_cache_mtree_open(alpm_pkg_t *pkg) archive_read_support_filter_gzip(mtree); archive_read_support_format_mtree(mtree); - if((r = archive_read_open_file(mtree, mtfile, ALPM_BUFFER_SIZE))) { + if((r = _alpm_archive_read_open_file(mtree, mtfile, ALPM_BUFFER_SIZE))) { _alpm_log(pkg->handle, ALPM_LOG_ERROR, _("error while reading file %s: %s\n"), mtfile, archive_error_string(mtree)); pkg->handle->pm_errno = ALPM_ERR_LIBARCHIVE; - archive_read_finish(mtree); + _alpm_archive_read_free(mtree); goto error; } @@ -279,7 +280,7 @@ static int _cache_mtree_next(const alpm_pkg_t UNUSED *pkg, static int _cache_mtree_close(const alpm_pkg_t UNUSED *pkg, struct archive *mtree) { - return archive_read_finish(mtree); + return _alpm_archive_read_free(mtree); } static int _cache_force_load(alpm_pkg_t *pkg) diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 18fc14a..cc430b1 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -32,6 +32,7 @@ /* libalpm */ #include "alpm_list.h" #include "alpm.h" +#include "libarchive-compat.h" #include "util.h" #include "log.h" #include "handle.h" @@ -74,7 +75,7 @@ static void *_package_changelog_open(alpm_pkg_t *pkg) changelog = malloc(sizeof(struct package_changelog)); if(!changelog) { pkg->handle->pm_errno = ALPM_ERR_MEMORY; - archive_read_finish(archive); + _alpm_archive_read_free(archive); CLOSE(fd); return NULL; } @@ -84,7 +85,7 @@ static void *_package_changelog_open(alpm_pkg_t *pkg) } } /* we didn't find a changelog */ - archive_read_finish(archive); + _alpm_archive_read_free(archive); CLOSE(fd); errno = ENOENT; @@ -124,7 +125,7 @@ static int _package_changelog_close(const alpm_pkg_t UNUSED *pkg, void *fp) { int ret; struct package_changelog *changelog = fp; - ret = archive_read_finish(changelog->archive); + ret = _alpm_archive_read_free(changelog->archive); CLOSE(changelog->fd); free(changelog); return ret; @@ -471,7 +472,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, goto pkg_invalid; } - archive_read_finish(archive); + _alpm_archive_read_free(archive); CLOSE(fd); /* internal fields for package struct */ @@ -503,7 +504,7 @@ pkg_invalid: handle->pm_errno = ALPM_ERR_PKG_INVALID; error: _alpm_pkg_free(newpkg); - archive_read_finish(archive); + _alpm_archive_read_free(archive); if(fd >= 0) { CLOSE(fd); } diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index a5a2c10..58a9c16 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -31,6 +31,7 @@ /* libalpm */ #include "util.h" #include "log.h" +#include "libarchive-compat.h" #include "alpm.h" #include "alpm_list.h" #include "package.h" @@ -383,7 +384,7 @@ static size_t estimate_package_count(struct stat *st, struct archive *archive) { int per_package; - switch(archive_compression(archive)) { + switch(_alpm_archive_filter_code(archive)) { case ARCHIVE_COMPRESSION_NONE: per_package = 3015; break; @@ -471,7 +472,7 @@ static int sync_db_populate(alpm_db_t *db) count, db->treename); cleanup: - archive_read_finish(archive); + _alpm_archive_read_free(archive); if(fd >= 0) { CLOSE(fd); } diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 5960be6..f4c33a0 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -49,6 +49,7 @@ /* libalpm */ #include "util.h" #include "log.h" +#include "libarchive-compat.h" #include "alpm.h" #include "alpm_list.h" #include "handle.h" @@ -240,7 +241,7 @@ int _alpm_open_archive(alpm_handle_t *handle, const char *path, RET_ERR(handle, ALPM_ERR_LIBARCHIVE, -1); } - archive_read_support_compression_all(*archive); + _alpm_archive_read_support_filter_all(*archive); archive_read_support_format_all(*archive); _alpm_log(handle, ALPM_LOG_DEBUG, "opening archive %s\n", path); @@ -271,7 +272,7 @@ int _alpm_open_archive(alpm_handle_t *handle, const char *path, return fd; error: - archive_read_finish(*archive); + _alpm_archive_read_free(*archive); *archive = NULL; if(fd >= 0) { CLOSE(fd); @@ -392,7 +393,7 @@ int _alpm_unpack(alpm_handle_t *handle, const char *path, const char *prefix, cleanup: umask(oldmask); - archive_read_finish(archive); + _alpm_archive_read_free(archive); CLOSE(fd); if(cwdfd >= 0) { if(fchdir(cwdfd) != 0) { -- 1.8.1.1
On Mon, Jan 28, 2013 at 7:23 PM, Dave Reisner <dreisner@archlinux.org> wrote:
This allows us to support both libarchive 2.8.x as well as 3.x without deprecation warnings on compile.
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Decided to just do this since libarchive 3.x has been a little scary from a stability standpoint. Compile tested on both 3.1.1 and 3.0.4.
Apparently patches don't sit more than two hours before being pulled and pushed to master now. :) Reviewing anyway. It is silly to do one-liners in a C file where they can't be inlined; I would have done everything in the .h file itself and then the compiler could work its magic to remove these redirections completely. -Dan
lib/libalpm/Makefile.am | 1 + lib/libalpm/libarchive-compat.c | 65 +++++++++++++++++++++++++++++++++++++++++ lib/libalpm/libarchive-compat.h | 33 +++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 lib/libalpm/libarchive-compat.c create mode 100644 lib/libalpm/libarchive-compat.h
diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am index 5cf66b9..55fec9c 100644 --- a/lib/libalpm/Makefile.am +++ b/lib/libalpm/Makefile.am @@ -44,6 +44,7 @@ libalpm_la_SOURCES = \ graph.h graph.c \ group.h group.c \ handle.h handle.c \ + libarchive-compat.h libarchive-compat.c \ log.h log.c \ package.h package.c \ pkghash.h pkghash.c \ diff --git a/lib/libalpm/libarchive-compat.c b/lib/libalpm/libarchive-compat.c new file mode 100644 index 0000000..56af2e1 --- /dev/null +++ b/lib/libalpm/libarchive-compat.c @@ -0,0 +1,65 @@ +/* + * libarchive-compat.c + * + * Copyright (c) 2013 Pacman Development Team <pacman-dev@archlinux.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdint.h> + +#include "libarchive-compat.h" + +int _alpm_archive_read_free(struct archive *archive) { +#if ARCHIVE_VERSION_NUMBER >= 3000000 + return archive_read_free(archive); +#else + return archive_read_finish(archive); +#endif +} + +int64_t _alpm_archive_compressed_ftell(struct archive *archive) { +#if ARCHIVE_VERSION_NUMBER >= 3000000 + return archive_filter_bytes(archive, -1); +#else + return archive_position_compressed(archive); +#endif +} + +int _alpm_archive_read_open_file(struct archive *archive, + const char *filename, size_t block_size) { +#if ARCHIVE_VERSION_NUMBER >= 3000000 + return archive_read_open_filename(archive, filename, block_size); +#else + return archive_read_open_file(archive, filename, block_size); +#endif +} + +int _alpm_archive_filter_code(struct archive *archive) { +#if ARCHIVE_VERSION_NUMBER >= 3000000 + return archive_filter_code(archive, 0); +#else + return archive_compression(archive); +#endif +} + +int _alpm_archive_read_support_filter_all(struct archive *archive) { +#if ARCHIVE_VERSION_NUMBER >= 3000000 + return archive_read_support_filter_all(archive); +#else + return archive_read_support_compression_all(archive); +#endif +} + +/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/libarchive-compat.h b/lib/libalpm/libarchive-compat.h new file mode 100644 index 0000000..a1b379e --- /dev/null +++ b/lib/libalpm/libarchive-compat.h @@ -0,0 +1,33 @@ +/* + * libarchive-compat.h + * + * Copyright (c) 2013 Pacman Development Team <pacman-dev@archlinux.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef _LIBARCHIVE_H +#define _LIBARCHIVE_H + +#include <archive.h> + +int _alpm_archive_read_free(struct archive *archive); +int64_t _alpm_archive_compressed_ftell(struct archive *archive); +int _alpm_archive_read_open_file(struct archive *archive, + const char *filename, size_t block_size); +int _alpm_archive_filter_code(struct archive *archive); +int _alpm_archive_read_support_filter_all(struct archive *archive); + +#endif /* _LIBARCHIVE_H */ + +/* vim: set ts=2 sw=2 noet: */ -- 1.8.1.1
On 29/01/13 13:42, Dan McGee wrote:
On Mon, Jan 28, 2013 at 7:23 PM, Dave Reisner <dreisner@archlinux.org> wrote:
This allows us to support both libarchive 2.8.x as well as 3.x without deprecation warnings on compile.
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Decided to just do this since libarchive 3.x has been a little scary from a stability standpoint. Compile tested on both 3.1.1 and 3.0.4.
Apparently patches don't sit more than two hours before being pulled and pushed to master now. :) Reviewing anyway.
Yeah... I was doing a patch round up and figured any further reviews were unlikely. I'll add a "have waited for a reasonable amount of time for review" to the "must go to the mailing list" requirement I am enforcing. Allan
On Mon, Jan 28, 2013 at 10:04 PM, Allan McRae <allan@archlinux.org> wrote:
On 29/01/13 13:42, Dan McGee wrote:
On Mon, Jan 28, 2013 at 7:23 PM, Dave Reisner <dreisner@archlinux.org> wrote:
This allows us to support both libarchive 2.8.x as well as 3.x without deprecation warnings on compile.
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Decided to just do this since libarchive 3.x has been a little scary from a stability standpoint. Compile tested on both 3.1.1 and 3.0.4.
Apparently patches don't sit more than two hours before being pulled and pushed to master now. :) Reviewing anyway.
Yeah... I was doing a patch round up and figured any further reviews were unlikely.
I'll add a "have waited for a reasonable amount of time for review" to the "must go to the mailing list" requirement I am enforcing.
No big deal, not like I've been on top of things even remotely lately. This one just caught my eye while coming home from the airport and was pushed before I even got home. :) If Dave doesn't reply in the next day or so, I'd be happy to send a quick patch implementing what I'm talking about for review. -Dan
participants (3)
-
Allan McRae
-
Dan McGee
-
Dave Reisner