Skip to content

Commit 2aa5062

Browse files
authored
Annotate FileStream.Lock/Unlock as unsupported on iOS/tvOS (#52433)
Part of #47910. FileStream.Lock/Unlock methods throw PNSE with Locking/unlocking file regions is not supported on this platform. Use FileShare on the entire file instead.
1 parent e0dffa1 commit 2aa5062

File tree

7 files changed

+54
-0
lines changed

7 files changed

+54
-0
lines changed

src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,17 @@ public static void Input(int FileNumber, ref string Value) { }
408408
public static void Kill(string PathName) { }
409409
public static string LineInput(int FileNumber) { throw null; }
410410
public static long Loc(int FileNumber) { throw null; }
411+
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
411412
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
413+
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
412414
public static void Lock(int FileNumber) { }
415+
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
413416
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
417+
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
414418
public static void Lock(int FileNumber, long Record) { }
419+
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
415420
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
421+
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
416422
public static void Lock(int FileNumber, long FromRecord, long ToRecord) { }
417423
public static long LOF(int FileNumber) { throw null; }
418424
public static void MkDir(string Path) { }
@@ -428,11 +434,17 @@ public static void SetAttr(string PathName, Microsoft.VisualBasic.FileAttribute
428434
public static Microsoft.VisualBasic.SpcInfo SPC(short Count) { throw null; }
429435
public static Microsoft.VisualBasic.TabInfo TAB() { throw null; }
430436
public static Microsoft.VisualBasic.TabInfo TAB(short Column) { throw null; }
437+
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
431438
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
439+
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
432440
public static void Unlock(int FileNumber) { }
441+
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
433442
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
443+
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
434444
public static void Unlock(int FileNumber, long Record) { }
445+
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
435446
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
447+
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
436448
public static void Unlock(int FileNumber, long FromRecord, long ToRecord) { }
437449
public static void Write(int FileNumber, params object[] Output) { }
438450
public static void WriteLine(int FileNumber, params object[] Output) { }

src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6BinaryFile.vb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ Namespace Microsoft.VisualBasic.CompilerServices
2626
End Sub
2727

2828
' the implementation of Lock in base class VB6RandomFile does not handle m_lRecordLen=-1
29+
<UnsupportedOSPlatform("ios")>
2930
<UnsupportedOSPlatform("macos")>
31+
<UnsupportedOSPlatform("tvos")>
3032
Friend Overloads Overrides Sub Lock(ByVal lStart As Long, ByVal lEnd As Long)
3133
If lStart > lEnd Then
3234
Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start"))
@@ -50,7 +52,9 @@ Namespace Microsoft.VisualBasic.CompilerServices
5052
End Sub
5153

5254
' see Lock description
55+
<UnsupportedOSPlatform("ios")>
5356
<UnsupportedOSPlatform("macos")>
57+
<UnsupportedOSPlatform("tvos")>
5458
Friend Overloads Overrides Sub Unlock(ByVal lStart As Long, ByVal lEnd As Long)
5559
If lStart > lEnd Then
5660
Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start"))

src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6File.vb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,18 +603,24 @@ Namespace Microsoft.VisualBasic.CompilerServices
603603
Return m_position
604604
End Function
605605

606+
<UnsupportedOSPlatform("ios")>
606607
<UnsupportedOSPlatform("macos")>
608+
<UnsupportedOSPlatform("tvos")>
607609
Friend Overridable Overloads Sub Lock()
608610
'Lock the whole file, not just the current size of file, since file could change.
609611
m_file.Lock(0, Int32.MaxValue)
610612
End Sub
611613

614+
<UnsupportedOSPlatform("ios")>
612615
<UnsupportedOSPlatform("macos")>
616+
<UnsupportedOSPlatform("tvos")>
613617
Friend Overridable Overloads Sub Unlock()
614618
m_file.Unlock(0, Int32.MaxValue)
615619
End Sub
616620

621+
<UnsupportedOSPlatform("ios")>
617622
<UnsupportedOSPlatform("macos")>
623+
<UnsupportedOSPlatform("tvos")>
618624
Friend Overridable Overloads Sub Lock(ByVal Record As Long)
619625
If m_lRecordLen = -1 Then
620626
m_file.Lock((Record - 1), 1)
@@ -623,7 +629,9 @@ Namespace Microsoft.VisualBasic.CompilerServices
623629
End If
624630
End Sub
625631

632+
<UnsupportedOSPlatform("ios")>
626633
<UnsupportedOSPlatform("macos")>
634+
<UnsupportedOSPlatform("tvos")>
627635
Friend Overridable Overloads Sub Unlock(ByVal Record As Long)
628636
If m_lRecordLen = -1 Then
629637
m_file.Unlock((Record - 1), 1)
@@ -632,7 +640,9 @@ Namespace Microsoft.VisualBasic.CompilerServices
632640
End If
633641
End Sub
634642

643+
<UnsupportedOSPlatform("ios")>
635644
<UnsupportedOSPlatform("macos")>
645+
<UnsupportedOSPlatform("tvos")>
636646
Friend Overridable Overloads Sub Lock(ByVal RecordStart As Long, ByVal RecordEnd As Long)
637647
If m_lRecordLen = -1 Then
638648
m_file.Lock((RecordStart - 1), (RecordEnd - RecordStart) + 1)
@@ -641,7 +651,9 @@ Namespace Microsoft.VisualBasic.CompilerServices
641651
End If
642652
End Sub
643653

654+
<UnsupportedOSPlatform("ios")>
644655
<UnsupportedOSPlatform("macos")>
656+
<UnsupportedOSPlatform("tvos")>
645657
Friend Overridable Overloads Sub Unlock(ByVal RecordStart As Long, ByVal RecordEnd As Long)
646658
If m_lRecordLen = -1 Then
647659
m_file.Unlock((RecordStart - 1), (RecordEnd - RecordStart) + 1)

src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6RandomFile.vb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ Namespace Microsoft.VisualBasic.CompilerServices
122122
CloseTheFile()
123123
End Sub
124124

125+
<UnsupportedOSPlatform("ios")>
125126
<UnsupportedOSPlatform("macos")>
127+
<UnsupportedOSPlatform("tvos")>
126128
Friend Overloads Overrides Sub Lock(ByVal lStart As Long, ByVal lEnd As Long)
127129
If lStart > lEnd Then
128130
Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start"))
@@ -137,7 +139,9 @@ Namespace Microsoft.VisualBasic.CompilerServices
137139
m_file.Lock(lStartByte, lLength)
138140
End Sub
139141

142+
<UnsupportedOSPlatform("ios")>
140143
<UnsupportedOSPlatform("macos")>
144+
<UnsupportedOSPlatform("tvos")>
141145
Friend Overloads Overrides Sub Unlock(ByVal lStart As Long, ByVal lEnd As Long)
142146
If lStart > lEnd Then
143147
Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start"))

src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileSystem.vb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,9 @@ Namespace Microsoft.VisualBasic
10091009
End Try
10101010
End Sub
10111011

1012+
<UnsupportedOSPlatform("ios")>
10121013
<UnsupportedOSPlatform("macos")>
1014+
<UnsupportedOSPlatform("tvos")>
10131015
Public Function InputString(ByVal FileNumber As Integer, ByVal CharCount As Integer) As String
10141016
Try
10151017
Dim oFile As VB6File
@@ -1047,37 +1049,49 @@ Namespace Microsoft.VisualBasic
10471049
Return oFile.LineInput()
10481050
End Function
10491051

1052+
<UnsupportedOSPlatform("ios")>
10501053
<UnsupportedOSPlatform("macos")>
1054+
<UnsupportedOSPlatform("tvos")>
10511055
Public Sub Lock(ByVal FileNumber As Integer)
10521056
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
10531057
GetStream(assem, FileNumber).Lock()
10541058
End Sub
10551059

1060+
<UnsupportedOSPlatform("ios")>
10561061
<UnsupportedOSPlatform("macos")>
1062+
<UnsupportedOSPlatform("tvos")>
10571063
Public Sub Lock(ByVal FileNumber As Integer, ByVal Record As Long)
10581064
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
10591065
GetStream(assem, FileNumber).Lock(Record)
10601066
End Sub
10611067

1068+
<UnsupportedOSPlatform("ios")>
10621069
<UnsupportedOSPlatform("macos")>
1070+
<UnsupportedOSPlatform("tvos")>
10631071
Public Sub Lock(ByVal FileNumber As Integer, ByVal FromRecord As Long, ByVal ToRecord As Long)
10641072
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
10651073
GetStream(assem, FileNumber).Lock(FromRecord, ToRecord)
10661074
End Sub
10671075

1076+
<UnsupportedOSPlatform("ios")>
10681077
<UnsupportedOSPlatform("macos")>
1078+
<UnsupportedOSPlatform("tvos")>
10691079
Public Sub Unlock(ByVal FileNumber As Integer)
10701080
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
10711081
GetStream(assem, FileNumber).Unlock()
10721082
End Sub
10731083

1084+
<UnsupportedOSPlatform("ios")>
10741085
<UnsupportedOSPlatform("macos")>
1086+
<UnsupportedOSPlatform("tvos")>
10751087
Public Sub Unlock(ByVal FileNumber As Integer, ByVal Record As Long)
10761088
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
10771089
GetStream(assem, FileNumber).Unlock(Record)
10781090
End Sub
10791091

1092+
<UnsupportedOSPlatform("ios")>
10801093
<UnsupportedOSPlatform("macos")>
1094+
<UnsupportedOSPlatform("tvos")>
10811095
Public Sub Unlock(ByVal FileNumber As Integer, ByVal FromRecord As Long, ByVal ToRecord As Long)
10821096
Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly()
10831097
GetStream(assem, FileNumber).Unlock(FromRecord, ToRecord)

src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ public FileStream(string path, FileMode mode, FileAccess access, FileShare share
197197
[Obsolete("This property has been deprecated. Please use FileStream's SafeFileHandle property instead. https://go.microsoft.com/fwlink/?linkid=14202")]
198198
public virtual IntPtr Handle => _strategy.Handle;
199199

200+
[UnsupportedOSPlatform("ios")]
200201
[UnsupportedOSPlatform("macos")]
202+
[UnsupportedOSPlatform("tvos")]
201203
public virtual void Lock(long position, long length)
202204
{
203205
if (position < 0 || length < 0)
@@ -212,7 +214,9 @@ public virtual void Lock(long position, long length)
212214
_strategy.Lock(position, length);
213215
}
214216

217+
[UnsupportedOSPlatform("ios")]
215218
[UnsupportedOSPlatform("macos")]
219+
[UnsupportedOSPlatform("tvos")]
216220
public virtual void Unlock(long position, long length)
217221
{
218222
if (position < 0 || length < 0)

src/libraries/System.Runtime/ref/System.Runtime.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7329,7 +7329,9 @@ public override void EndWrite(System.IAsyncResult asyncResult) { }
73297329
public override void Flush() { }
73307330
public virtual void Flush(bool flushToDisk) { }
73317331
public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; }
7332+
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
73327333
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
7334+
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
73337335
public virtual void Lock(long position, long length) { }
73347336
public override int Read(byte[] buffer, int offset, int count) { throw null; }
73357337
public override int Read(System.Span<byte> buffer) { throw null; }
@@ -7338,7 +7340,9 @@ public virtual void Lock(long position, long length) { }
73387340
public override int ReadByte() { throw null; }
73397341
public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; }
73407342
public override void SetLength(long value) { }
7343+
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
73417344
[System.Runtime.Versioning.UnsupportedOSPlatform("macos")]
7345+
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
73427346
public virtual void Unlock(long position, long length) { }
73437347
public override void Write(byte[] buffer, int offset, int count) { }
73447348
public override void Write(System.ReadOnlySpan<byte> buffer) { }

0 commit comments

Comments
 (0)