symlinks
This commit is contained in:
parent
ea54bed80d
commit
63a3c4eef6
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DTLib.Filesystem
|
||||
{
|
||||
@ -134,5 +135,11 @@ namespace DTLib.Filesystem
|
||||
System.Security.AccessControl.AccessControlType.Allow));
|
||||
dirInfo.SetAccessControl(dirSecurity);
|
||||
}
|
||||
|
||||
public static void CreateSymlink(string symlinkName, string sourceName)
|
||||
{
|
||||
if (!Symlink.CreateSymbolicLink(symlinkName, sourceName, Symlink.SymlinkTarget.Directory))
|
||||
throw new InvalidOperationException($"some error occured while creating symlink\nCreateSymlink({symlinkName}, {sourceName})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,5 +74,11 @@ namespace DTLib.Filesystem
|
||||
File.Create(file);
|
||||
return System.IO.File.Open(file, System.IO.FileMode.Append);
|
||||
}
|
||||
|
||||
public static void CreateSymlink(string symlinkName, string sourceName)
|
||||
{
|
||||
if (!Symlink.CreateSymbolicLink(symlinkName, sourceName, Symlink.SymlinkTarget.File))
|
||||
throw new InvalidOperationException($"some error occured while creating symlink\nCreateSymlink({symlinkName}, {sourceName})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,13 +8,13 @@ namespace DTLib.Filesystem
|
||||
public static class OldFilework
|
||||
{
|
||||
// записывает текст в файл и закрывает файл
|
||||
public static void LogToFile(string logfile, string msg)
|
||||
/*public static void LogToFile(string logfile, string msg)
|
||||
{
|
||||
lock (new object())
|
||||
{
|
||||
File.AppendAllText(logfile, msg);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// чтение параметров из конфига
|
||||
public static string ReadFromConfig(string configfile, string key)
|
||||
|
||||
21
Filesystem/Symlink.cs
Normal file
21
Filesystem/Symlink.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DTLib.Filesystem
|
||||
{
|
||||
internal class Symlink
|
||||
{
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
static internal extern bool CreateSymbolicLink(string symlinkName, string sourceName, SymlinkTarget type);
|
||||
|
||||
internal enum SymlinkTarget
|
||||
{
|
||||
File,
|
||||
Directory
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user