This change is an incomplete attempt to allow tar to have read access to archives published on HTTP servers using wget. * src/buffer.c (_open_archive): start wget using popen. * configure.ac: add --with-wget and check for its presence.
--- The main aim of this patch is to reduce the number of keystrokes. Instead of 'wget http://example.org/foo.tar && tar -xf foo.tar' now you're able to 'tar -xf http://example.org/foo.tar'. I'd be grateful for your comments regarding this idea. The patch is far from being complete but it offers some basic functionality. So far it works only for uncompressed tarballs. I'm a novice when it comes to tar's code and GNU coding style so please let me know if I'm doing it wrong. Best regards, Jan StÄpieÅ --- configure.ac | 5 +++++ src/buffer.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index c3a3af7..8ff71fe 100644 --- a/configure.ac +++ b/configure.ac @@ -243,6 +243,11 @@ AC_ARG_ENABLE(backup-scripts, ;; esac]) +AC_ARG_WITH([wget], + AC_HELP_STRING([--with-wget], [use wget for remote file fetching])) +AS_IF([test "x$with_wget" = "xyes"], + [AC_DEFINE([WITH_WGET], [1], [Should we use wget.])]) + AC_SUBST(BACKUP_SED_COND) if date +%Y-%m-%d 2>/dev/null >&2; then BACKUP_SED_COND='/^\#ELSE_DATE_FORMAT_OK/,/^\#ENDIF_DATE_FORMAT_OK/d;/^\#IF_DATE_FORMAT_OK/d' diff --git a/src/buffer.c b/src/buffer.c index ef4bbac..7f11d0d 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -32,6 +32,7 @@ #include "common.h" #include <rmt.h> +#include <config.h> /* Number of retries before giving up on read. */ #define READ_ERROR_MAX 10 @@ -651,6 +652,34 @@ _open_archive (enum access_mode wanted_access) break; } } +#ifdef WITH_WGET + else if (!strncmp (archive_name_array[0], "http://", strlen("http://")) || + !strncmp (archive_name_array[0], "https://", strlen("https://"))) + { + if (wanted_access == ACCESS_READ) + { + bool shortfile; + enum compress_type type; + char* command = alloca(sizeof(char) * (strlen("wget -qO- ") + + strlen(archive_name_array[0]) + 1)); + sprintf(command, "wget -qO- %s", archive_name_array[0]); + archive = fileno(popen(command, "r")); + read_full_records = true; + + type = check_compressed_archive (&shortfile); + if (type != ct_tar && type != ct_none) + FATAL_ERROR ((0, 0, + _("Archive is compressed. Use %s option"), + compress_option (type))); + if (shortfile) + ERROR ((0, 0, _("This does not look like a tar archive"))); + } + else + { + ERROR ((0, 0, _("Remote archives are available only for reading"))); + } + } +#endif /* WITH_WGET */ else if (verify_option) archive = rmtopen (archive_name_array[0], O_RDWR | O_CREAT | O_BINARY, MODE_RW, rsh_command_option); -- 1.7.0.4
