From c6fc694ea6d332f23e30c8624f42341380186f33 Mon Sep 17 00:00:00 2001 From: swagtoy Date: Mon, 30 Sep 2024 16:41:53 -0400 Subject: [PATCH] Fix deletePathFromFilename returning cutoff filenames (#15211) --- irr/include/coreutil.h | 9 ++++----- irr/src/CFileList.cpp | 4 ++-- irr/src/CZipReader.cpp | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/irr/include/coreutil.h b/irr/include/coreutil.h index 60014c4a7..73d1c4b43 100644 --- a/irr/include/coreutil.h +++ b/irr/include/coreutil.h @@ -63,7 +63,7 @@ inline io::path &getFileNameExtension(io::path &dest, const io::path &source) } //! delete path from filename -inline io::path &deletePathFromFilename(io::path &filename) +inline io::path deletePathFromFilename(const io::path &filename) { // delete path from filename const fschar_t *s = filename.c_str(); @@ -73,11 +73,10 @@ inline io::path &deletePathFromFilename(io::path &filename) while (*p != '/' && *p != '\\' && p != s) p--; - if (p != s) { + if (p != s) ++p; - filename = p; - } - return filename; + + return p; } //! trim paths diff --git a/irr/src/CFileList.cpp b/irr/src/CFileList.cpp index dde8e75ac..cd6c85df4 100644 --- a/irr/src/CFileList.cpp +++ b/irr/src/CFileList.cpp @@ -80,7 +80,7 @@ u32 CFileList::addItem(const io::path &fullPath, u32 offset, u32 size, bool isDi entry.FullName = entry.Name; - core::deletePathFromFilename(entry.Name); + entry.Name = core::deletePathFromFilename(entry.Name); if (IgnorePaths) entry.FullName = entry.Name; @@ -140,7 +140,7 @@ s32 CFileList::findFile(const io::path &filename, bool isDirectory = false) cons entry.FullName.make_lower(); if (IgnorePaths) - core::deletePathFromFilename(entry.FullName); + entry.FullName = core::deletePathFromFilename(entry.FullName); return Files.binary_search(entry); } diff --git a/irr/src/CZipReader.cpp b/irr/src/CZipReader.cpp index 2d2152719..036f6302a 100644 --- a/irr/src/CZipReader.cpp +++ b/irr/src/CZipReader.cpp @@ -191,8 +191,7 @@ bool CZipReader::scanGZipHeader() } } else { // no file name? - ZipFileName = Path; - core::deletePathFromFilename(ZipFileName); + ZipFileName = core::deletePathFromFilename(Path); // rename tgz to tar or remove gz extension if (core::hasFileExtension(ZipFileName, "tgz")) {