[smuxi/experiments/sqlite: 12/27] [Engine] Correctly lock CommitMessage before use
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi/experiments/sqlite: 12/27] [Engine] Correctly lock CommitMessage before use
- Date: Sun, 23 Feb 2014 17:07:23 +0000 (UTC)
commit 47b42b7846b449d85f2bb83e6751e20b30c9c8a4
Author: Mirco Bauer <meebey meebey net>
Date: Sun Feb 26 12:14:48 2012 +0100
[Engine] Correctly lock CommitMessage before use
src/Engine/MessageBuffers/GitMessageBuffer.cs | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/src/Engine/MessageBuffers/GitMessageBuffer.cs b/src/Engine/MessageBuffers/GitMessageBuffer.cs
index b197fa4..1ffa07b 100644
--- a/src/Engine/MessageBuffers/GitMessageBuffer.cs
+++ b/src/Engine/MessageBuffers/GitMessageBuffer.cs
@@ -105,7 +105,6 @@ namespace Smuxi.Engine
var msgFilePath = Path.Combine(RepositoryPath, msgFileName);
using (var writer = File.OpenWrite(msgFilePath))
using (var textWriter = new StreamWriter(writer, Encoding.UTF8)) {
- //JsonSerializer.SerializeToStream(msg, writer);
JsonSerializer.SerializeToWriter(msg, textWriter);
}
@@ -126,9 +125,11 @@ namespace Smuxi.Engine
// FIXME: delete file when index was written to disk
File.Delete(msgFilePath);
- CommitMessage.Append(
- String.Format("{0}: {1}\n", msgFileName, msg.ToString())
- );
+ lock (CommitMessage) {
+ CommitMessage.Append(
+ String.Format("{0}: {1}\n", msgFileName, msg.ToString())
+ );
+ }
// TODO: create tree, commit tree, repack repo reguraly (see rugged docs)
}
@@ -232,8 +233,9 @@ namespace Smuxi.Engine
if (repo == null) {
return;
}
- lock (repo) {
- if (repo.Index.Count == 0 || CommitMessage.Length == 0) {
+ lock (repo)
+ lock (CommitMessage) {
+ if (CommitMessage.Length == 0) {
// nothing to commit
return;
}
@@ -249,7 +251,6 @@ namespace Smuxi.Engine
#endif
start = DateTime.UtcNow;
- // FIXME: CommitMessage is not thread-safe!
repo.Commit(CommitMessage.ToString(), false);
stop = DateTime.UtcNow;
#if MSGBUF_DEBUG
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]