tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
PosixPostWriteHandler.cs
Go to the documentation of this file.
1using System;
2
3using Microsoft.Extensions.Logging;
4using Mono.Unix;
5using Mono.Unix.Native;
6
8{
13 {
17 readonly ILogger<PosixPostWriteHandler> logger;
18
23 public PosixPostWriteHandler(ILogger<PosixPostWriteHandler> logger)
24 {
25 this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
26 }
27
29 public bool NeedsPostWrite(string sourceFilePath)
30 {
31 ArgumentNullException.ThrowIfNull(sourceFilePath);
32
33 if (Syscall.stat(sourceFilePath, out var stat) != 0)
34 throw new UnixIOException(Stdlib.GetLastError());
35
36 return stat.st_mode.HasFlag(FilePermissions.S_IXUSR);
37 }
38
40 public void HandleWrite(string filePath)
41 {
42 ArgumentNullException.ThrowIfNull(filePath);
43
44 // set executable bit every time, don't want people calling me when their uploaded "sl" binary doesn't work
45 if (Syscall.stat(filePath, out var stat) != 0)
46 throw new UnixIOException(Stdlib.GetLastError());
47
48 if (stat.st_mode.HasFlag(FilePermissions.S_IXUSR))
49 {
50 logger.LogTrace("{0} already +x", filePath);
51 return;
52 }
53
54 logger.LogTrace("Setting +x on {0}", filePath);
55 if (Syscall.chmod(filePath, stat.st_mode | FilePermissions.S_IXUSR) != 0)
56 throw new UnixIOException(Stdlib.GetLastError());
57 }
58 }
59}
IPostWriteHandler for POSIX systems.
PosixPostWriteHandler(ILogger< PosixPostWriteHandler > logger)
Initializes a new instance of the PosixPostWriteHandler class.
void HandleWrite(string filePath)
For handling system specific necessities after a write.
readonly ILogger< PosixPostWriteHandler > logger
The ILogger<TCategoryName> for the PosixPostWriteHandler.
bool NeedsPostWrite(string sourceFilePath)
Check if a given sourceFilePath will need HandleWrite(string) called on a copy of it....
Handles changing file modes/permissions after writing.