Make TorrentInfo immutable

This commit is contained in:
Vladimir Golovnev (Glassez) 2021-12-09 13:05:49 +03:00
parent 9d2bb67834
commit 62b50d1475
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7
22 changed files with 382 additions and 255 deletions

View file

@ -398,3 +398,40 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path)
#endif
}
#endif // Q_OS_HAIKU
QString Utils::Fs::findRootFolder(const QStringList &filePaths)
{
QString rootFolder;
for (const QString &filePath : filePaths)
{
const auto filePathElements = QStringView(filePath).split(u'/');
// if at least one file has no root folder, no common root folder exists
if (filePathElements.count() <= 1)
return {};
if (rootFolder.isEmpty())
rootFolder = filePathElements.at(0).toString();
else if (rootFolder != filePathElements.at(0))
return {};
}
return rootFolder;
}
void Utils::Fs::stripRootFolder(QStringList &filePaths)
{
const QString commonRootFolder = findRootFolder(filePaths);
if (commonRootFolder.isEmpty())
return;
for (QString &filePath : filePaths)
filePath = filePath.mid(commonRootFolder.size() + 1);
}
void Utils::Fs::addRootFolder(QStringList &filePaths, const QString &rootFolder)
{
Q_ASSERT(!rootFolder.isEmpty());
for (QString &filePath : filePaths)
filePath = rootFolder + QLatin1Char('/') + filePath;
}