8000 GlobalSettings.NativeLibraryPath: throw once used · thatfrankdev/libgit2sharp@e56c097 · GitHub
[go: up one dir, main page]

Skip to content

Commit e56c097

Browse files
Edward Thomsonnulltoken
Edward Thomson
authored andcommitted
GlobalSettings.NativeLibraryPath: throw once used
1 parent f83c090 commit e56c097

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ static NativeMethods()
6666
{
6767
if (Platform.OperatingSystem == OperatingSystemType.Windows)
6868
{
69-
string path = Path.Combine(GlobalSettings.NativeLibraryPath, Platform.ProcessorArchitecture);
69+
string nativeLibraryPath = GlobalSettings.GetAndLockNativeLibraryPath();
70+
71+
string path = Path.Combine(nativeLibraryPath, Platform.ProcessorArchitecture);
7072

7173
const string pathEnvVariable = "PATH";
7274
Environment.SetEnvironmentVariable(pathEnvVariable,

LibGit2Sharp/GlobalSettings.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static class GlobalSettings
1515
private static LogConfiguration logConfiguration = LogConfiguration.None;
1616

1717
private static string nativeLibraryPath;
18+
private static bool nativeLibraryPathLocked;
1819

1920
static GlobalSettings()
2021
{
@@ -154,8 +155,19 @@ public static string NativeLibraryPath
154155
throw new LibGit2SharpException("Setting the native hint path is only supported on Windows platforms");
155156
}
156157

158+
if (nativeLibraryPathLocked)
159+
{
160+
throw new LibGit2SharpException("You cannot set the native library path after it has been loaded");
161+
}
162+
157163
nativeLibraryPath = value;
158164
}
159165
}
166+
167+
internal static string GetAndLockNativeLibraryPath()
168+
{
169+
nativeLibraryPathLocked = true;
170+
return nativeLibraryPath;
171+
}
160172
}
161173
}

0 commit comments

Comments
 (0)
0