| 67 | } |
| 68 | |
| 69 | bool File::open() { |
| 70 | if (isFileValid()) { |
| 71 | return true; |
| 72 | } |
| 73 | auto pair = OpenFlag2NativeFlag(m_flag); |
| 74 | m_fd = CreateFile(m_path.c_str(), pair.first, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, |
| 75 | pair.second, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 76 | if (!isFileValid()) { |
| 77 | MMKVError("fail to open:[%s], flag %x, error %d", m_utf8Path.c_str(), m_flag, GetLastError()); |
| 78 | return false; |
| 79 | } |
| 80 | MMKVInfo("open fd[%p], flag %x, %s", m_fd, m_flag, m_utf8Path.c_str()); |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | void File::close() { |
| 85 | if (isFileValid()) { |
no test coverage detected