LCOV - code coverage report
Current view: top level - libs/common - files.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 14 21 66.7 %
Date: 2019-03-07 14:46:43 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "common/files.hpp"
       7             : 
       8             : #include <ciso646>
       9             : 
      10             : #include <boost/filesystem.hpp>
      11             : #include "logger/logger.hpp"
      12             : 
      13             : void iroha::remove_dir_contents(const std::string &dir,
      14             :                                 const logger::LoggerPtr &log) {
      15         941 :   boost::system::error_code error_code;
      16             : 
      17         941 :   bool exists = boost::filesystem::exists(dir, error_code);
      18         941 :   if (error_code != boost::system::errc::success) {
      19           1 :     log->error(error_code.message());
      20           1 :     return;
      21             :   }
      22         940 :   if (not exists) {
      23           0 :     log->error("Directory does not exist {}", dir);
      24           0 :     return;
      25             :   }
      26             : 
      27         940 :   bool is_dir = boost::filesystem::is_directory(dir, error_code);
      28         940 :   if (error_code != boost::system::errc::success) {
      29           0 :     log->error(error_code.message());
      30           0 :     return;
      31             :   }
      32         940 :   if (not is_dir) {
      33           0 :     log->error("{} is not a directory", dir);
      34           0 :     return;
      35             :   }
      36             : 
      37        2229 :   for (auto entry : boost::filesystem::directory_iterator(dir)) {
      38        1289 :     boost::filesystem::remove_all(entry.path(), error_code);
      39        1289 :     if (error_code != boost::system::errc::success)
      40           0 :       log->error(error_code.message());
      41        1289 :   }
      42         941 : }

Generated by: LCOV version 1.13