mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
fix(desktop): let desktop apps save read-only game files, and make game libraries writable (#1781)
This commit is contained in:
1 parent
5786e89ff4
commit
22d39998f0
8 files changed
+366
-4
No files matched your search
@@ -139,17 +139,31 @@ static int (*next_faccessat(void))(int, const char *, int, int) {
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_runnable(const char *path, int mode);
|
||||
__attribute__((visibility("hidden"))) int bl_writable_access(int dirfd, const char *path, int mode, int flags);
|
||||
|
||||
static int writable_as_owner(int (*real)(int, const char *, int, int), int dirfd, const char *path, int mode, int flags) {
|
||||
if (!bl_writable_access(dirfd, path, mode, flags)) return -1;
|
||||
if ((mode & ~W_OK) == 0 || real(dirfd, path, mode & ~W_OK, flags) == 0) return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int check_cwd(const char *path, int mode, int flags) {
|
||||
int (*real)(int, const char *, int, int) = next_faccessat();
|
||||
int result;
|
||||
int err;
|
||||
|
||||
if (real == NULL) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
result = real(AT_FDCWD, path, mode, flags);
|
||||
return result != 0 && errno == EACCES && bl_binfmt_runnable(path, mode) ? 0 : result;
|
||||
if (result == 0) return 0;
|
||||
err = errno;
|
||||
if (err == EACCES && bl_binfmt_runnable(path, mode)) return 0;
|
||||
errno = err;
|
||||
if (writable_as_owner(real, AT_FDCWD, path, mode, flags) == 0) return 0;
|
||||
errno = err;
|
||||
return result;
|
||||
}
|
||||
|
||||
int access(const char *path, int mode) {
|
||||
@@ -166,6 +180,7 @@ int eaccess(const char *path, int mode) {
|
||||
|
||||
int faccessat(int dirfd, const char *path, int mode, int flags) {
|
||||
int (*real)(int, const char *, int, int);
|
||||
int err;
|
||||
|
||||
if (dirfd == AT_FDCWD) {
|
||||
return cached_access(path, mode, flags, check_cwd);
|
||||
@@ -175,5 +190,9 @@ int faccessat(int dirfd, const char *path, int mode, int flags) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
return real(dirfd, path, mode, flags);
|
||||
if (real(dirfd, path, mode, flags) == 0) return 0;
|
||||
err = errno;
|
||||
if (writable_as_owner(real, dirfd, path, mode, flags) == 0) return 0;
|
||||
errno = err;
|
||||
return -1;
|
||||
}
|
||||
Reference in new issue
Block a user