tgstation-server  4.4.0
The /tg/station 13 server suite
PosixPostWriteHandler.cs
Go to the documentation of this file.
1 using Microsoft.Extensions.Logging;
2 using Mono.Unix;
3 using Mono.Unix.Native;
4 using System;
5 
6 namespace Tgstation.Server.Host.IO
7 {
12  {
16  readonly ILogger<PosixPostWriteHandler> logger;
17 
22  public PosixPostWriteHandler(ILogger<PosixPostWriteHandler> logger)
23  {
24  this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
25  }
26 
28  public void HandleWrite(string filePath)
29  {
30  if (filePath == null)
31  throw new ArgumentNullException(nameof(filePath));
32 
33  // set executable bit every time, don't want people calling me when their uploaded "sl" binary doesn't work
34  if (Syscall.stat(filePath, out var stat) != 0)
35  throw new UnixIOException(Stdlib.GetLastError());
36 
37  if (stat.st_mode.HasFlag(FilePermissions.S_IXUSR))
38  {
39  logger.LogTrace("{0} already +x", filePath);
40  return;
41  }
42 
43  logger.LogTrace("Setting +x on {0}", filePath);
44  if (Syscall.chmod(filePath, stat.st_mode | FilePermissions.S_IXUSR) != 0)
45  throw new UnixIOException(Stdlib.GetLastError());
46  }
47  }
48 }
void HandleWrite(string filePath)
For handling system specific necessities after a write
IPostWriteHandler for POSIX systems
Handles changing file modes/permissions after writing
PosixPostWriteHandler(ILogger< PosixPostWriteHandler > logger)
Initializes a new instance of the PosixPostWriteHandler .
readonly ILogger< PosixPostWriteHandler > logger
The ILogger<TCategoryName> for the PosixPostWriteHandler