I'm trying to check if a directory exists in a Native Client file system but can't find any functions to do it. I tried creating a PPB_FileRef
for the directory and then opening that using PPB_FileIO::Open
and then calling PPB_FileIO::Query
but PPB_FileIO::Open
returns PP_ERROR_NOTAFILE
and then the second call fails.
This is the code I have been trying, some of the initialisation is left out for brevity.
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;
Is a return value of PP_ERROR_NOTAFILE
from PPB_FileIO::Open
for a valid PPB_FileRef
enough for me to tell it's a directory or is there another better method I should be using?
Thanks, James
Yes, currently the way to determine if a PPB_FileRef
refers to a directory is to try to open it and look for a PP_ERROR_NOTAFILE
return value.
For background PP_ERROR_NOTAFILE
was added after the branch for pepper_25
was made, so until pepper_26
becomes available in the SDK, one should develop with pepper_canary
to get its definition in pp_errors.h
. For more details, see the relevant Chrome change list , which specifically mentions that this return value is used when trying to open a directory.
The current behavior is arguably a bit opaque. There is a "dev" (experimental/unfinished) interface PPB_DirectoryReader
that when released will provide a more direct way to work with directories.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.