Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6530,7 +6530,7 @@ public IContentWriter GetContentWriter(string path)
return stream;
}

stream = new FileSystemContentReaderWriter(path, streamName, filemode, FileAccess.Write, FileShare.Write, encoding, usingByteEncoding, false, this, false, suppressNewline);
stream = new FileSystemContentReaderWriter(path, streamName, filemode, FileAccess.Write, FileShare.ReadWrite, encoding, usingByteEncoding, false, this, false, suppressNewline);
}
catch (PathTooLongException pathTooLong)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Add-Content cmdlet tests" -Tags "CI" {
$file1 = "file1.txt"
Setup -File "$file1"

BeforeAll {
$file1 = "file1.txt"
Setup -File "$file1"
}

Context "Add-Content should actually add content" {
It "should Add-Content to TestDrive:\$file1" {
Expand Down Expand Up @@ -40,7 +43,7 @@ Describe "Add-Content cmdlet tests" -Tags "CI" {
{ Add-Content -Path $() -Value "ShouldNotWorkBecausePathIsInvalid" -ErrorAction Stop } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand"
}

It "Should throw an error on a directory" {
It "Should throw an error on a directory" {
{ Add-Content -Path . -Value "WriteContainerContentException" -ErrorAction Stop } | Should -Throw -ErrorId "WriteContainerContentException,Microsoft.PowerShell.Commands.AddContentCommand"
}

Expand All @@ -57,5 +60,22 @@ Describe "Add-Content cmdlet tests" -Tags "CI" {
$result[0] | Should -BeExactly "hello"
$result[1] | Should -BeExactly "world"
}

It "Should not block reads while writing" {
$logpath = Join-Path $testdrive "test.log"

Set-Content $logpath -Value "hello"

$f = [System.IO.FileStream]::new($logpath, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)

Add-Content $logpath -Value "world"

$f.Close()

$content = Get-Content $logpath
$content | Should -HaveCount 2
$content[0] | Should -BeExactly "hello"
$content[1] | Should -BeExactly "world"
}
}
}