【发布时间】:2019-07-12 11:11:54
【问题描述】:
我观察到 boost (v. 1.64) 目录迭代器构造函数 (directory_iterator(const path& p)) 在 Windows 系统上抛出带有 ERROR_INVALID_DRIVE 的异常。我想问题发生在 NTFS 上,但不能 100% 确定。
- ERROR_INVALID_DRIVE 的一般原因是什么?
-
directory_iterator(const path& p)里面可能是什么东西?据我了解,它只是列出了一个目录,因此无法在此处找到一种获取无效驱动器的方法
更新:
以下是相关代码:
namespace bfs = boost::filesystem;
bfs::path cache_path("C:/Users/Администратор/AppData/Local/some_unique_path/");
long long dir_size = 0;
boost::system::error_code ec;
int err_no = 0;
for (bfs::directory_iterator it(cache_path), eit; it != eit; it.increment(ec)) {
if (ec) {
std::cout << "Error " << 0 << ":" << ec << " while clearing the cache\n";
return;
}
dir_size += bfs::file_size(it->path(), ec);
if (ec) {
std::cout << "Error " << 1 << ":" << ec << " while clearing the cache\n";
return;
}
}
dir_size >>= 20; // want current cache size in Mb
if (dir_size > new_size) {
std::cout << "Clearing the kernel cache..." << std::endl;
// each file is attempted to be removed
for (bfs::directory_iterator it(cache_path), eit; it != eit; ++it) {
if (ec) {
std::cout << "Error " << 2 << ":" << ec << " while clearing the cache\n";
return;
}
bfs::remove(it->path(), ec); // this ec is skipped: don't care if it was impossible to delete file
}
}
【问题讨论】:
-
你有 boost 的源代码。只需进入它,直到您到达可能失败的内部 (win32/crt) 函数。找出传递给它的参数并查找该函数的文档。如果这不起作用,请使用这些详细信息编辑问题,我们或许可以提供帮助。
-
@MikeVine,不幸的是,我没有办法直接调试它,因为它发生在我无法访问的机器上,所以这是一个猜谜游戏,很抱歉要求与它一起玩我。我已经用我拥有的所有与 boost:filesystem 模块相关的代码更新了我的问题。也许,它会有所帮助。
标签: c++ boost filesystems