c++ - 检查 google-nativeclient 文件系统中是否存在目录?

标签 c++ file-io directory google-nativeclient

我正在尝试检查 native 客户端中是否存在目录 file system但找不到任何功能来做到这一点。我尝试为目录创建一个 PPB_FileRef,然后使用 PPB_FileIO::Open 打开它,然后调用 PPB_FileIO::Query 但是 PPB_FileIO::Open 返回 PP_ERROR_NOTAFILE,然后第二次调用失败。

这是我一直在尝试的代码,为简洁起见省略了一些初始化。

PP_Instance instance; // initialised elsewhere
PPB_FileRef *fileRefInterface; // initialised elsewhere
PPB_FileIO *fileIOInterface; // initialised elsewhere
PP_Resource fileSystemResource; // initialised elsewhere

PP_Resource fileRefResource = fileRefInterface->Create(
  fileSystemResource,
  "/directory");

PP_Resource fileIOResource = fileIOInterface->Create(instance);

// This call is returning PP_ERROR_NOTAFILE
//
int32_t result = fileIOInterface->Open(
  fileIOResource,
  fileRefResource,
  PP_FILEOPENFLAG_READ,
  PP_BlockUntilComplete()); // this is being called from a background thread.
if (result != PP_OK)
{
  return false;
}

PP_FileInfo info;
result = fileIOInterface->Query(fileIOResource, &info, PP_BlockUntilComplete());
if (result != PP_OK)
{
  return info.type == PP_FILETYPE_DIRECTORY;
}

return false;

PPB_FileIO::OpenPP_ERROR_NOTAFILE 的返回值是有效的 PPB_FileRef 足以让我判断它是一个目录还是在那里我应该使用另一种更好的方法吗?

谢谢,詹姆斯

最佳答案

是的,目前确定 PPB_FileRef 是否引用目录的方法是尝试打开它并查找 PP_ERROR_NOTAFILE 返回值。

背景 PP_ERROR_NOTAFILE 是在 pepper_25 的分支创建之后添加的,因此在 pepper_26 在 SDK 中可用之前,应该使用pepper_canarypp_errors.h 中获取它的定义。有关更多详细信息,请参阅相关的 Chrome change list ,其中特别提到尝试打开目录时会使用此返回值。

目前的行为可以说是有点不透明。有一个“开发”(实验性/未完成)接口(interface) PPB_DirectoryReader,发布后将提供更直接的目录处理方式。

关于c++ - 检查 google-nativeclient 文件系统中是否存在目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14503920/

相关文章:

c++ - OpenGL- 没有光 C++ 的平面着色

java - String.split 未按预期工作

ios - 从iphone上传图片到服务器文件夹

amazon-web-services - 如何使用 terraform 在亚马逊 S3 存储桶中创建文件夹

android 文本文件导入 我在哪里保存文本文件什么文件夹?

c++ - 如何仅在一个函数的参数上应用类型映射?

c++ - 令人抓狂的链表问题

c++ - 了解堆上保留内存的大小

c++ - 如何在 Visual C++ 中截断文件?

Python/Pandas - 使用 'describe' 时如何避免省略号