@@ -14,13 +14,6 @@ protected virtual void Copy(string source, string dest)
14
14
File . Copy ( source , dest ) ;
15
15
}
16
16
17
- protected virtual void CopyReadOnlyFile ( string source , string dest )
18
- {
19
- byte [ ] bits = File . ReadAllBytes ( source ) ;
20
- File . WriteAllBytes ( dest , bits ) ;
21
- File . SetAttributes ( dest , FileAttributes . ReadOnly ) ;
22
- }
23
-
24
17
#region UniversalTests
25
18
26
19
[ Fact ]
@@ -115,7 +108,6 @@ public static IEnumerable<object[]> CopyFileWithData_MemberData()
115
108
116
109
[ Theory ]
117
110
[ MemberData ( nameof ( CopyFileWithData_MemberData ) ) ]
118
- [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/40867" , TestPlatforms . Browser ) ]
119
111
public void CopyFileWithData ( char [ ] data , bool readOnly )
120
112
{
121
113
string testFileSource = GetTestFilePath ( ) ;
@@ -127,21 +119,8 @@ public void CopyFileWithData(char[] data, bool readOnly)
127
119
stream . Write ( data , 0 , data . Length ) ;
128
120
}
129
121
130
- DateTime lastWriteTime ;
131
- if ( PlatformDetection . IsBrowser )
132
- {
133
- // For browser, there is technically only 1 time. It's the max
134
- // of LastWrite and LastAccess. Setting to a date/time in the future
135
- // is a way of making this test work similarly.
136
- //
137
- // https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.utime
138
- //
139
- lastWriteTime = DateTime . UtcNow . Add ( TimeSpan . FromHours ( 1 ) ) ;
140
- }
141
- else
142
- {
143
- lastWriteTime = DateTime . UtcNow . Subtract ( TimeSpan . FromHours ( 1 ) ) ;
144
- }
122
+ // Set the last write time of the source file to something a while ago
123
+ DateTime lastWriteTime = DateTime . UtcNow . Subtract ( TimeSpan . FromHours ( 1 ) ) ;
145
124
File . SetLastWriteTime ( testFileSource , lastWriteTime ) ;
146
125
147
126
if ( readOnly )
@@ -150,16 +129,7 @@ public void CopyFileWithData(char[] data, bool readOnly)
150
129
}
151
130
152
131
// Copy over the data
153
- //
154
- // For browser, work around limitation of File.Copy, which
155
- // fails when trying to open the dest file
156
- if ( PlatformDetection . IsBrowser && readOnly )
157
- {
158
- CopyReadOnlyFile ( testFileSource , testFileDest ) ;
159
- File . SetLastWriteTime ( testFileDest , lastWriteTime ) ;
160
- }
161
- else
162
- Copy ( testFileSource , testFileDest ) ;
132
+ Copy ( testFileSource , testFileDest ) ;
163
133
164
134
// Ensure copy transferred written data
165
135
using ( StreamReader stream = new StreamReader ( File . OpenRead ( testFileDest ) ) )
@@ -170,7 +140,15 @@ public void CopyFileWithData(char[] data, bool readOnly)
170
140
}
171
141
172
142
// Ensure last write/access time on the new file is appropriate
173
- Assert . InRange ( File . GetLastWriteTimeUtc ( testFileDest ) , lastWriteTime . AddSeconds ( - 1 ) , lastWriteTime . AddSeconds ( 1 ) ) ;
143
+ //
144
+ // For browser, there is technically only 1 time. It's the max
145
+ // of LastWrite and LastAccess. On browser, File.SetLastWriteTime
146
+ // overwrites LastWrite and LastAccess, and File.Copy
147
+ // overwrites LastWrite , so this check doesn't apply.
148
+ if ( PlatformDetection . IsNotBrowser )
149
+ {
150
+ Assert . InRange ( File . GetLastWriteTimeUtc ( testFileDest ) , lastWriteTime . AddSeconds ( - 1 ) , lastWriteTime . AddSeconds ( 1 ) ) ;
151
+ }
174
152
175
153
Assert . Equal ( readOnly , ( File . GetAttributes ( testFileDest ) & FileAttributes . ReadOnly ) != 0 ) ;
176
154
if ( readOnly )
0 commit comments