【问题标题】:Check if a directory exists within a google-nativeclient file system?检查 google-nativeclient 文件系统中是否存在目录?
【发布时间】:2013-01-08 08:40:00
【问题描述】:

我正在尝试检查 Native Client 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_FileRefPPB_FileIO::Open 的返回值 PP_ERROR_NOTAFILE 是否足以让我判断它是一个目录,或者我应该使用其他更好的方法吗?

谢谢,詹姆斯

【问题讨论】:

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


    【解决方案1】:

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

    在创建pepper_25 的分支之后添加背景PP_ERROR_NOTAFILE,因此在pepper_26 在SDK 中可用之前,应该使用pepper_canary 进行开发以在pp_errors.h 中获得其定义。更多详情请看相关的Chromechange list,其中特别提到在尝试打开目录时会用到这个返回值。

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

    【讨论】:

      猜你喜欢
      • 2011-04-19
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 2011-01-18
      • 1970-01-01
      • 2013-04-24
      相关资源
      最近更新 更多