Commit 40265fd4 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

fs: Deal with platform specific folder separators

parent 8270c2b4
......@@ -25,6 +25,7 @@
#endif
#include "CommonDevice.h"
#include "utils/Filename.h"
namespace medialibrary
{
......@@ -33,12 +34,10 @@ namespace fs
CommonDevice::CommonDevice( const std::string& uuid, const std::string& mountpoint, bool isRemovable )
: m_uuid( uuid )
, m_mountpoint( mountpoint )
, m_mountpoint( utils::file::toFolderPath( mountpoint ) )
, m_present( true )
, m_removable( isRemovable )
{
if ( *m_mountpoint.crbegin() != '/' )
m_mountpoint += '/';
}
const std::string& CommonDevice::uuid() const
......
......@@ -38,11 +38,9 @@ namespace fs
medialibrary::fs::CommonDirectory::CommonDirectory( const std::string& path,
factory::IFileSystem& fsFactory )
: m_path( path )
: m_path( utils::file::toFolderPath( path ) )
, m_fsFactory( fsFactory )
{
if ( *m_path.crbegin() != '/' )
m_path += '/';
}
const std::string& CommonDirectory::path() const
......
......@@ -26,6 +26,12 @@
#include "utils/Filename.h"
#ifdef _WIN32
#define DIR_SEPARATOR '\\'
#else
#define DIR_SEPARATOR '/'
#endif
namespace medialibrary
{
......@@ -90,6 +96,21 @@ std::string removePath( const std::string& fullPath, const std::string& toRemove
return fullPath.substr( pos );
}
std::string& toFolderPath( std::string& path )
{
if ( *path.crbegin() != DIR_SEPARATOR )
path += DIR_SEPARATOR;
return path;
}
std::string toFolderPath( const std::string& path )
{
auto p = path;
if ( *p.crbegin() != DIR_SEPARATOR )
p += DIR_SEPARATOR;
return p;
}
}
}
......
......@@ -38,6 +38,12 @@ namespace file
std::string firstFolder( const std::string& path );
std::string removePath( const std::string& fullPath, const std::string& toRemove );
std::string parentDirectory( const std::string& path );
/**
* @brief toFolder Ensures a path is a folder path; ie. it has a terminal '/'
* @param path The path to sanitize
*/
std::string& toFolderPath( std::string& path );
std::string toFolderPath( const std::string& path );
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment