Skip to content

Commit

Permalink
Fix findAutoscanDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlStraussberger committed Feb 1, 2024
1 parent 3e7c944 commit 9e2fbc8
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
12 changes: 11 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@

- Add ctypes include
- Avoid crash when parent was not created yet.
- Bump follow-redirects from 1.15.3 to 1.15.4 in /gerbera-web
- Build Support for NPUPNP
- Bump follow-redirects from 1.15.3 to 1.15.4 in /gerbera-web
- clang-tidy and cppcheck fixes
- clang-tidy fixes
- CMake: Use presets
- Config: Refactor handling of integer types
- Correct two typos.
- Fix build-deb.sh for releases
- Gerbera welcomes 2024
- github workflows: make cmake stuff consistent
- Import: Safely handle second scan
- Import: Safely handle second scan - 2
- Refactor config and enums to reduce nesting
- Refactor parser files
- Safely handle suppressed file types
- Scripting: print2 function with log level support
- some fixes
- Update workflow actions

### v2.0.0

Expand Down
10 changes: 10 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

## MAIN

### NEW Features

- new JavaScript function `print2` to allow setting log type (info, debug, trace)

### FIXES

- Fix loading of playlists

### Code Improvements

- Restructuring files
- Updates to the build system: Use cmake presets
- Update versions of fmt (10.2.1), spdlog (1.13.0)
- Support build with NPUPNP

## v2.0.0

Expand Down
8 changes: 7 additions & 1 deletion src/content/content_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -846,18 +846,24 @@ std::shared_ptr<AutoscanDirectory> ContentManager::findAutoscanDirectory(fs::pat
{
std::shared_ptr<AutoscanDirectory> autoscanDir;
path.remove_filename();
std::error_code ec;

for (std::size_t i = 0; i < autoscanList->size(); i++) {
auto dir = autoscanList->get(i);
if (dir) {
log_debug("AutoscanDir ({}): {}", AutoscanDirectory::mapScanmode(dir->getScanMode()), i);
if (isSubDir(dir->getLocation(), path) && fs::is_directory(dir->getLocation())) {
if (isSubDir(path, dir->getLocation()) && fs::is_directory(dir->getLocation(), ec)) {
autoscanDir = std::move(dir);
}
if (ec) {
log_warning("No AutoscanDir {} has problems '{}'", dir->getLocation().string(), ec.message());
}
}
}
if (!autoscanDir) {
log_warning("No AutoscanDir found for {}", path.string());
}

return autoscanDir;
}

Expand Down
5 changes: 0 additions & 5 deletions src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#include "action_request.h"
#include "config/config_manager.h"
#include "config/config_option_enum.h"
#include "config/result/autoscan.h"
#include "content/content_manager.h"
#include "database/database.h"
#include "device_description_handler.h"
Expand All @@ -70,10 +69,6 @@
#include "web/pages.h"
#include "web/session_manager.h"

#ifdef HAVE_JS
#include "content/scripting/playlist_parser_script.h"
#endif

#ifdef HAVE_CURL
#include "url_request_handler.h"
#endif
Expand Down
7 changes: 4 additions & 3 deletions src/util/grb_fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ Gerbera - https://gerbera.io/

#include "util/tools.h"

void rtrimPath(std::string& s, unsigned char sep)
std::string rtrimPath(std::string& s, unsigned char sep)
{
if (!s.empty()) {
s.erase(std::find_if(s.rbegin(), s.rend() - 1, [&](unsigned char ch) {
return ch != sep;
}).base(),
s.end());
}
return s;
}

bool isSubDir(const fs::path& path, const fs::path& check)
bool isSubDir(const fs::path& path, const fs::path& parent)
{
auto pathStr = fmt::format("{}/", path.string());
auto chkStr = fmt::format("{}/", check.string());
auto chkStr = fmt::format("{}/", parent.string());
rtrimPath(pathStr);
rtrimPath(chkStr);
return startswith(pathStr, chkStr);
Expand Down
4 changes: 2 additions & 2 deletions src/util/grb_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class GrbFile {
const fs::path& getPath() { return path; }
};

void rtrimPath(std::string& s, unsigned char sep = '/');
bool isSubDir(const fs::path& path, const fs::path& check);
std::string rtrimPath(std::string& s, unsigned char sep = '/');
bool isSubDir(const fs::path& path, const fs::path& parent);

/// \brief Checks if the given file is a regular file (imitate same behaviour as std::filesystem::is_regular_file)
bool isRegularFile(const fs::path& path, std::error_code& ec) noexcept;
Expand Down
16 changes: 16 additions & 0 deletions test/util/test_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ TEST(ToolsTest, renderWebUriV6)
EXPECT_EQ(GrbNet::renderWebUri("2001:0db8:85a3:0000:0000:8a2e:0370:7334", 7777), "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:7777");
}

TEST(ToolsTest, pathTrimTest)
{
std::string test = "/regular/path";
EXPECT_EQ(rtrimPath(test), test);
std::string test2 = "/regular/path//";
EXPECT_EQ(rtrimPath(test2), test);
}

TEST(ToolsTest, subdirTest)
{
std::string test = "/regular/path";
std::string test2 = "/regular/path/sub/";
EXPECT_EQ(isSubDir(test, test2), false);
EXPECT_EQ(isSubDir(test2, test), true);
}

TEST(ToolsTest, splitStringTest)
{
auto parts = splitString("", ',');
Expand Down

0 comments on commit 9e2fbc8

Please sign in to comment.