Retry opening without the O_NOATIME flag

According to the description at [man7.org](https://man7.org/linux/man-pages/man2/open.2.html),
you must either be the owner of the file or have sudo privileges for
the `O_NOATIME` flag:

- The effective UID of the process matches the owner UID
  of the file.

- The calling process has the CAP_FOWNER capability in its
  user namespace and the owner UID of the file has a
  mapping in the namespace.

The pCloud library code checks the file permissions and handles them
accordingly, but the library cannot open another user's file due to
the flag. To work around this, it first tries to open the file with
the flag, and if that fails, it tries again without the flag.
This commit is contained in:
Chris82111 2026-02-26 20:00:31 +01:00
parent b9ea6ca4c9
commit 047e27aca2
1 changed files with 11 additions and 3 deletions

View File

@ -125,11 +125,19 @@ int pfile_open(const char *path, int access, int flags) {
flags |= O_NOATIME;
#endif
fd = open(path, access | flags, PSYNC_DEFAULT_POSIX_FILE_MODE);
if (unlikely(fd == -1)) {
while (errno == EINTR) {
#if defined(O_NOATIME)
if ((-1 == fd ) && (EPERM == errno)) {
flags &= ~O_NOATIME;
fd = open(path, access | flags, PSYNC_DEFAULT_POSIX_FILE_MODE);
}
#endif
if (unlikely(-1 == fd)) {
while (EINTR == errno) {
pdbg_logf(D_NOTICE, "got EINTR while opening file");
fd = open(path, access | flags, PSYNC_DEFAULT_POSIX_FILE_MODE);
if (fd != -1)
if (-1 != fd)
return fd;
}
}