Skip to content

Commit b4fb82a

Browse files
committed
Use thread safe stream.
1 parent 6051af4 commit b4fb82a

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

src/Applications/Applications/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ subject-prefix: ''
3838
3939
``` yaml
4040
directive:
41+
# Remove invalid paths.
42+
- remove-path-by-operation: onPremisesPublishingProfiles\.(connectors\.memberOf_.*|connectors_GetMemberOf|connectorGroups\.members_.*|connectorGroups_(Get|Create|Update|Delete)Members)
43+
4144
# Remove cmdlets
4245
- where:
4346
verb: Test
@@ -69,6 +72,11 @@ directive:
6972
subject: ^OnPremis(PublishingProfile.*)$
7073
set:
7174
subject: OnPremise$1
75+
# Fix cmdlet name
76+
- where:
77+
subject: (^OnPremisePublishingProfileConnectorMember$)
78+
set:
79+
subject: $1Of
7280
```
7381
### Versioning
7482

src/Authentication/Authentication/Common/DiskDataStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.Graph.PowerShell.Authentication.Common
1111
/// <summary>
1212
/// Disk data store based on System.IO APIs.
1313
/// </summary>
14-
internal class DiskDataStore : IDataStore
14+
public class DiskDataStore : IDataStore
1515
{
1616
/// <summary>
1717
/// Writes the given contents to the specified file.

src/Authentication/Authentication/Common/ProtectedFileProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public enum FileProtection
2222
/// The file can be accessed in ReadOnly or ReadWrite mode.
2323
/// This class MUST be disposed by the caller.
2424
/// </summary>
25-
internal abstract class ProtectedFileProvider : IFileProvider, IDisposable
25+
public abstract class ProtectedFileProvider : IFileProvider, IDisposable
2626
{
2727
protected Stream _stream;
2828
public const int MaxTries = 30;

src/Files/Files/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ subject-prefix: ''
3838
3939
``` yaml
4040
directive:
41-
- remove-path-by-operation: .*_(Create|Get|Update|Set|Delete)Activities$|.*\.activities.*$
41+
- remove-path-by-operation: .*_(Create|Get|Update|Set|Delete)Activities$|.*\.activities.*$|shares\..*_createLink
4242
```
4343
### Versioning
4444

tools/Custom/FileUploadCmdlet.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// ------------------------------------------------------------------------------
44
namespace Microsoft.Graph.PowerShell.Cmdlets.Custom
55
{
6+
using Microsoft.Graph.PowerShell.Authentication.Common;
67
using System.IO;
78
using System.Management.Automation;
89

@@ -31,7 +32,8 @@ internal Stream GetFileAsStream()
3132
if (MyInvocation.BoundParameters.ContainsKey(nameof(InFile)))
3233
{
3334
string resolvedFilePath = this.GetProviderPath(InFile, true);
34-
return new FileStream(resolvedFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
35+
var fileProvider = ProtectedFileProvider.CreateFileProvider(resolvedFilePath, FileProtection.SharedRead, new DiskDataStore());
36+
return fileProvider.Stream;
3537
}
3638
else
3739
{

tools/Custom/PSCmdletExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// ------------------------------------------------------------------------------
44
namespace Microsoft.Graph.PowerShell
55
{
6+
using Microsoft.Graph.PowerShell.Authentication.Common;
67
using System;
78
using System.Collections.ObjectModel;
89
using System.IO;
@@ -62,9 +63,9 @@ internal static string GetProviderPath(this PSCmdlet cmdlet, string filePath, bo
6263
/// <param name="cancellationToken">A cancellation token that will be used to cancel the operation by the user.</param>
6364
internal static void WriteToFile(this PSCmdlet cmdlet, Stream inputStream, string filePath, CancellationToken cancellationToken)
6465
{
65-
using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
66+
using (var fileProvider = ProtectedFileProvider.CreateFileProvider(filePath, FileProtection.ExclusiveWrite, new DiskDataStore()))
6667
{
67-
cmdlet.WriteToStream(inputStream, fileStream, cancellationToken);
68+
cmdlet.WriteToStream(inputStream, fileProvider.Stream, cancellationToken);
6869
}
6970
}
7071

0 commit comments

Comments
 (0)