SDL: android: Different approach to SDL_GetPathInfo() for assets.

From 774c0b36eaf74d957af6dd6f647f5d86c5009d7c Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 29 Jul 2025 12:14:04 -0400
Subject: [PATCH] android: Different approach to SDL_GetPathInfo() for assets.

Reference Issue #13050.
---
 src/core/android/SDL_android.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 4f54265a9dafe..1f9093ef58b86 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -1890,14 +1890,6 @@ bool Android_JNI_GetAssetPathInfo(const char *path, SDL_PathInfo *info)
     }
 
     // this is sort of messy, but there isn't a stat()-like interface to the Assets.
-    AAssetDir *adir = AAssetManager_openDir(asset_manager, path);
-    if (adir) {  // it's a directory!
-        AAssetDir_close(adir);
-        info->type = SDL_PATHTYPE_DIRECTORY;
-        info->size = 0;
-        return true;
-    }
-
     AAsset *aasset = AAssetManager_open(asset_manager, path, AASSET_MODE_UNKNOWN);
     if (aasset) {  // it's a file!
         info->type = SDL_PATHTYPE_FILE;
@@ -1906,6 +1898,17 @@ bool Android_JNI_GetAssetPathInfo(const char *path, SDL_PathInfo *info)
         return true;
     }
 
+    AAssetDir *adir = AAssetManager_openDir(asset_manager, path);
+    if (adir) {  // This does _not_ return NULL for a missing directory! Treat empty directories as missing. Better than nothing.  :/
+        const bool contains_something = (AAssetDir_getNextFileName(adir) != NULL);  // if not NULL, there are files in this directory, so it's _definitely_ a directory.
+        AAssetDir_close(adir);
+        if (contains_something) {
+            info->type = SDL_PATHTYPE_DIRECTORY;
+            info->size = 0;
+            return true;
+        }
+    }
+
     return SDL_SetError("Couldn't open asset '%s'", path);
 }