diff --git a/Common/Common/Persistence/PersistenceController.cs b/Common/Common/Persistence/PersistenceController.cs index 46a76c1..a3c494b 100644 --- a/Common/Common/Persistence/PersistenceController.cs +++ b/Common/Common/Persistence/PersistenceController.cs @@ -19,7 +19,7 @@ namespace LeanCloud.Common { } string path = GetFileFullPath(filename); - using (FileStream fs = IOFile.OpenWrite(path)) { + using (FileStream fs = IOFile.Create(path)) { byte[] buffer = Encoding.UTF8.GetBytes(text); await fs.WriteAsync(buffer, 0, buffer.Length); } diff --git a/Storage/Storage/Public/LCObject.cs b/Storage/Storage/Public/LCObject.cs index 38d5e9c..62868ea 100644 --- a/Storage/Storage/Public/LCObject.cs +++ b/Storage/Storage/Public/LCObject.cs @@ -572,8 +572,8 @@ namespace LeanCloud.Storage { public void Merge(LCObjectData objectData) { data.ClassName = objectData.ClassName ?? data.ClassName; data.ObjectId = objectData.ObjectId ?? data.ObjectId; - data.CreatedAt = objectData.CreatedAt != null ? objectData.CreatedAt : data.CreatedAt; - data.UpdatedAt = objectData.UpdatedAt != null ? objectData.UpdatedAt : data.UpdatedAt; + data.CreatedAt = !objectData.CreatedAt.Equals(default) ? objectData.CreatedAt : data.CreatedAt; + data.UpdatedAt = !objectData.UpdatedAt.Equals(default) ? objectData.UpdatedAt : data.UpdatedAt; // 先将本地的预估数据直接替换 data.CustomPropertyDict = estimatedData; // 再将服务端的数据覆盖 diff --git a/Storage/Storage/Public/LCUser.cs b/Storage/Storage/Public/LCUser.cs index ef0957e..ea8143d 100644 --- a/Storage/Storage/Public/LCUser.cs +++ b/Storage/Storage/Public/LCUser.cs @@ -127,9 +127,6 @@ namespace LeanCloud.Storage { throw new ArgumentException("Cannot sign up a user that already exists."); } await Save(); - currentUser = this; - - await SaveToLocal(); return this; } @@ -555,7 +552,7 @@ namespace LeanCloud.Storage { { authType, data } }; try { - await Save(); + await base.Save(); oriAuthData[authType] = data; await UpdateAuthData(oriAuthData); } catch (Exception e) { @@ -570,7 +567,7 @@ namespace LeanCloud.Storage { { authType, null } }; try { - await Save(); + await base.Save(); oriAuthData.Remove(authType); await UpdateAuthData(oriAuthData); } catch (Exception e) { @@ -765,5 +762,12 @@ namespace LeanCloud.Storage { } return result; } + + public new async Task Save(bool fetchWhenSave = false, LCQuery query = null) { + await base.Save(fetchWhenSave, query); + currentUser = this; + await SaveToLocal(); + return this; + } } }