Add case conflict check
This commit is contained in:
parent
e3db7cc225
commit
be3b43c2d7
4 changed files with 29 additions and 0 deletions
|
@ -220,6 +220,11 @@ bool addons_client::install_addon(config& archive_cfg, const addon_info& info)
|
|||
"name and cannot be installed.", i18n_symbols));
|
||||
return false;
|
||||
}
|
||||
if(!check_case_insensitive_duplicates(archive_cfg)){
|
||||
gui2::show_error_message(v_,
|
||||
vgettext("The add-on <i>$addon_title</i> has file or directory names "
|
||||
"with case conflicts. This may cause problems.", i18n_symbols));
|
||||
}
|
||||
|
||||
// Add local version information before unpacking
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include "config.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <set>
|
||||
|
||||
const unsigned short default_campaignd_port = 15008;
|
||||
|
||||
|
@ -120,6 +122,23 @@ bool check_names_legal(const config& dir, std::vector<std::string>* badlist)
|
|||
return check_names_legal_internal(dir, "", badlist);
|
||||
}
|
||||
|
||||
bool check_case_insensitive_duplicates(const config& dir){
|
||||
std::set<std::string> filenames;
|
||||
bool inserted;
|
||||
for (const config &path : dir.child_range("file")) {
|
||||
const config::attribute_value &filename = path["name"];
|
||||
std::tie(std::ignore, inserted) = filenames.insert(boost::algorithm::to_lower_copy(filename.str()));
|
||||
if (!inserted) return false;
|
||||
}
|
||||
for (const config &path : dir.child_range("dir")) {
|
||||
const config::attribute_value &filename = path["name"];
|
||||
std::tie(std::ignore, inserted) = filenames.insert(boost::algorithm::to_lower_copy(filename.str()));
|
||||
if (!inserted) return false;
|
||||
if (!check_case_insensitive_duplicates(path)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ADDON_TYPE get_addon_type(const std::string& str)
|
||||
{
|
||||
if (str.empty())
|
||||
|
|
|
@ -77,6 +77,8 @@ bool addon_filename_legal(const std::string& name);
|
|||
* @returns True if no illegal names were found.
|
||||
*/
|
||||
bool check_names_legal(const config& dir, std::vector<std::string>* badlist = nullptr);
|
||||
/** Probes an add-on archive for case-conflicts on case-insensitive filesystems. */
|
||||
bool check_case_insensitive_duplicates(const config& dir);
|
||||
|
||||
std::string encode_binary(const std::string& str);
|
||||
std::string unencode_binary(const std::string& str);
|
||||
|
|
|
@ -692,6 +692,9 @@ void server::handle_upload(const server::request& req)
|
|||
"Add-on rejected: The add-on contains files or directories with illegal names. "
|
||||
"File or directory names may not contain whitespace or any of the following characters: '/ \\ : ~'",
|
||||
filelist, req.sock);
|
||||
} else if(!check_case_insensitive_duplicates(data)) {
|
||||
LOG_CS << "Upload aborted - case conflict in add-on data.\n";
|
||||
send_error("Add-on rejected: Two files have a case conflict", req.sock);
|
||||
} else if(campaign && !authenticate(*campaign, upload["passphrase"])) {
|
||||
LOG_CS << "Upload aborted - incorrect passphrase.\n";
|
||||
send_error("Add-on rejected: The add-on already exists, and your passphrase was incorrect.", req.sock);
|
||||
|
|
Loading…
Add table
Reference in a new issue