【发布时间】: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_FileRef,PPB_FileIO::Open 的返回值 PP_ERROR_NOTAFILE 是否足以让我判断它是一个目录,或者我应该使用其他更好的方法吗?
谢谢,詹姆斯
【问题讨论】:
标签: c++ file-io directory google-nativeclient