Skip to content
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

mark FileStream.Lock and Unlock as unsupported on macOS #47040

Merged
merged 4 commits into from
Feb 8, 2021
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 @@ -394,12 +394,16 @@ public static void Input(int FileNumber, ref long Value) { }
public static void Input(int FileNumber, ref object Value) { }
public static void Input(int FileNumber, ref float Value) { }
public static void Input(int FileNumber, ref string Value) { }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public static string InputString(int FileNumber, int CharCount) { throw null; }
public static void Kill(string PathName) { }
public static string LineInput(int FileNumber) { throw null; }
public static long Loc(int FileNumber) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public static void Lock(int FileNumber) { }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public static void Lock(int FileNumber, long Record) { }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public static void Lock(int FileNumber, long FromRecord, long ToRecord) { }
public static long LOF(int FileNumber) { throw null; }
public static void MkDir(string Path) { }
Expand All @@ -415,8 +419,11 @@ public static void SetAttr(string PathName, Microsoft.VisualBasic.FileAttribute
public static Microsoft.VisualBasic.SpcInfo SPC(short Count) { throw null; }
public static Microsoft.VisualBasic.TabInfo TAB() { throw null; }
public static Microsoft.VisualBasic.TabInfo TAB(short Column) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public static void Unlock(int FileNumber) { }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public static void Unlock(int FileNumber, long Record) { }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public static void Unlock(int FileNumber, long FromRecord, long ToRecord) { }
public static void Write(int FileNumber, params object[] Output) { }
public static void WriteLine(int FileNumber, params object[] Output) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Imports System
Imports Microsoft.VisualBasic.CompilerServices.ExceptionUtils
Imports Microsoft.VisualBasic.CompilerServices.Utils
Imports System.Runtime.Versioning

Namespace Microsoft.VisualBasic.CompilerServices

Expand All @@ -24,6 +25,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Sub

' the implementation of Lock in base class VB6RandomFile does not handle m_lRecordLen=-1
<UnsupportedOSPlatform("macos")>
Friend Overloads Overrides Sub Lock(ByVal lStart As Long, ByVal lEnd As Long)
If lStart > lEnd Then
Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start"))
Expand All @@ -47,6 +49,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Sub

' see Lock description
<UnsupportedOSPlatform("macos")>
Friend Overloads Overrides Sub Unlock(ByVal lStart As Long, ByVal lEnd As Long)
If lStart > lEnd Then
Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Imports System.Security
Imports System.Globalization
Imports System.IO
Imports System.Text
Imports System.Runtime.Versioning

Imports Microsoft.VisualBasic.CompilerServices.StructUtils
Imports Microsoft.VisualBasic.CompilerServices.ExceptionUtils
Expand Down Expand Up @@ -595,15 +596,18 @@ Namespace Microsoft.VisualBasic.CompilerServices
Return m_position
End Function

<UnsupportedOSPlatform("macos")>
Friend Overridable Overloads Sub Lock()
'Lock the whole file, not just the current size of file, since file could change.
m_file.Lock(0, Int32.MaxValue)
End Sub

<UnsupportedOSPlatform("macos")>
Friend Overridable Overloads Sub Unlock()
m_file.Unlock(0, Int32.MaxValue)
End Sub

<UnsupportedOSPlatform("macos")>
Friend Overridable Overloads Sub Lock(ByVal Record As Long)
If m_lRecordLen = -1 Then
m_file.Lock((Record - 1), 1)
Expand All @@ -612,6 +616,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End If
End Sub

<UnsupportedOSPlatform("macos")>
Friend Overridable Overloads Sub Unlock(ByVal Record As Long)
If m_lRecordLen = -1 Then
m_file.Unlock((Record - 1), 1)
Expand All @@ -620,6 +625,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End If
End Sub

<UnsupportedOSPlatform("macos")>
Friend Overridable Overloads Sub Lock(ByVal RecordStart As Long, ByVal RecordEnd As Long)
If m_lRecordLen = -1 Then
m_file.Lock((RecordStart - 1), (RecordEnd - RecordStart) + 1)
Expand All @@ -628,6 +634,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End If
End Sub

<UnsupportedOSPlatform("macos")>
Friend Overridable Overloads Sub Unlock(ByVal RecordStart As Long, ByVal RecordEnd As Long)
If m_lRecordLen = -1 Then
m_file.Unlock((RecordStart - 1), (RecordEnd - RecordStart) + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Imports System
Imports System.IO
Imports System.Runtime.Versioning

Imports Microsoft.VisualBasic.CompilerServices.ExceptionUtils
Imports Microsoft.VisualBasic.CompilerServices.Utils
Expand Down Expand Up @@ -120,6 +121,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
CloseTheFile()
End Sub

<UnsupportedOSPlatform("macos")>
Friend Overloads Overrides Sub Lock(ByVal lStart As Long, ByVal lEnd As Long)
If lStart > lEnd Then
Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start"))
Expand All @@ -134,6 +136,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
m_file.Lock(lStartByte, lLength)
End Sub

<UnsupportedOSPlatform("macos")>
Friend Overloads Overrides Sub Unlock(ByVal lStart As Long, ByVal lEnd As Long)
If lStart > lEnd Then
Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ Namespace Microsoft.VisualBasic
End Try
End Sub

<UnsupportedOSPlatform("macos")>
Public Function InputString(ByVal FileNumber As Integer, ByVal CharCount As Integer) As String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this API's area owner would prefer to reduce the aggressiveness of marking the whole platform as unsupported, and instead only calling oFile.Lock() and oFile.Unlock() when the platform is not MacOS.

Copy link
Member

@buyaa-n buyaa-n Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, mono team has a story for adding more attributes for mac/android/ios, they might want to see this changes cc @marek-safar

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That story is for SDKs but we are going to audit libraries as well during #47910 work

Try
Dim oFile As VB6File
Expand Down Expand Up @@ -1037,31 +1038,37 @@ Namespace Microsoft.VisualBasic
Return oFile.LineInput()
End Function

<UnsupportedOSPlatform("macos")>
Public Sub Lock(ByVal FileNumber As Integer)
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
GetStream(assem, FileNumber).Lock()
End Sub

<UnsupportedOSPlatform("macos")>
Public Sub Lock(ByVal FileNumber As Integer, ByVal Record As Long)
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
GetStream(assem, FileNumber).Lock(Record)
End Sub

<UnsupportedOSPlatform("macos")>
Public Sub Lock(ByVal FileNumber As Integer, ByVal FromRecord As Long, ByVal ToRecord As Long)
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
GetStream(assem, FileNumber).Lock(FromRecord, ToRecord)
End Sub

<UnsupportedOSPlatform("macos")>
Public Sub Unlock(ByVal FileNumber As Integer)
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
GetStream(assem, FileNumber).Unlock()
End Sub

<UnsupportedOSPlatform("macos")>
Public Sub Unlock(ByVal FileNumber As Integer, ByVal Record As Long)
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
GetStream(assem, FileNumber).Unlock(Record)
End Sub

<UnsupportedOSPlatform("macos")>
Public Sub Unlock(ByVal FileNumber As Integer, ByVal FromRecord As Long, ByVal ToRecord As Long)
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
GetStream(assem, FileNumber).Unlock(FromRecord, ToRecord)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public override void EndWrite(System.IAsyncResult asyncResult) { }
public override void Flush() { }
public override void Flush(bool flushToDisk) { }
public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public override void Lock(long position, long length) { }
public override int Read(byte[] buffer, int offset, int count) { throw null; }
public override int Read(System.Span<byte> buffer) { throw null; }
Expand All @@ -127,6 +128,7 @@ public override void Lock(long position, long length) { }
public override int ReadByte() { throw null; }
public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; }
public override void SetLength(long value) { }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public override void Unlock(long position, long length) { }
public override void Write(byte[] buffer, int offset, int count) { }
public override void Write(System.ReadOnlySpan<byte> buffer) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Win32.SafeHandles;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.Versioning;

namespace System.IO.IsolatedStorage
{
Expand Down Expand Up @@ -327,11 +328,13 @@ public override IntPtr Handle
get { return _fs.Handle; }
}

[UnsupportedOSPlatform("macos")]
public override void Unlock(long position, long length)
{
_fs.Unlock(position, length);
}

[UnsupportedOSPlatform("macos")]
public override void Lock(long position, long length)
{
_fs.Lock(position, length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Win32.SafeHandles;
Expand Down Expand Up @@ -256,6 +257,7 @@ public FileStream(string path, FileMode mode, FileAccess access, FileShare share
[Obsolete("This property has been deprecated. Please use FileStream's SafeFileHandle property instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public virtual IntPtr Handle => SafeFileHandle.DangerousGetHandle();

[UnsupportedOSPlatform("macos")]
public virtual void Lock(long position, long length)
{
if (position < 0 || length < 0)
Expand All @@ -271,6 +273,7 @@ public virtual void Lock(long position, long length)
LockInternal(position, length);
}

[UnsupportedOSPlatform("macos")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably the ref needs to be updated, too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what about overrides? e.g. IsolatedStorageFileStream.Lock/Unlock?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephentoub excellent points (as usual). I've added missing attributes (ref & overrides) PTAL

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, I've missed the VB files... let me fix the build and get back to you

public virtual void Unlock(long position, long length)
{
if (position < 0 || length < 0)
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7139,6 +7139,7 @@ public override void EndWrite(System.IAsyncResult asyncResult) { }
public override void Flush() { }
public virtual void Flush(bool flushToDisk) { }
public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public virtual void Lock(long position, long length) { }
public override int Read(byte[] buffer, int offset, int count) { throw null; }
public override int Read(System.Span<byte> buffer) { throw null; }
Expand All @@ -7147,6 +7148,7 @@ public virtual void Lock(long position, long length) { }
public override int ReadByte() { throw null; }
public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; }
public override void SetLength(long value) { }
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
public virtual void Unlock(long position, long length) { }
public override void Write(byte[] buffer, int offset, int count) { }
public override void Write(System.ReadOnlySpan<byte> buffer) { }
Expand Down