windows: changes to install/upgrade/uninstallation process (#9025)

This commit is contained in:
dave caruso
2024-02-27 03:11:43 -08:00
committed by GitHub
parent fd6fd78f0f
commit 4e2d00d052
13 changed files with 430 additions and 130 deletions

View File

@@ -610,15 +610,14 @@ pub const RunCommand = struct {
const file_slice = target_path_buffer[0 .. prefix.len + len + file_name.len - "\x00".len];
const dir_slice = target_path_buffer[0 .. prefix.len + len + dir_name.len];
const ImagePathName = std.os.windows.peb().ProcessParameters.ImagePathName;
std.debug.assert(ImagePathName.Buffer[ImagePathName.Length / 2] == 0); // trust windows
const image_path = bun.windows.exePathW();
if (Environment.isDebug) {
// the link becomes out of date on rebuild
std.os.unlinkW(file_slice) catch {};
}
if (bun.windows.CreateHardLinkW(@ptrCast(file_slice.ptr), @ptrCast(ImagePathName.Buffer), null) == 0) {
if (bun.windows.CreateHardLinkW(@ptrCast(file_slice.ptr), image_path.ptr, null) == 0) {
switch (std.os.windows.kernel32.GetLastError()) {
.ALREADY_EXISTS => {},
else => {
@@ -629,7 +628,7 @@ pub const RunCommand = struct {
target_path_buffer[dir_slice.len] = '\\';
}
if (bun.windows.CreateHardLinkW(@ptrCast(file_slice.ptr), @ptrCast(ImagePathName.Buffer), null) == 0) {
if (bun.windows.CreateHardLinkW(@ptrCast(file_slice.ptr), image_path.ptr, null) == 0) {
return;
}
},