Skip to content

Commit 16ca68c

Browse files
committed
Compile-gate CopyMode to net7+
Move `CopyMode` behind `#if NET7_0_OR_GREATER` and gate its call site the same way. This avoids compiling an effectively empty method on older targets and documents that Unix mode preservation is only available once `SetUnixFileMode` exists.
1 parent 35da2c4 commit 16ca68c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/DiffEngine/Inline/InlineApplier.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,21 @@ static string ResolveLink(string path)
234234
#endif
235235
}
236236

237+
#if NET7_0_OR_GREATER
237238
/// <summary>
238239
/// The destination's Unix permissions onto the temporary, because the swap is a rename and the
239240
/// file that survives it is the temporary - created with this process's umask. A source file
240241
/// that was executable, or group writable, or anything else out of the ordinary, came back as
241242
/// whatever the umask happened to say. Windows keeps the destination's ACLs across a Replace,
242243
/// so there is nothing to carry there.
244+
/// <para>
245+
/// Only exists from net7, which is where SetUnixFileMode arrives. Below that there is nothing
246+
/// to carry on any OS, so the call site is compiled out with it rather than calling an empty
247+
/// method.
248+
/// </para>
243249
/// </summary>
244250
static void CopyMode(string destination, string temporary)
245251
{
246-
#if NET7_0_OR_GREATER
247252
if (OperatingSystem.IsWindows())
248253
{
249254
return;
@@ -259,8 +264,8 @@ static void CopyMode(string destination, string temporary)
259264
// Best effort. The content is the point, and a mode that could not be read or set is
260265
// not worth failing a patch that otherwise applied.
261266
}
262-
#endif
263267
}
268+
#endif
264269

265270
static void WriteThroughTemporary(string fullPath, byte[] output)
266271
{
@@ -271,7 +276,9 @@ static void WriteThroughTemporary(string fullPath, byte[] output)
271276
try
272277
{
273278
File.WriteAllBytes(temporary, output);
279+
#if NET7_0_OR_GREATER
274280
CopyMode(fullPath, temporary);
281+
#endif
275282
File.Replace(temporary, fullPath, null);
276283
}
277284
finally

0 commit comments

Comments
 (0)