Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
3 : * http://soramitsu.co.jp
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #include "common/files.hpp"
19 :
20 : #include <boost/filesystem.hpp>
21 :
22 : #include "logger/logger.hpp"
23 :
24 : void iroha::remove_dir_contents(const std::string &dump_dir) {
25 923 : auto log = logger::log("common::remove_all");
26 923 : boost::system::error_code error_code;
27 :
28 923 : bool exists = boost::filesystem::exists(dump_dir, error_code);
29 923 : if (error_code != boost::system::errc::success) {
30 1 : log->error(error_code.message());
31 1 : return;
32 : }
33 922 : if (not exists) {
34 0 : log->error("Directory does not exist {}", dump_dir);
35 0 : return;
36 : }
37 :
38 922 : bool is_dir = boost::filesystem::is_directory(dump_dir, error_code);
39 922 : if (error_code != boost::system::errc::success) {
40 0 : log->error(error_code.message());
41 0 : return;
42 : }
43 922 : if (not is_dir) {
44 0 : log->error("{} is not a directory", dump_dir);
45 0 : return;
46 : }
47 :
48 2204 : for (auto entry : boost::filesystem::directory_iterator(dump_dir)) {
49 1282 : boost::filesystem::remove_all(entry.path(), error_code);
50 1282 : if (error_code != boost::system::errc::success)
51 0 : log->error(error_code.message());
52 1282 : }
53 923 : }
|