Skip to content

Commit

Permalink
Do not copy directory symlinks recursively.
Browse files Browse the repository at this point in the history
  • Loading branch information
rqu authored and Martin Kruliš committed Jan 4, 2021
1 parent 483a474 commit 1f47051
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/helpers/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void helpers::copy_directory(const fs::path &src, const fs::path &dest)
if (!fs::exists(src)) {
throw filesystem_exception(
"helpers::copy_directory: Source directory does not exist '" + src.string() + "'");
} else if (!fs::is_directory(src)) {
} else if (!fs::is_directory(fs::symlink_status(src))) {
throw filesystem_exception(
"helpers::copy_directory: Source directory is not a directory '" + src.string() + "'");
} else if (!fs::exists(dest) && !fs::create_directories(dest)) {
Expand All @@ -17,7 +17,7 @@ void helpers::copy_directory(const fs::path &src, const fs::path &dest)

fs::directory_iterator endit;
for (fs::directory_iterator it(src); it != endit; ++it) {
if (fs::is_directory(it->status())) {
if (fs::is_directory(it->symlink_status())) {
helpers::copy_directory(it->path(), dest / it->path().filename());
} else {
fs::copy(it->path(), dest / it->path().filename());
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/internal/cp_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::shared_ptr<task_results> cp_task::run()
for (fs::directory_iterator item(base_dir); item != end_itr; ++item) {
if (regex_match(item->path().filename().string(), pattern)) {
auto target = output_is_dir ? (output / item->path().filename()) : output;
if (fs::is_directory(item->path())) {
if (fs::is_directory(fs::symlink_status(item->path()))) {
helpers::copy_directory(item->path(), target);
} else {
boost::system::error_code error_code;
Expand Down

0 comments on commit 1f47051

Please sign in to comment.