diff --git a/Changes b/Changes index 390cc1370..7c997adfc 100644 --- a/Changes +++ b/Changes @@ -2255,3 +2255,6 @@ - Fix bundled TRE compilation error on OpenBSD with pkg-config-0.21 where pkg-config can't find 'tre.pc'. Reported by CuleX. (#3982) Also properly escape the sed expression used in the pkg-config call. +- Fix remote MOTDs for URLs whose path components contain + subdirectories, in the process much simplifying my remote MOTD + code. Reported by goldenwolf (#3986). diff --git a/include/struct.h b/include/struct.h index 522b2cb6a..d4bcccb2b 100644 --- a/include/struct.h +++ b/include/struct.h @@ -724,7 +724,6 @@ struct Motd; struct MotdDownload { struct Motd *themotd; - char url_filename[PATH_MAX+1]; /*< Where the downloaded file should be stored */ }; #endif /* USE_LIBCURL */ diff --git a/src/s_serv.c b/src/s_serv.c index 4af32c196..345a96708 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -1001,12 +1001,11 @@ void read_motd(const char *filename, aMotdFile *themotd) motd_download->themotd = themotd; themotd->motd_download = motd_download; - /* determine where to the MOTD should be stored after it's downloaded */ - url_filename = url_getfilename(filename); - strlcpy(motd_download->url_filename, url_filename, sizeof(motd_download->url_filename)); - motd_download->url_filename[PATH_MAX] = '\0'; - - modtime = unreal_getfilemodtime(url_filename); +#ifdef REMOTEINC_SPECIALCACHE + modtime = unreal_getfilemodtime(unreal_mkcache(filename)); +#else + modtime = 0; +#endif MyFree(url_filename); @@ -1033,6 +1032,8 @@ void read_motd_asynch_downloaded(const char *url, const char *filename, const ch { aMotdFile *themotd; + char *tmpfile; + themotd = motd_download->themotd; /* check if the download was soft-canceled. See struct.h's docs on @@ -1050,10 +1051,8 @@ void read_motd_asynch_downloaded(const char *url, const char *filename, const ch #ifdef REMOTEINC_SPECIALCACHE if(has_cached_version(url)) { - - config_warn("Error downloading MOTD file from \"%s\": %s", url, errorbuf); - filename = motd_download->url_filename; - unreal_copyfileex(unreal_mkcache(url), filename, 0); + config_warn("Error downloading MOTD file from \"%s\": %s -- using cached version instead.", url, errorbuf); + filename = unreal_mkcache(url); } else { #endif config_error("Error downloading MOTD file from \"%s\": %s", url, errorbuf); @@ -1064,24 +1063,23 @@ void read_motd_asynch_downloaded(const char *url, const char *filename, const ch #endif } +#ifdef REMOTEINC_SPECIALCACHE /* - We need to move our newly downloaded file to the place specified - by url_filename if it's not cached. - */ + * We need to move our newly downloaded file to its cache file + * if it isn't there already. + */ if(!cached) { - unreal_copyfileex(filename, motd_download->url_filename, 0); -#ifdef REMOTEINC_SPECIALCACHE /* create specialcached version for later */ unreal_copyfileex(filename, unreal_mkcache(url), 1); -#endif } else { /* - The file is cached. Thus we must look for it at - motd_download->url_filename, where be placed it earlier. + * The file is cached. Thus we must look for it at the + * cache location where we placed it earlier. */ - filename = motd_download->url_filename; + filename = unreal_mkcache(url); } +#endif do_read_motd(filename, themotd); MyFree(motd_download);