private async Task HandleNotExistsInCloud(B2Db b2Db, string filePath, ulong xhash, string parentPath, string b2Path) { FileObject existingFileObject = b2Db.GetFileObject(filePath); // fo exists but not uploaded yet if (existingFileObject != null && existingFileObject.B2Files.Count == 0) { UploadList.Add(new UploadObject(existingFileObject, parentPath, b2Path)); } // fo exists and b2file exits but not available on cloud, so clear b2file object else if (existingFileObject != null && existingFileObject.B2Files.Count >= 0) { existingFileObject.B2Files.Clear(); existingFileObject.DateModified = DateTime.Now; await b2Db.UpdateFileObject(existingFileObject); UploadList.Add(new UploadObject(existingFileObject, parentPath, b2Path)); } // no fo, no b2file else { FileObject tempFileObject = new FileObject(filePath, xhash); await b2Db.Add(tempFileObject); UploadList.Add(new UploadObject(tempFileObject, parentPath, b2Path)); } }
private async Task HandleIfExistsInCloud(B2Db b2Db, string filePath, B2File existingB2File, ulong xhash, string parentPath, string b2Path) { // try find local object in db FileObject existingFileObject = b2Db.GetFileObject(filePath); if (existingFileObject != null && existingFileObject.B2Files.ContainsKey(existingB2File.FileId)) { // local object xhash diff from cloud, then mark this for upload if (existingFileObject.Xhash != xhash) { existingFileObject.Xhash = xhash; UploadList.Add(new UploadObject(existingFileObject, parentPath, b2Path)); } } // if existing file object is available but b2file object is not available else if (existingFileObject != null && !existingFileObject.B2Files.ContainsKey(existingB2File.FileId)) { // update b2file object and does not need to reupload if (existingB2File.ContentSHA1.Equals("none") || Utils.FilepathToSha1Hash(filePath).Equals(existingB2File.ContentSHA1.Replace("unverified:", ""), StringComparison.InvariantCultureIgnoreCase)) { existingFileObject.B2Files.Add(existingB2File.FileId, existingB2File); existingFileObject.DateModified = DateTime.Now; await b2Db.UpdateFileObject(existingFileObject); } else // mark this object to upload if diff sha { existingFileObject.Xhash = xhash; UploadList.Add(new UploadObject(existingFileObject, parentPath, b2Path)); } } else { // local not available, so check it's sha1hash when same add to db or mark to upload FileObject tempFileObject = new FileObject(filePath, xhash); if (existingB2File.ContentSHA1.Equals("none") || Utils.FilepathToSha1Hash(filePath).Equals(existingB2File.ContentSHA1.Replace("unverified:", ""), StringComparison.InvariantCultureIgnoreCase)) { tempFileObject.B2Files.Add(existingB2File.FileId, existingB2File); await b2Db.Add(tempFileObject); } else { UploadList.Add(new UploadObject(tempFileObject, parentPath, b2Path)); } } }