SB2 Bug using std::filesystem

Using std::filesystem operations in a program built in the SDK results in odd/incorrect file permissions.

Please see this minimal test case:
As you can see, test.out has only w permission, no r permission when copied with

std::filesystem::copy
In SDK:
    #include <filesystem>
    ​
    int main(int argc, char *argv[])
    {
    ​
        std::filesystem::path src(argv[1]);
        std::filesystem::path dst(argv[2]);
    ​
    ​
        std::error_code ec;
        std::filesystem::copy(src, dst, std::filesystem::copy_options::update_existing, ec);
    }
    [SailfishOS-4.6.0.11EA-aarch64] upstream # clang++ -std=c++17 test.cpp
    [SailfishOS-4.6.0.11EA-aarch64] upstream # ./a.out test.cpp test.out
    [SailfishOS-4.6.0.11EA-aarch64] upstream # ls -lh test.*
    -rw-r--r-- 1 1001 1001 256 Sep 19 15:43 test.cpp
    -rw-r--r-- 1 root root 256 Sep 19 15:46 test.out
    ​
    ​
    On Host:
    ​
    ╰ $ ls -lh test.*
    -rw-r--r-- 1 piggz piggz 256 Sep 19 16:43 test.cpp
    --w------- 1 piggz piggz 256 Sep 19 16:46 test.out
1 Like

These are the syscalls made when the same program is run on my host (strace doesnt work in the sdk)

openat(AT_FDCWD, “test.cpp”, O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, “test.out”, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0200) = 4
fchmod(4, 0100644) = 0
sendfile(4, 3, [0] => [184], 184) = 184
close(4) = 0
close(3) = 0

Maybe fchmod isnt implemented correctly?

1 Like

When updating permissions using command line chmod within the sdk, permissions appear to update correctly, but on the host the remain the same. Becuase on the host there is no r permission, its not possible to cp a file within the sdk

[SailfishOS-4.6.0.11EA-aarch64] upstream # cp test.out test.2
cp: cannot open ‘test.out’ for reading: Operation not permitted
[SailfishOS-4.6.0.11EA-aarch64] upstream # ls -lh test.*
-rw-r–r-- 1 1001 1001 239 Sep 19 16:17 test.cpp
-rw----r-- 1 root root 239 Sep 19 16:24 test.out

1 Like

@vige Just tagging you as this bug report isnt in the general bug reports category :slight_smile:

Searching fchmod doesn’t yield good results on scratchbox2, maybe it is really not supported?

Tagging @martyone or @Thaodan might be more effective :slight_smile: