Medial Code Documentation
Loading...
Searching...
No Matches
filesys.cc
1// Copyright by Contributors
2
3#include <dmlc/filesystem.h>
4#include <queue>
5
6namespace dmlc {
7namespace io {
8
9void FileSystem::ListDirectoryRecursive(const URI &path,
10 std::vector<FileInfo> *out_list) {
11 std::queue<URI> queue;
12 queue.push(path);
13 while (!queue.empty()) {
14 std::vector<FileInfo> dfiles;
15 ListDirectory(queue.front(), &dfiles);
16 queue.pop();
17 for (auto dfile : dfiles) {
18 if (dfile.type == kDirectory) {
19 queue.push(dfile.path);
20 } else {
21 out_list->push_back(dfile);
22 }
23 }
24 }
25}
26
27} // namespace io
28
29void TemporaryDirectory::RecursiveDelete(const std::string &path) {
30 io::URI uri(path.c_str());
31 io::FileSystem* fs = io::FileSystem::GetInstance(uri);
32 std::vector<io::FileInfo> file_list;
33 fs->ListDirectory(uri, &file_list);
34 for (io::FileInfo info : file_list) {
35 CHECK(!IsSymlink(info.path.name))
36 << "Symlink not supported in TemporaryDirectory";
37 if (info.type == io::FileType::kDirectory) {
38 RecursiveDelete(info.path.name);
39 } else {
40 if (std::remove(info.path.name.c_str()) != 0) {
41 LOG(INFO) << "Couldn't remove file " << info.path.name
42 << "; you may want to remove it manually";
43 }
44 }
45 }
46#if _WIN32
47 const bool rmdir_success = (RemoveDirectoryA(path.c_str()) != 0);
48#else
49 const bool rmdir_success = (rmdir(path.c_str()) == 0);
50#endif
51 if (rmdir_success) {
52 if (verbose_) {
53 LOG(INFO) << "Successfully deleted temporary directory " << path;
54 }
55 } else {
56 LOG(INFO) << "~TemporaryDirectory(): "
57 << "Could not remove temporary directory " << path
58 << "; you may want to remove it manually";
59 }
60}
61} // namespace dmlc
std::string path
Full path of the temporary directory.
Definition filesystem.h:126
Utilities to manipulate files.
namespace for dmlc
Definition array_view.h:12