install(EXPORT): Fix support for mid-length install destinations on Windows

The implementation of `install(EXPORT)` generates files into a staging
directory for later installation.  We use the full install destination
in the path to the staging directory to avoid collisions.  In order to
avoid exceeding maximum path lengths (especially on Windows) we compute
a hash of the install destination when it is too long.  Fix this logic
to account for the length of the file name(s) when deciding whether to
switch to the hashed name.

Reported-by: Alan W. Irwin <irwin@beluga.phys.uvic.ca>
This commit is contained in:
Brad King 2016-08-09 09:53:16 -04:00
parent 4689d16e8a
commit c7a319ab05
2 changed files with 26 additions and 2 deletions

View File

@ -74,9 +74,12 @@ void cmInstallExportGenerator::ComputeTempDir()
#else #else
std::string::size_type const max_total_len = 1000; std::string::size_type const max_total_len = 1000;
#endif #endif
if (this->TempDir.size() < max_total_len) { // Will generate files of the form "<temp-dir>/<base>-<config>.<ext>".
std::string::size_type const len = this->TempDir.size() + 1 +
this->FileName.size() + 1 + this->GetMaxConfigLength();
if (len < max_total_len) {
// Keep the total path length below the limit. // Keep the total path length below the limit.
std::string::size_type max_len = max_total_len - this->TempDir.size(); std::string::size_type const max_len = max_total_len - len;
if (this->Destination.size() > max_len) { if (this->Destination.size() > max_len) {
useMD5 = true; useMD5 = true;
} }
@ -102,6 +105,26 @@ void cmInstallExportGenerator::ComputeTempDir()
} }
} }
size_t cmInstallExportGenerator::GetMaxConfigLength() const
{
// Always use at least 8 for "noconfig".
size_t len = 8;
if (this->ConfigurationTypes->empty()) {
if (this->ConfigurationName.size() > 8) {
len = this->ConfigurationName.size();
}
} else {
for (std::vector<std::string>::const_iterator ci =
this->ConfigurationTypes->begin();
ci != this->ConfigurationTypes->end(); ++ci) {
if (ci->size() > len) {
len = ci->size();
}
}
}
return len;
}
void cmInstallExportGenerator::GenerateScript(std::ostream& os) void cmInstallExportGenerator::GenerateScript(std::ostream& os)
{ {
// Skip empty sets. // Skip empty sets.

View File

@ -53,6 +53,7 @@ protected:
void GenerateImportFile(cmExportSet const* exportSet); void GenerateImportFile(cmExportSet const* exportSet);
void GenerateImportFile(const char* config, cmExportSet const* exportSet); void GenerateImportFile(const char* config, cmExportSet const* exportSet);
void ComputeTempDir(); void ComputeTempDir();
size_t GetMaxConfigLength() const;
cmExportSet* ExportSet; cmExportSet* ExportSet;
std::string FilePermissions; std::string FilePermissions;