Skip to content

Commit a3bfd36

Browse files
lbd-alexslouken
authored andcommitted
filesystem: Fix Android asset enumeration
Passes expected relative paths to Android's AssetManager API instead of absolute ones + fixes some indexing logic with trailing slashes.
1 parent 70e1804 commit a3bfd36

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/filesystem/posix/SDL_sysfsops.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,22 @@ bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback
8383

8484
// trim down to a single path separator at the end, in case the caller added one or more.
8585
pathwithseplen--;
86-
while ((pathwithseplen > 0) && (pathwithsep[pathwithseplen] == '/')) {
86+
while ((pathwithseplen > 0) && (pathwithsep[pathwithseplen - 1] == '/')) {
8787
pathwithsep[pathwithseplen--] = '\0';
8888
}
8989

9090
DIR *dir = opendir(pathwithsep);
9191
if (!dir) {
92-
#ifdef SDL_PLATFORM_ANDROID // Maybe it's an asset...?
93-
const bool retval = Android_JNI_EnumerateAssetDirectory(pathwithsep, cb, userdata);
92+
#ifdef SDL_PLATFORM_ANDROID // Maybe it's an asset...?
93+
const bool retval = Android_JNI_EnumerateAssetDirectory(pathwithsep + extralen, cb, userdata);
9494
SDL_free(pathwithsep);
9595
return retval;
96-
#else
96+
#else
9797
SDL_free(pathwithsep);
9898
return SDL_SetError("Can't open directory: %s", strerror(errno));
99-
#endif
99+
#endif
100100
}
101101

102-
// make sure there's a path separator at the end now for the actual callback.
103-
pathwithsep[++pathwithseplen] = '/';
104-
pathwithsep[++pathwithseplen] = '\0';
105-
106102
SDL_EnumerationResult result = SDL_ENUM_CONTINUE;
107103
struct dirent *ent;
108104
while ((result == SDL_ENUM_CONTINUE) && ((ent = readdir(dir)) != NULL)) {
@@ -454,4 +450,3 @@ char *SDL_SYS_GetCurrentDirectory(void)
454450
}
455451

456452
#endif // SDL_FSOPS_POSIX
457-

0 commit comments

Comments
 (0)