diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 19 | ||||
-rw-r--r-- | src/xattr.c | 10 | ||||
-rw-r--r-- | src/xattr.h | 2 |
3 files changed, 16 insertions, 15 deletions
diff --git a/src/main.c b/src/main.c index deca6c979..2f81ef4e8 100644 --- a/src/main.c +++ b/src/main.c @@ -5633,9 +5633,17 @@ operate(struct Configurable *config, int argc, argv_item_t argv[]) } } } - if(outfile && !curlx_strequal(outfile, "-") && outs.stream) { - int rc = fclose(outs.stream); + int rc; + + if(config->xattr) { + rc = fwrite_xattr(curl, fileno(outs.stream) ); + if(rc) + warnf(config, "Error setting extended attributes: %s\n", + strerror(errno) ); + } + + rc = fclose(outs.stream); if(!res && rc) { /* something went wrong in the writing process */ res = CURLE_WRITE_ERROR; @@ -5643,13 +5651,6 @@ operate(struct Configurable *config, int argc, argv_item_t argv[]) } } - if(config->xattr && outs.filename) { - int err = write_xattr(curl, outs.filename ); - if(err) - warnf( config, "Error setting extended attributes: %s\n", - strerror(errno) ); - } - #ifdef HAVE_UTIME /* Important that we set the time _after_ the file has been closed, as is done above here */ diff --git a/src/xattr.c b/src/xattr.c index e03509680..a770405c9 100644 --- a/src/xattr.c +++ b/src/xattr.c @@ -25,7 +25,7 @@ #include <curl/curl.h> #include "xattr.h" -#ifdef HAVE_SETXATTR +#ifdef HAVE_FSETXATTR #include <sys/types.h> #include <string.h> #include <sys/xattr.h> /* include header from libc, not from libattr */ @@ -46,7 +46,7 @@ static const struct xattr_mapping { /* store metadata from the curl request alongside the downloaded * file using extended attributes */ -int write_xattr(CURL *curl, const char *filename) +int fwrite_xattr(CURL *curl, int fd) { int i = 0; int err = 0; @@ -55,17 +55,17 @@ int write_xattr(CURL *curl, const char *filename) char *value = NULL; CURLcode rc = curl_easy_getinfo(curl, mappings[i].info, &value); if ( rc == CURLE_OK && value ) { - err = setxattr( filename, mappings[i].attr, value, strlen(value), 0 ); + err = fsetxattr( fd, mappings[i].attr, value, strlen(value), 0 ); } i++; } return err; } #else -int write_xattr(CURL *curl, const char *filename) +int fwrite_xattr(CURL *curl, int fd) { (void)curl; - (void)filename; + (void)fd; return 0; } #endif diff --git a/src/xattr.h b/src/xattr.h index df62066c8..fea98f188 100644 --- a/src/xattr.h +++ b/src/xattr.h @@ -21,6 +21,6 @@ * KIND, either express or implied. * ***************************************************************************/ -int write_xattr( CURL *curl, const char *filename ); +int fwrite_xattr(CURL *curl, int fd); #endif |