Fixed bug in IOConnection.cs: Errors when uploading data to http(s) were not handled correctly
Improved logging in CachingFileStorage
This commit is contained in:
		| @@ -506,11 +506,12 @@ namespace KeePassLib.Serialization | |||||||
| 			} | 			} | ||||||
| 			catch (WebException ex) | 			catch (WebException ex) | ||||||
| 			{ | 			{ | ||||||
| 				if ((ex.Response is HttpWebResponse) && (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Unauthorized)) | 				if ((ex.Response is HttpWebResponse) && (((HttpWebResponse) ex.Response).StatusCode == HttpStatusCode.Unauthorized)) | ||||||
| 				{ | 				{ | ||||||
| 					req = CreateWebRequest(ioc, true); | 					req = CreateWebRequest(ioc, true); | ||||||
| 					f(req); | 					f(req); | ||||||
| 				} | 				} | ||||||
|  | 				else throw; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -146,10 +146,12 @@ namespace keepass2android.Io | |||||||
| 				if (!IsCached(ioc) | 				if (!IsCached(ioc) | ||||||
| 				    || GetLocalVersionHash(ioc) == GetBaseVersionHash(ioc)) | 				    || GetLocalVersionHash(ioc) == GetBaseVersionHash(ioc)) | ||||||
| 				{ | 				{ | ||||||
|  | 					Kp2aLog.Log("CFS: OpenWhenNoLocalChanges"); | ||||||
| 					return OpenFileForReadWhenNoLocalChanges(ioc, cachedFilePath); | 					return OpenFileForReadWhenNoLocalChanges(ioc, cachedFilePath); | ||||||
| 				} | 				} | ||||||
| 				else | 				else | ||||||
| 				{ | 				{ | ||||||
|  | 					Kp2aLog.Log("CFS: OpenWhenLocalChanges"); | ||||||
| 					return OpenFileForReadWhenLocalChanges(ioc, cachedFilePath); | 					return OpenFileForReadWhenLocalChanges(ioc, cachedFilePath); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| @@ -174,16 +176,21 @@ namespace keepass2android.Io | |||||||
|  |  | ||||||
| 			if (File.ReadAllText(BaseVersionFilePath(ioc)) == hash) | 			if (File.ReadAllText(BaseVersionFilePath(ioc)) == hash) | ||||||
| 			{ | 			{ | ||||||
|  | 				Kp2aLog.Log("CFS: No changes in remote"); | ||||||
| 				//no changes in remote file -> upload | 				//no changes in remote file -> upload | ||||||
| 				using (Stream localData = File.OpenRead(CachedFilePath(ioc))) | 				using (Stream localData = File.OpenRead(CachedFilePath(ioc))) | ||||||
| 				{ | 				{ | ||||||
| 					if (TryUpdateRemoteFile(localData, ioc, true, hash)) | 					if (TryUpdateRemoteFile(localData, ioc, true, hash)) | ||||||
|  | 					{ | ||||||
| 						_cacheSupervisor.UpdatedRemoteFileOnLoad(ioc); | 						_cacheSupervisor.UpdatedRemoteFileOnLoad(ioc); | ||||||
|  | 						Kp2aLog.Log("CFS: Updated remote file"); | ||||||
|  | 					} | ||||||
| 					return File.OpenRead(cachedFilePath); | 					return File.OpenRead(cachedFilePath); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			else | 			else | ||||||
| 			{ | 			{ | ||||||
|  | 				Kp2aLog.Log("CFS: Files in conflict"); | ||||||
| 				//conflict: both files changed. | 				//conflict: both files changed. | ||||||
| 				return OpenFileForReadWithConflict(ioc, cachedFilePath); | 				return OpenFileForReadWithConflict(ioc, cachedFilePath); | ||||||
| 			} | 			} | ||||||
| @@ -232,20 +239,27 @@ namespace keepass2android.Io | |||||||
| 			string previousHash = null; | 			string previousHash = null; | ||||||
| 			string baseVersionFilePath = BaseVersionFilePath(ioc); | 			string baseVersionFilePath = BaseVersionFilePath(ioc); | ||||||
| 			if (File.Exists(baseVersionFilePath)) | 			if (File.Exists(baseVersionFilePath)) | ||||||
|  | 			{ | ||||||
|  | 				Kp2aLog.Log("CFS: hashing cached version"); | ||||||
| 				previousHash = File.ReadAllText(baseVersionFilePath); | 				previousHash = File.ReadAllText(baseVersionFilePath); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			//copy to cache:  | ||||||
|  | 			var fileHash = UpdateCacheFromRemote(ioc, cachedFilePath); | ||||||
|  |  | ||||||
|  | 			//notify supervisor what we did: | ||||||
|  | 			if (previousHash != fileHash) | ||||||
|  | 			{ | ||||||
|  | 				Kp2aLog.Log("CFS: Updated Cache"); | ||||||
|  | 				_cacheSupervisor.UpdatedCachedFileOnLoad(ioc); | ||||||
|  | 			} | ||||||
|  | 			else | ||||||
|  | 			{ | ||||||
|  | 				Kp2aLog.Log("CFS: Files in Sync"); | ||||||
|  | 				_cacheSupervisor.LoadedFromRemoteInSync(ioc); | ||||||
|  | 			} | ||||||
|  |  | ||||||
| 				//copy to cache:  | 			return File.OpenRead(cachedFilePath);	 | ||||||
| 				var fileHash = UpdateCacheFromRemote(ioc, cachedFilePath); |  | ||||||
|  |  | ||||||
| 				//notify supervisor what we did: |  | ||||||
| 				if (previousHash != fileHash) |  | ||||||
| 					_cacheSupervisor.UpdatedCachedFileOnLoad(ioc); |  | ||||||
| 				else |  | ||||||
| 					_cacheSupervisor.LoadedFromRemoteInSync(ioc); |  | ||||||
|  |  | ||||||
| 				return File.OpenRead(cachedFilePath);	 |  | ||||||
|  |  | ||||||
| 			 | 			 | ||||||
| 		} | 		} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Philipp Crocoll
					Philipp Crocoll