-
Couldn't load subscription status.
- Fork 327
Add ability to enable Read Sharing when Writing to files #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,6 @@ | ||||||
| using NUnit.Framework; | ||||||
| using System.Threading; | ||||||
| using System.Threading.Tasks; | ||||||
| using TagLib; | ||||||
|
|
||||||
| namespace TaglibSharp.Tests.FileFormats | ||||||
|
|
@@ -133,5 +135,43 @@ public void TestCreateId3Tags () | |||||
| file = File.Create (tempFile); | ||||||
| Assert.AreEqual (TagTypes.Id3v1 | TagTypes.Id3v2, file.TagTypes); | ||||||
| } | ||||||
|
|
||||||
| [Test] | ||||||
| public async Task TestReadShareWhenWriting () | ||||||
| { | ||||||
| // Simulate having another thread open the file and begin playing it (by | ||||||
| // keeping it open) until we tell it to stop playback and close the file. | ||||||
| SemaphoreSlim playbackStarted = new SemaphoreSlim (0); | ||||||
| SemaphoreSlim stopPlayback = new SemaphoreSlim (0); | ||||||
| _ = Task.Run (async () => { | ||||||
| using (var fileToPlay = System.IO.File.Open (tmp_file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite)) { | ||||||
|
||||||
| using (var fileToPlay = System.IO.File.Open (tmp_file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite)) { | |
| using (var readOnlyFileStream = System.IO.File.Open (tmp_file, FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite)) { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,12 @@ public enum AccessMode | |
| /// </summary> | ||
| List<string> corruption_reasons; | ||
|
|
||
| /// <summary> | ||
| /// Specifies whether the file should be readable by other | ||
| /// threads while being written to by the thread that opened it. | ||
| /// </summary> | ||
| public bool read_share_when_writing; | ||
|
|
||
| #endregion | ||
|
|
||
|
|
||
|
|
@@ -1621,7 +1627,15 @@ public LocalFileAbstraction (string path) | |
| /// </value> | ||
| public Stream WriteStream => System.IO.File.Open (Name, | ||
| FileMode.Open, | ||
| FileAccess.ReadWrite); | ||
| FileAccess.ReadWrite, | ||
| ReadShareWhenWriting ? FileShare.Read : FileShare.None); | ||
|
||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value indicating whether the file should | ||
| /// be readable by other threads while being written to by | ||
| /// the thread that opened it. | ||
| /// </summary> | ||
| public bool ReadShareWhenWriting { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Closes a stream created by the current instance. | ||
|
|
@@ -1793,6 +1807,19 @@ public interface IFileAbstraction | |
| /// </remarks> | ||
| Stream WriteStream { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value indicating whether the file | ||
| /// should be readable by other threads while being | ||
| /// written to by the thread that opened it. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This property is useful when editing ID3 tags of | ||
| /// MP3 files. In particular, setting it to true | ||
| /// ensures you can listen to a song in one application | ||
| /// while simultaneously editing its ID3 tags in another. | ||
| /// </remarks> | ||
| bool ReadShareWhenWriting { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Closes a stream originating from the current | ||
| /// instance. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The discarded task should be awaited or stored in a variable to handle potential exceptions. Consider using
var backgroundTask = Task.Run(...)and awaiting it at the end of the test.