> void JsonStorage::save(bool bIgnoreLength) { if (nullptr == _document) { assert(0); return; } SYNCHRONIZED(); std::string jsonString = rapidjson::getReprsentedString(*_document); if (jsonString.length() > MIN_JSON_LENGTH || bIgnoreLength) { //GCL-3613, directly write to original file will clear the file first, if crash happend in this step, the file contents will lost; // so next time re-launch app will be not in signin status; // using a more safe method to save file; std::string tempFileName = _filename + "_temp"; #ifdef _MSC_VER FILE *fp = fopen(tempFileName.c_str(), "wb"); if (fp) { fwrite(jsonString.c_str(), 1, jsonString.length(), fp); fclose(fp); remove(_filename.c_str()); #else int fp = ::open(tempFileName.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fp != -1) { write(fp, jsonString.c_str(), jsonString.length()); ::close(fp); #endif // move temp file to overwitten original one; rename(tempFileName.c_str(), _filename.c_str()); } } }