Skip to content

Commit 9b20b33

Browse files
committed
(GH-943) IFileSystem - Open File Exclusively
Add method for opening a file exclusively.
1 parent b7974d5 commit 9b20b33

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs

+5
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ public FileStream open_file_readonly(string filePath)
382382
return File.OpenRead(filePath);
383383
}
384384

385+
public FileStream open_file_exclusive(string filePath)
386+
{
387+
return File.Open(filePath,FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.None);
388+
}
389+
385390
public void write_file(string filePath, string fileText)
386391
{
387392
write_file(filePath, fileText, file_exists(filePath) ? get_file_encoding(filePath) : Encoding.UTF8);

src/chocolatey/infrastructure/filesystem/IFileSystem.cs

+7
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ public interface IFileSystem
238238
/// <returns>A file stream object for use after accessing the file</returns>
239239
FileStream open_file_readonly(string filePath);
240240

241+
/// <summary>
242+
/// Opens a file exlusively
243+
/// </summary>
244+
/// <param name="filePath">Path to the file name</param>
245+
/// <returns>A file stream object for use after accessing the file</returns>
246+
FileStream open_file_exclusive(string filePath);
247+
241248
/// <summary>
242249
/// Writes the file text to the specified path
243250
/// </summary>

0 commit comments

Comments
 (0)