Skip to content

Commit

Permalink
(GH-943) IFileSystem - Open File Exclusively
Browse files Browse the repository at this point in the history
Add method for opening a file exclusively.
  • Loading branch information
ferventcoder committed Sep 16, 2016
1 parent b7974d5 commit 9b20b33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ public FileStream open_file_readonly(string filePath)
return File.OpenRead(filePath);
}

public FileStream open_file_exclusive(string filePath)
{
return File.Open(filePath,FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.None);
}

public void write_file(string filePath, string fileText)
{
write_file(filePath, fileText, file_exists(filePath) ? get_file_encoding(filePath) : Encoding.UTF8);
Expand Down
7 changes: 7 additions & 0 deletions src/chocolatey/infrastructure/filesystem/IFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ public interface IFileSystem
/// <returns>A file stream object for use after accessing the file</returns>
FileStream open_file_readonly(string filePath);

/// <summary>
/// Opens a file exlusively
/// </summary>
/// <param name="filePath">Path to the file name</param>
/// <returns>A file stream object for use after accessing the file</returns>
FileStream open_file_exclusive(string filePath);

/// <summary>
/// Writes the file text to the specified path
/// </summary>
Expand Down

0 comments on commit 9b20b33

Please sign in to comment.