fixed empty tool name

delete temp extractor directory if it exists
This commit is contained in:
isanae
2020-05-04 03:12:06 -04:00
parent 748b0e4838
commit a2c2350c26
5 changed files with 25 additions and 11 deletions
+2 -1
View File
@@ -114,7 +114,8 @@ fs::path downloader::path_for_url(const mob::url& u) const
const std::string strip = "/download";
cx_->trace(context::net,
"url " + u.string() + " is sourceforge, stripping " + strip);
"url " + u.string() + " is sourceforge, "
"stripping " + strip + " for filename");
if (url_string.ends_with(strip))
url_string = url_string.substr(0, url_string.size() - strip.size());
+14 -7
View File
@@ -163,21 +163,28 @@ void extractor::check_duplicate_directory(const fs::path& ifile)
// give it a temp name in case there's yet another directory with the
// same name in it
const auto temp_dir_name = where_ / ("_mob_" + dir_name );
const auto temp_dir = where_ / ("_mob_" + dir_name );
cx_->trace(context::generic,
"renaming dir to " + temp_dir_name.string() + " to avoid clashes");
"renaming dir to " + temp_dir.string() + " to avoid clashes");
op::rename(*cx_,
where_ / dir_name,
where_ / temp_dir_name);
if (fs::exists(temp_dir))
{
cx_->trace(context::generic,
"temp dir " + temp_dir.string() + " already exists, "
"deleting");
op::delete_directory(*cx_, temp_dir);
}
op::rename(*cx_, where_ / dir_name, temp_dir);
// move the content of the directory up
for (auto e : fs::directory_iterator(where_ / temp_dir_name))
for (auto e : fs::directory_iterator(temp_dir))
op::move_to_directory(*cx_, e.path(), where_);
// delete the old directory, which should be empty now
op::delete_directory(*cx_, where_ / temp_dir_name);
op::delete_directory(*cx_, temp_dir);
}
} // namespace
+1 -1
View File
@@ -10,7 +10,7 @@ basic_process_runner::basic_process_runner(std::string name)
{
}
std::string basic_process_runner::name() const
std::string basic_process_runner::do_name() const
{
return process_.name();
}
+4
View File
@@ -27,6 +27,10 @@ tool& tool::operator=(tool&& t)
std::string tool::name() const
{
std::string s = do_name();
if (!s.empty())
return s;
return name_;
}
+4 -2
View File
@@ -17,7 +17,7 @@ public:
virtual ~tool() = default;
virtual std::string name() const;
std::string name() const;
void run(context& cx);
void interrupt();
@@ -30,8 +30,10 @@ protected:
tool(std::string name);
bool interrupted() const;
virtual void do_run() = 0;
virtual void do_interrupt() = 0;
virtual std::string do_name() const { return {}; }
private:
std::string name_;
@@ -66,7 +68,7 @@ private:
class basic_process_runner : public tool
{
public:
std::string name() const override;
std::string do_name() const override;
void join();
int exit_code() const;