tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
PosixFilesystemLinkFactory.cs
Go to the documentation of this file.
1using System;
2using System.IO.Abstractions;
3using System.Threading;
4using System.Threading.Tasks;
5
6using Mono.Unix;
7
9{
14 {
17
21 readonly IFileSystem fileSystem;
22
28 {
29 this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
30 }
31
33 public Task CreateHardLink(string targetPath, string linkPath, CancellationToken cancellationToken) => Task.Factory.StartNew(
34 () =>
35 {
36 ArgumentNullException.ThrowIfNull(targetPath);
37 ArgumentNullException.ThrowIfNull(linkPath);
38
39 cancellationToken.ThrowIfCancellationRequested();
40 var fsInfo = new UnixFileInfo(targetPath);
41 cancellationToken.ThrowIfCancellationRequested();
42 fsInfo.CreateLink(linkPath);
43 },
44 cancellationToken,
46 TaskScheduler.Current);
47
49 public Task CreateSymbolicLink(string targetPath, string linkPath, CancellationToken cancellationToken) => Task.Factory.StartNew(
50 () =>
51 {
52 ArgumentNullException.ThrowIfNull(targetPath);
53 ArgumentNullException.ThrowIfNull(linkPath);
54
55 UnixFileSystemInfo fsInfo;
56 var isFile = fileSystem.File.Exists(targetPath);
57 cancellationToken.ThrowIfCancellationRequested();
58 if (isFile)
59 fsInfo = new UnixFileInfo(targetPath);
60 else
61 fsInfo = new UnixDirectoryInfo(targetPath);
62 cancellationToken.ThrowIfCancellationRequested();
63 fsInfo.CreateSymbolicLink(linkPath);
64 },
65 cancellationToken,
67 TaskScheduler.Current);
68 }
69}
IIOManager that resolves paths to Environment.CurrentDirectory.
const TaskCreationOptions BlockingTaskCreationOptions
The TaskCreationOptions used to spawn Tasks for potentially long running, blocking operations.