Browse Source

Improve path extension handling

PR #16867.
adaptive-webui-19844
Vladimir Golovnev 3 years ago committed by GitHub
parent
commit
7377974731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/base/bittorrent/customstorage.cpp
  2. 8
      src/base/bittorrent/torrentimpl.cpp
  3. 9
      src/base/path.cpp
  4. 5
      src/base/path.h
  5. 3
      src/base/search/searchpluginmanager.cpp

6
src/base/bittorrent/customstorage.cpp

@ -208,8 +208,7 @@ void CustomDiskIOThread::handleCompleteFiles(lt::storage_index_t storage, const @@ -208,8 +208,7 @@ void CustomDiskIOThread::handleCompleteFiles(lt::storage_index_t storage, const
if (filePath.hasExtension(QB_EXT))
{
const Path incompleteFilePath = savePath / filePath;
Path completeFilePath = incompleteFilePath;
completeFilePath.removeExtension(QB_EXT);
const Path completeFilePath = incompleteFilePath.removedExtension(QB_EXT);
if (completeFilePath.exists())
{
Utils::Fs::removeFile(incompleteFilePath);
@ -274,8 +273,7 @@ void CustomStorage::handleCompleteFiles(const Path &savePath) @@ -274,8 +273,7 @@ void CustomStorage::handleCompleteFiles(const Path &savePath)
if (filePath.hasExtension(QB_EXT))
{
const Path incompleteFilePath = savePath / filePath;
Path completeFilePath = incompleteFilePath;
completeFilePath.removeExtension();
const Path completeFilePath = incompleteFilePath.removedExtension(QB_EXT);
if (completeFilePath.exists())
{
Utils::Fs::removeFile(incompleteFilePath);

8
src/base/bittorrent/torrentimpl.cpp

@ -294,8 +294,7 @@ TorrentImpl::TorrentImpl(Session *session, lt::session *nativeSession @@ -294,8 +294,7 @@ TorrentImpl::TorrentImpl(Session *session, lt::session *nativeSession
const lt::file_index_t nativeIndex = m_torrentInfo.nativeIndexes().at(i);
m_indexMap[nativeIndex] = i;
Path filePath {fileStorage.file_path(nativeIndex)};
filePath.removeExtension(QB_EXT);
const auto filePath = Path(fileStorage.file_path(nativeIndex)).removedExtension(QB_EXT);
m_filePaths.append(filePath);
const auto priority = LT::fromNative(filePriorities[LT::toUnderlyingType(nativeIndex)]);
@ -1520,11 +1519,10 @@ void TorrentImpl::endReceivedMetadataHandling(const Path &savePath, const PathLi @@ -1520,11 +1519,10 @@ void TorrentImpl::endReceivedMetadataHandling(const Path &savePath, const PathLi
{
const auto nativeIndex = nativeIndexes.at(i);
Path filePath = fileNames.at(i);
const Path filePath = fileNames.at(i);
p.renamed_files[nativeIndex] = filePath.toString().toStdString();
filePath.removeExtension(QB_EXT);
m_filePaths.append(filePath);
m_filePaths.append(filePath.removedExtension(QB_EXT));
const auto priority = LT::fromNative(filePriorities[LT::toUnderlyingType(nativeIndex)]);
m_filePriorities.append(priority);

9
src/base/path.cpp

@ -151,7 +151,7 @@ QString Path::extension() const @@ -151,7 +151,7 @@ QString Path::extension() const
return ((dotIndex == -1) ? QString() : filename.mid(dotIndex).toString());
}
bool Path::hasExtension(const QString &ext) const
bool Path::hasExtension(const QStringView ext) const
{
Q_ASSERT(ext.startsWith(u'.') && (ext.size() >= 2));
@ -186,12 +186,17 @@ Path Path::removedExtension() const @@ -186,12 +186,17 @@ Path Path::removedExtension() const
return createUnchecked(m_pathStr.chopped(extension().size()));
}
void Path::removeExtension(const QString &ext)
void Path::removeExtension(const QStringView ext)
{
if (hasExtension(ext))
m_pathStr.chop(ext.size());
}
Path Path::removedExtension(const QStringView ext) const
{
return (hasExtension(ext) ? createUnchecked(m_pathStr.chopped(ext.size())) : *this);
}
QString Path::data() const
{
return m_pathStr;

5
src/base/path.h

@ -58,10 +58,11 @@ public: @@ -58,10 +58,11 @@ public:
QString filename() const;
QString extension() const;
bool hasExtension(const QString &ext) const;
bool hasExtension(QStringView ext) const;
void removeExtension();
Path removedExtension() const;
void removeExtension(const QString &ext);
void removeExtension(QStringView ext);
Path removedExtension(QStringView ext) const;
bool hasAncestor(const Path &other) const;
Path relativePathOf(const Path &childPath) const;

3
src/base/search/searchpluginmanager.cpp

@ -392,8 +392,7 @@ void SearchPluginManager::pluginDownloadFinished(const Net::DownloadResult &resu @@ -392,8 +392,7 @@ void SearchPluginManager::pluginDownloadFinished(const Net::DownloadResult &resu
{
const Path filePath = result.filePath;
Path pluginPath {QUrl(result.url).path()};
pluginPath.removeExtension(); // Remove extension
const auto pluginPath = Path(QUrl(result.url).path()).removedExtension();
installPlugin_impl(pluginPath.filename(), filePath);
Utils::Fs::removeFile(filePath);
}

Loading…
Cancel
Save