Fixed crash when a library is set with a trailing /, fixes #552
This commit is contained in:
@@ -93,6 +93,8 @@ namespace lms::core::pathUtils::tests
|
|||||||
{ "/root/", "/root/", true },
|
{ "/root/", "/root/", true },
|
||||||
{ "/folder/file.txt", "/root", false },
|
{ "/folder/file.txt", "/root", false },
|
||||||
{ "/folder/file.txt", "/root/", false },
|
{ "/folder/file.txt", "/root/", false },
|
||||||
|
{ "/file.txt", "/root", false },
|
||||||
|
{ "/file.txt", "/root/", false },
|
||||||
{ "", "/root", false },
|
{ "", "/root", false },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,9 +31,9 @@
|
|||||||
namespace lms::db
|
namespace lms::db
|
||||||
{
|
{
|
||||||
MediaLibrary::MediaLibrary(const std::filesystem::path& p, std::string_view name)
|
MediaLibrary::MediaLibrary(const std::filesystem::path& p, std::string_view name)
|
||||||
: _path{ p }
|
: _name{ std::string{ name, 0, maxNameLength } }
|
||||||
, _name{ std::string{ name, 0, maxNameLength } }
|
|
||||||
{
|
{
|
||||||
|
setPath(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaLibrary::pointer MediaLibrary::create(Session& session, const std::filesystem::path& p, std::string_view name)
|
MediaLibrary::pointer MediaLibrary::create(Session& session, const std::filesystem::path& p, std::string_view name)
|
||||||
@@ -77,4 +77,13 @@ namespace lms::db
|
|||||||
func(mediaLibrary);
|
func(mediaLibrary);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MediaLibrary::setPath(const std::filesystem::path& p)
|
||||||
|
{
|
||||||
|
assert(p.is_absolute());
|
||||||
|
if (!p.has_filename() && p.has_parent_path())
|
||||||
|
_path = p.parent_path();
|
||||||
|
else
|
||||||
|
_path = p;
|
||||||
|
}
|
||||||
} // namespace lms::db
|
} // namespace lms::db
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace lms::db
|
|||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
static constexpr Version LMS_DATABASE_VERSION{ 73 };
|
static constexpr Version LMS_DATABASE_VERSION{ 74 };
|
||||||
}
|
}
|
||||||
|
|
||||||
VersionInfo::VersionInfo()
|
VersionInfo::VersionInfo()
|
||||||
@@ -941,6 +941,12 @@ SELECT
|
|||||||
utils::executeCommand(*session.getDboSession(), "UPDATE scan_settings SET scan_version = scan_version + 1");
|
utils::executeCommand(*session.getDboSession(), "UPDATE scan_settings SET scan_version = scan_version + 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void migrateFromV73(Session& session)
|
||||||
|
{
|
||||||
|
// Remove any trailing '/' in library paths
|
||||||
|
utils::executeCommand(*session.getDboSession(), "UPDATE media_library SET path = rtrim(path, '/') WHERE path LIKE '%/'");
|
||||||
|
}
|
||||||
|
|
||||||
bool doDbMigration(Session& session)
|
bool doDbMigration(Session& session)
|
||||||
{
|
{
|
||||||
constexpr std::string_view outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
|
constexpr std::string_view outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
|
||||||
@@ -990,6 +996,7 @@ SELECT
|
|||||||
{ 70, migrateFromV70 },
|
{ 70, migrateFromV70 },
|
||||||
{ 71, migrateFromV71 },
|
{ 71, migrateFromV71 },
|
||||||
{ 72, migrateFromV72 },
|
{ 72, migrateFromV72 },
|
||||||
|
{ 73, migrateFromV73 },
|
||||||
};
|
};
|
||||||
|
|
||||||
bool migrationPerformed{};
|
bool migrationPerformed{};
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace lms::db
|
|||||||
|
|
||||||
// setters
|
// setters
|
||||||
void setName(std::string_view name) { _name = name; }
|
void setName(std::string_view name) { _name = name; }
|
||||||
void setPath(const std::filesystem::path& p) { _path = p; }
|
void setPath(const std::filesystem::path& p);
|
||||||
|
|
||||||
template<class Action>
|
template<class Action>
|
||||||
void persist(Action& a)
|
void persist(Action& a)
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace lms::ui
|
|||||||
if (p.is_relative())
|
if (p.is_relative())
|
||||||
return Wt::WValidator::Result(Wt::ValidationState::Invalid, Wt::WString::tr("Lms.Admin.MediaLibrary.path-must-be-absolute"));
|
return Wt::WValidator::Result(Wt::ValidationState::Invalid, Wt::WString::tr("Lms.Admin.MediaLibrary.path-must-be-absolute"));
|
||||||
|
|
||||||
// TODO check and translate rights issues
|
// TODO check and translate access rights issues
|
||||||
bool res{ std::filesystem::is_directory(p, ec) };
|
bool res{ std::filesystem::is_directory(p, ec) };
|
||||||
if (ec)
|
if (ec)
|
||||||
return Wt::WValidator::Result(Wt::ValidationState::Invalid, ec.message()); // TODO translate common errors
|
return Wt::WValidator::Result(Wt::ValidationState::Invalid, ec.message()); // TODO translate common errors
|
||||||
|
|||||||
Reference in New Issue
Block a user