AAssetDir_getNextFileName

241 views
Skip to first unread message

ni...@osomi.net

unread,
Jan 9, 2019, 10:27:42 AM1/9/19
to android-ndk

The spec shows that there is only a function for iterating over files, not directories. This either means that the developers using the NDK can't query the asset manager for directories; at least not on my device. Or that it only works on some devices (not on 8.0.0 s7 edge). I'd recommend adding AAssetDir_getNextFolderName, requiring AAssetDir_getNextFileName to display directories as well as assets or providing a function to loop over all files in the assets dir (nested).


	AAssetManager *assetManager = ((android_app*)param)->activity->assetManager;
	AAssetDir *dir = AAssetManager_openDir(assetManager, path);

	Log::println(String((void*)dir));

	const char *name = nullptr;

	while ((name = AAssetDir_getNextFileName(dir)) != nullptr) {
		Log::println(String("res/") + name);
	}

	AAssetDir_close(dir);

Doesn't do anything for path = "" or "res" (assets/res; a directory with only directories), but when I pass in a directory with files "res/shaders" (assets/res/shaders) it does work.

AssetDir supports this, why is this removed by AAssetManager?


I posted this issue on Github too; which got the following response:


"this needs some digging into the history and not sure what will be outcome either:

// Find the next regular file; explicitly don't report directories even if the
// underlying implementation changes to report them.  At that point we can add
// a more general iterator to this native interface set if appropriate.
   while ((index < max) && (assetDir->mAssetDir->getFileType(index) != kFileTypeRegular)) {
   index++;
  }

How about post this question to https://groups.google.com/forum/#!forum/android-ndk?"

Frederik

unread,
May 15, 2019, 2:49:32 PM5/15/19
to android-ndk
I’d also be interested in why AAssetDir does not allow to list directories. While this seems to be a deliberate design choice, this doesn’t match standard Unix opendir()/readdir() behavior and severely limits AAssetDir uses. This is especially limiting when adapting existing code based on opendir()/readdir() for Android, as there is no way to implement recursion into subdirectories.

In order to not break existing implementations I would suggest adding a new AAssetDir_getNext() method which lists both files and directories.

I would be great if this could be considered for a future release.

Thanks!

Dan Albert

unread,
May 20, 2019, 4:03:25 PM5/20/19
to android-ndk
I would be great if this could be considered for a future release.

Filing a framework bug following https://source.android.com/setup/contribute/report-bugs would be your best bet.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/41f7e968-4ffb-4b0a-822e-9bfc9ce2ebb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Frederik Seiffert

unread,
May 21, 2019, 3:36:35 AM5/21/19
to andro...@googlegroups.com
Thank you Dan. I found this existing report which I starred:


You received this message because you are subscribed to a topic in the Google Groups "android-ndk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-ndk/77OGvoeXN34/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-ndk...@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Dan Albert

unread,
May 21, 2019, 3:22:13 PM5/21/19
to android-ndk
Good find. Looks like that was re-triaged recently as well.

Reply all
Reply to author
Forward
0 new messages