Tencent / MMKV

An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.
Other
17.39k stars 1.91k forks source link

windows,访问没有写权限目录下的mmkv数据库失败 #1383

Closed snoopyIV closed 2 months ago

snoopyIV commented 2 months ago

Note:

An crash issue will be ignored & closed in a week without logs.

The language of MMKV

c++

The version of MMKV

latest(看了下master分支上的代码也是同样的问题)

The platform of MMKV

windows

The installation of MMKV

cmake, use with dynamic library(mmkv.dll)

What's the issue?

windows平台,在没有目录的写权限时,读取mmkv数据库内容失败。 原因是代码中要求使用读写权限打开。请问mmkv是否支持只读的方式打开,因为应用程序期望只访问数据库中的数据但是不进行写入? On the Windows platform, reading the contents of the MMKV database failed when there is no write permission for the directory. The reason is that the code requires the use of read-write permissions to open . May I ask if MMKV supports read-only access, as the application expects to only access data in the database without writing it?

code here: https://github.com/Tencent/MMKV/blob/master/Core/MemoryFile_Win32.cpp

bool File::open() {
    if (isFileValid()) {
        return true;
    }
    auto pair = OpenFlag2NativeFlag(m_flag);
    m_fd = CreateFile(m_path.c_str(), pair.first, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
                      pair.second, FILE_ATTRIBUTE_NORMAL, nullptr);
    if (!isFileValid()) {
        MMKVError("fail to open:[%ls], %d", m_path.c_str(), GetLastError());
        return false;
    }
    MMKVInfo("open fd[%p], %ls", m_fd, m_path.c_str());
    return true;
}

What's the log of MMKV when that happened?

nothing

### Tasks
lingol commented 2 months ago

Yes, that's a long-requested feature we don't have time to implement.

snoopyIV commented 2 months ago

ok, I‘ll close this issue later. Waiting for the better mmkv coming.

lingol commented 1 month ago

It's supported in the dev branch. You can try it out.

lingol commented 6 days ago

v2.0.0 with readonly mode is out.