From 047e27aca25ebeda03f83b0bcff4c1a717942b4d Mon Sep 17 00:00:00 2001 From: Chris82111 <75613723+Chris82111@users.noreply.github.com> Date: Thu, 26 Feb 2026 20:00:31 +0100 Subject: [PATCH] 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. --- pclsync/pfile.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pclsync/pfile.c b/pclsync/pfile.c index 0226394..fbf1d94 100644 --- a/pclsync/pfile.c +++ b/pclsync/pfile.c @@ -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; } }