mirror of
https://github.com/Tencent/MMKV.git
synced 2026-10-17 04:30:56 +08:00
protect from file size change on multi-process load #1599
This commit is contained in:
@@ -72,6 +72,13 @@ void MMKV::loadFromFile() {
|
||||
#endif
|
||||
if (!m_file->isFileValid()) {
|
||||
m_file->reloadFromFile(m_expectedCapacity);
|
||||
} else if (isMultiProcess()) {
|
||||
// the file size may change by other process between instance creation and loadFromFile
|
||||
// because we have lazy load
|
||||
auto actualFileSize = m_file->getActualFileSize();
|
||||
if (actualFileSize != m_file->getFileSize()) {
|
||||
m_file->reloadFromFile(m_expectedCapacity);
|
||||
}
|
||||
}
|
||||
if (!m_file->isFileValid()) {
|
||||
MMKVError("file [%s] not valid", m_path.c_str());
|
||||
|
||||
Reference in New Issue
Block a user