Skip to content

Commit

Permalink
Fix RepoCache::Impl::remove_recursive: Do not follow symlinks
Browse files Browse the repository at this point in the history
Symlinks were followed when removing the libdnf5 cache. This is very
dangerous.
Example:
A user extracted a package into the cache folder. And later runs
`dnf clean all`. The package contained a recursive symlink, which
terminated the deletion with
a `filesystem error: status: too many levels of symbolic...` error.

Imagine what would happen if there was a symlink outside the cache. Like
a link to "/home", "/"...
  • Loading branch information
jrohel authored and kontura committed Feb 18, 2025
1 parent b12d9fe commit c9529c6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libdnf5/repo/repo_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ RepoCache::RemoveStatistics RepoCache::Impl::remove_recursive(const std::filesys
RepoCache::RemoveStatistics status{};
std::error_code ec;
for (const auto & dir_entry : std::filesystem::directory_iterator(dir_path, ec)) {
if (dir_entry.is_directory()) {
if (dir_entry.is_directory() && !dir_entry.is_symlink()) {
status += remove_recursive(dir_entry, log);
status.p_impl->dirs_removed += remove(dir_entry, status.p_impl->errors, log);
} else {
Expand Down

0 comments on commit c9529c6

Please sign in to comment.