[vlc-devel] [PATCH v2 1/5] media_library: Fix FsFactory::createFile method

Alaric Senat dev.asenat at posteo.net
Fri Feb 5 11:47:46 UTC 2021


The createFile method in the FsFactory was using the mrl incorrectly by
creating a temporary directory with the full mrl of the file instead of
truncating the file name.
---
 modules/misc/medialibrary/fs/fs.cpp   | 2 +-
 modules/misc/medialibrary/fs/util.cpp | 8 ++++++++
 modules/misc/medialibrary/fs/util.h   | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/modules/misc/medialibrary/fs/fs.cpp b/modules/misc/medialibrary/fs/fs.cpp
index 85323cb231..6a04c5f564 100644
--- a/modules/misc/medialibrary/fs/fs.cpp
+++ b/modules/misc/medialibrary/fs/fs.cpp
@@ -60,7 +60,7 @@ SDFileSystemFactory::createDirectory(const std::string &mrl)
 std::shared_ptr<fs::IFile>
 SDFileSystemFactory::createFile(const std::string& mrl)
 {
-    auto dir = createDirectory(mrl);
+    auto dir = createDirectory(utils::directory(mrl));
     assert(dir != nullptr);
     return dir->file(mrl);
 }
diff --git a/modules/misc/medialibrary/fs/util.cpp b/modules/misc/medialibrary/fs/util.cpp
index f25f96d161..7f22425c07 100644
--- a/modules/misc/medialibrary/fs/util.cpp
+++ b/modules/misc/medialibrary/fs/util.cpp
@@ -52,6 +52,14 @@ fileName(const std::string &filePath)
     return filePath.substr(pos + 1);
 }
 
+std::string
+directory(const std::string &filePath)
+{
+    auto pos = filePath.find_last_of(DIR_SEPARATORS);
+    if (pos == std::string::npos)
+        return filePath;
+    return filePath.substr(0, pos);
+}
     } /* namespace utils */
   } /* namespace medialibrary */
 } /* namespace vlc */
diff --git a/modules/misc/medialibrary/fs/util.h b/modules/misc/medialibrary/fs/util.h
index 6cbff37114..10862477ad 100644
--- a/modules/misc/medialibrary/fs/util.h
+++ b/modules/misc/medialibrary/fs/util.h
@@ -29,6 +29,7 @@ namespace vlc {
 
 std::string fileName(const std::string& filePath);
 std::string extension(const std::string& fileName);
+std::string directory(const std::string& fileName);
 
     } /* namespace utils */
   } /* namespace medialibrary */
-- 
2.28.0



More information about the vlc-devel mailing list