Commit 52dae672 authored by Stefan Tomanek's avatar Stefan Tomanek
Browse files

store URL to xattr of downloaded file

It is often convinient to track back the source of a once downloaded
file; this patch makes wget store the source URL by using the extended
attributes (if supported by the file system and enabled by --xattr-url).
parent 1b260850
......@@ -50,7 +50,7 @@ wget_SOURCES = cmpt.c connect.c convert.c cookies.c ftp.c \
http.h http-ntlm.h init.h log.h mswindows.h netrc.h \
options.h progress.h ptimer.h recur.h res.h retr.h \
spider.h ssl.h sysdep.h url.h utils.h wget.h iri.h \
exits.h gettext.h
exits.h gettext.h xattr.c xattr.h
nodist_wget_SOURCES = version.c
EXTRA_wget_SOURCES = mswindows.c iri.c
LDADD = $(LIBOBJS) ../lib/libgnu.a @MD5_LDADD@
......
......@@ -120,7 +120,7 @@ am__libunittest_a_SOURCES_DIST = cmpt.c connect.c convert.c cookies.c \
hash.h host.h html-parse.h html-url.h http.h http-ntlm.h \
init.h log.h mswindows.h netrc.h options.h progress.h ptimer.h \
recur.h res.h retr.h spider.h ssl.h sysdep.h url.h utils.h \
wget.h iri.h exits.h gettext.h test.c test.h
wget.h iri.h exits.h gettext.h test.c test.h xattr.c xattr.h
@IRI_IS_ENABLED_TRUE@am__objects_1 = libunittest_a-iri.$(OBJEXT)
am__objects_2 = libunittest_a-cmpt.$(OBJEXT) \
libunittest_a-connect.$(OBJEXT) \
......@@ -159,7 +159,7 @@ am__wget_SOURCES_DIST = cmpt.c connect.c convert.c cookies.c ftp.c \
hash.h host.h html-parse.h html-url.h http.h http-ntlm.h \
init.h log.h mswindows.h netrc.h options.h progress.h ptimer.h \
recur.h res.h retr.h spider.h ssl.h sysdep.h url.h utils.h \
wget.h iri.h exits.h gettext.h
wget.h iri.h exits.h gettext.h xattr.h xattr.c
@IRI_IS_ENABLED_TRUE@am__objects_3 = iri.$(OBJEXT)
am_wget_OBJECTS = cmpt.$(OBJEXT) connect.$(OBJEXT) convert.$(OBJEXT) \
cookies.$(OBJEXT) ftp.$(OBJEXT) css.$(OBJEXT) \
......@@ -170,6 +170,7 @@ am_wget_OBJECTS = cmpt.$(OBJEXT) connect.$(OBJEXT) convert.$(OBJEXT) \
ptimer.$(OBJEXT) recur.$(OBJEXT) res.$(OBJEXT) retr.$(OBJEXT) \
snprintf.$(OBJEXT) spider.$(OBJEXT) url.$(OBJEXT) \
utils.$(OBJEXT) exits.$(OBJEXT) build_info.$(OBJEXT) \
xattr.$(OBJEXT) \
$(am__objects_3)
nodist_wget_OBJECTS = version.$(OBJEXT)
wget_OBJECTS = $(am_wget_OBJECTS) $(nodist_wget_OBJECTS)
......@@ -678,7 +679,7 @@ wget_SOURCES = cmpt.c connect.c convert.c cookies.c ftp.c \
http.h http-ntlm.h init.h log.h mswindows.h netrc.h \
options.h progress.h ptimer.h recur.h res.h retr.h \
spider.h ssl.h sysdep.h url.h utils.h wget.h iri.h \
exits.h gettext.h
exits.h gettext.h xattr.h xattr.c
nodist_wget_SOURCES = version.c
EXTRA_wget_SOURCES = mswindows.c iri.c
......
......@@ -51,6 +51,8 @@ as that of the covered work. */
#include "convert.h" /* for downloaded_file */
#include "recur.h" /* for INFINITE_RECURSION */
#include "xattr.h"
#ifdef __VMS
# include "vms.h"
#endif /* def __VMS */
......@@ -1206,6 +1208,11 @@ Error in server response, closing control connection.\n"));
else
fp = output_stream;
if (opt.xattr_url && file_exists_p(con->target))
{
set_xattr( u, con->target );
}
if (passed_expected_bytes)
{
print_length (passed_expected_bytes, restval, true);
......
......@@ -62,6 +62,8 @@ as that of the covered work. */
#include "convert.h"
#include "spider.h"
#include "xattr.h"
#ifdef TESTING
#include "test.h"
#endif
......@@ -2359,6 +2361,11 @@ File %s already there; not retrieving.\n\n"), quote (hs->local_file));
else
fp = output_stream;
if (opt.xattr_url && file_exists_p(hs->local_file))
{
set_xattr( u, hs->local_file );
}
/* Print fetch message, if opt.verbose. */
if (opt.verbose)
{
......
......@@ -252,6 +252,7 @@ static const struct {
#ifdef USE_WATT32
{ "wdebug", &opt.wdebug, cmd_boolean },
#endif
{ "xattrurl", &opt.xattr_url, cmd_boolean },
};
/* Look up CMDNAME in the commands[] and return its position in the
......
......@@ -55,6 +55,7 @@ as that of the covered work. */
#include "convert.h"
#include "spider.h"
#include "http.h" /* for save_cookies */
#include "xattr.h"
#include <getopt.h>
#include <getpass.h>
......@@ -258,6 +259,7 @@ static struct cmdline_option option_data[] =
{ "retry-connrefused", 0, OPT_BOOLEAN, "retryconnrefused", -1 },
{ "save-cookies", 0, OPT_VALUE, "savecookies", -1 },
{ "save-headers", 0, OPT_BOOLEAN, "saveheaders", -1 },
{ "xattr-url", 0, OPT_BOOLEAN, "xattrurl", -1 },
{ IF_SSL ("secure-protocol"), 0, OPT_VALUE, "secureprotocol", -1 },
{ "server-response", 'S', OPT_BOOLEAN, "serverresponse", -1 },
{ "span-hosts", 'H', OPT_BOOLEAN, "spanhosts", -1 },
......@@ -554,6 +556,8 @@ HTTP options:\n"),
--referer=URL include `Referer: URL' header in HTTP request.\n"),
N_("\
--save-headers save the HTTP headers to file.\n"),
N_("\
--xattr-url save the URL to extended file attributes.\n"),
N_("\
-U, --user-agent=AGENT identify as AGENT instead of Wget/VERSION.\n"),
N_("\
......
......@@ -127,6 +127,7 @@ struct options
bool server_response; /* Do we print server response? */
bool save_headers; /* Do we save headers together with
file? */
bool xattr_url;
#ifdef ENABLE_DEBUG
bool debug; /* Debugging on/off */
......
#include "wget.h"
#include "url.h"
#include <attr/xattr.h>
int set_xattr( struct url *origin, const char *filename ) {
char *url = url_string(origin, URL_AUTH_HIDE);
logprintf (LOG_VERBOSE, _("Placing URL '%s' in extended attributes.\n"), url);
int err = setxattr( filename, "user.wget.origin", url, strlen(url), 0 );
if (err) {
logprintf (LOG_NOTQUIET, "setxattr: %s\n", strerror (errno));
}
return err;
}
int set_xattr( struct url *origin, const char *filename );
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment