Skip to content

Commit

Permalink
Copy task should be able to copy directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Neloop authored and Martin Kruliš committed Nov 9, 2019
1 parent 1b8b0b5 commit b9fb4ed
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/tasks/internal/cp_task.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "cp_task.h"
#include <regex>
#include "helpers/filesystem.h"

#define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_NO_CXX11_SCOPED_ENUMS
Expand Down Expand Up @@ -96,12 +97,16 @@ 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;
boost::system::error_code error_code;
fs::copy(item->path(), target, error_code);
if (error_code.value() != boost::system::errc::success) {
result->status = task_status::FAILED;
result->error_message = std::string("Cannot copy files. Error: ") + error_code.message();
break;
if (fs::is_directory(item->path())) {
helpers::copy_directory(item->path(), target);
} else {
boost::system::error_code error_code;
fs::copy(item->path(), target, error_code);
if (error_code.value() != boost::system::errc::success) {
result->status = task_status::FAILED;
result->error_message = std::string("Cannot copy files. Error: ") + error_code.message();
break;
}
}
}
}
Expand Down

0 comments on commit b9fb4ed

Please sign in to comment.