Convert resolved wildcard paths to relative path before saving in database (#4574)

* Convert resolved wildcard paths to relative path before saving in database.

Warn if file could not be converted to a relative path.
Fix FindWildcardMatches path handling that could result in pathMatch missing the first character

Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com>

* Handle abs path wildcard dependencies

Remove dependencies outside of scan folder

Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com>

* Switch to AZ::IO::PathView for abs path check

Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com>

* Made code a little more clear

Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com>
monroegm-disable-blank-issue-2
amzn-mike 4 years ago committed by GitHub
parent 0031016548
commit c1335f69c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3573,19 +3573,61 @@ namespace AssetProcessor
QString knownPathBeforeWildcard = encodedFileData.left(slashBeforeWildcardIndex + 1); // include the slash QString knownPathBeforeWildcard = encodedFileData.left(slashBeforeWildcardIndex + 1); // include the slash
QString relativeSearch = encodedFileData.mid(slashBeforeWildcardIndex + 1); // skip the slash QString relativeSearch = encodedFileData.mid(slashBeforeWildcardIndex + 1); // skip the slash
for (int i = 0; i < m_platformConfig->GetScanFolderCount(); ++i) // Absolute path, just check the 1 scan folder
if (AZ::IO::PathView(encodedFileData.toUtf8().constData()).IsAbsolute())
{ {
const ScanFolderInfo* scanFolderInfo = &m_platformConfig->GetScanFolderAt(i); QString scanFolderName;
if (!m_platformConfig->ConvertToRelativePath(encodedFileData, resultDatabaseSourceName, scanFolderName))
if (!scanFolderInfo->RecurseSubFolders() && encodedFileData.contains("/"))
{ {
continue; AZ_Warning(
AssetProcessor::ConsoleChannel, false,
"'%s' does not appear to be in any input folder. Use relative paths instead.",
sourceDependency.m_sourceFileDependencyPath.c_str());
} }
QDir rooted(scanFolderInfo->ScanPath()); auto scanFolderInfo = m_platformConfig->GetScanFolderByPath(scanFolderName);
QString absolutePath = rooted.absoluteFilePath(knownPathBeforeWildcard);
// Make an absolute path that is ScanFolderPath + Part of search path before the wildcard
QDir rooted(scanFolderName);
QString scanFolderAndKnownSubPath = rooted.absoluteFilePath(knownPathBeforeWildcard);
resolvedDependencyList.append(m_platformConfig->FindWildcardMatches(
scanFolderAndKnownSubPath, relativeSearch, false, scanFolderInfo->RecurseSubFolders()));
}
else // Relative path, check every scan folder
{
for (int i = 0; i < m_platformConfig->GetScanFolderCount(); ++i)
{
const ScanFolderInfo* scanFolderInfo = &m_platformConfig->GetScanFolderAt(i);
if (!scanFolderInfo->RecurseSubFolders() && encodedFileData.contains("/"))
{
continue;
}
resolvedDependencyList.append(m_platformConfig->FindWildcardMatches(absolutePath, relativeSearch, false, scanFolderInfo->RecurseSubFolders())); QDir rooted(scanFolderInfo->ScanPath());
QString absolutePath = rooted.absoluteFilePath(knownPathBeforeWildcard);
resolvedDependencyList.append(m_platformConfig->FindWildcardMatches(
absolutePath, relativeSearch, false, scanFolderInfo->RecurseSubFolders()));
}
}
// Convert to relative paths
for (auto dependencyItr = resolvedDependencyList.begin(); dependencyItr != resolvedDependencyList.end();)
{
QString relativePath, scanFolder;
if (m_platformConfig->ConvertToRelativePath(*dependencyItr, relativePath, scanFolder))
{
*dependencyItr = relativePath;
++dependencyItr;
}
else
{
AZ_Warning("AssetProcessor", false, "Failed to get relative path for wildcard dependency file %s. Is the file within a scan folder?",
dependencyItr->toUtf8().constData());
dependencyItr = resolvedDependencyList.erase(dependencyItr);
}
} }
resultDatabaseSourceName = encodedFileData.replace('\\', '/'); resultDatabaseSourceName = encodedFileData.replace('\\', '/');

@ -1435,32 +1435,35 @@ namespace AssetProcessor
return QString(); return QString();
} }
QStringList PlatformConfiguration::FindWildcardMatches(const QString& sourceFolder, QString relativeName, bool includeFolders, bool recursiveSearch) const QStringList PlatformConfiguration::FindWildcardMatches(
const QString& sourceFolder, QString relativeName, bool includeFolders, bool recursiveSearch) const
{ {
if (relativeName.isEmpty()) if (relativeName.isEmpty())
{ {
return QStringList(); return QStringList();
} }
const int pathLen = sourceFolder.length() + 1; QDir sourceFolderDir(sourceFolder);
relativeName.replace('\\', '/'); QString posixRelativeName = QDir::fromNativeSeparators(relativeName);
QStringList returnList; QStringList returnList;
QRegExp nameMatch{ relativeName, Qt::CaseInsensitive, QRegExp::Wildcard }; QRegExp nameMatch{ posixRelativeName, Qt::CaseInsensitive, QRegExp::Wildcard };
QDirIterator diretoryIterator(sourceFolder, QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot, recursiveSearch ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags); QDirIterator dirIterator(
sourceFolderDir.path(), QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot,
recursiveSearch ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags);
QStringList files; QStringList files;
while (diretoryIterator.hasNext()) while (dirIterator.hasNext())
{ {
diretoryIterator.next(); dirIterator.next();
if (!includeFolders && !diretoryIterator.fileInfo().isFile()) if (!includeFolders && !dirIterator.fileInfo().isFile())
{ {
continue; continue;
} }
QString pathMatch{ diretoryIterator.filePath().mid(pathLen) }; QString pathMatch{ sourceFolderDir.relativeFilePath(dirIterator.filePath()) };
if (nameMatch.exactMatch(pathMatch)) if (nameMatch.exactMatch(pathMatch))
{ {
returnList.append(AssetUtilities::NormalizeFilePath(diretoryIterator.filePath())); returnList.append(QDir::fromNativeSeparators(dirIterator.filePath()));
} }
} }
return returnList; return returnList;

Loading…
Cancel
Save