authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-07-19 12:21:46+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-07-22 08:51:22+02:00
log3c8ceb674eb00ac0a70d6a0742234ce520eccf06
treeb98b93c9e3bb2aea91d53a1318207fc4167412a2
parentfc7d87fef19964273eb65e8cee05eaffa7a9e72f

Fix Windows build


3 files changed, 14 insertions(+), 6 deletions(-)

lib/std/fs.zig+4-4
...@@ -1720,12 +1720,12 @@ pub const SymlinkFlags = struct {...@@ -1720,12 +1720,12 @@ pub const SymlinkFlags = struct {
1720/// See also `symLinkAbsoluteZ` and `symLinkAbsoluteW`.1720/// See also `symLinkAbsoluteZ` and `symLinkAbsoluteW`.
1721pub fn symLinkAbsolute(target_path: []const u8, sym_link_path: []const u8, flags: SymlinkFlags) !void {1721pub fn symLinkAbsolute(target_path: []const u8, sym_link_path: []const u8, flags: SymlinkFlags) !void {
1722 if (builtin.os.tag == .wasi) {1722 if (builtin.os.tag == .wasi) {
1723 @compileError("symLink is not supported in WASI");1723 @compileError("symLinkAbsolute is not supported in WASI");
1724 }1724 }
1725 assert(path.isAbsolute(target_path));1725 assert(path.isAbsolute(target_path));
1726 assert(path.isAbsolute(sym_link_path));1726 assert(path.isAbsolute(sym_link_path));
1727 if (builtin.os.tag == .windows) {1727 if (builtin.os.tag == .windows) {
1728 return os.windows.CreateSymbolicLink(target_path, sym_link_path, flags.is_directory);1728 return os.windows.CreateSymbolicLink(sym_link_path, target_path, flags.is_directory);
1729 }1729 }
1730 return os.symlink(target_path, sym_link_path);1730 return os.symlink(target_path, sym_link_path);
1731}1731}
...@@ -1737,7 +1737,7 @@ pub fn symLinkAbsolute(target_path: []const u8, sym_link_path: []const u8, flags...@@ -1737,7 +1737,7 @@ pub fn symLinkAbsolute(target_path: []const u8, sym_link_path: []const u8, flags
1737pub fn symLinkAbsoluteW(target_path_w: [*:0]const u16, sym_link_path_w: [*:0]const u16, flags: SymlinkFlags) !void {1737pub fn symLinkAbsoluteW(target_path_w: [*:0]const u16, sym_link_path_w: [*:0]const u16, flags: SymlinkFlags) !void {
1738 assert(path.isAbsoluteWindowsW(target_path_w));1738 assert(path.isAbsoluteWindowsW(target_path_w));
1739 assert(path.isAbsoluteWindowsW(sym_link_path_w));1739 assert(path.isAbsoluteWindowsW(sym_link_path_w));
1740 return os.windows.CreateSymbolicLinkW(target_path_w, sym_link_path_w, flags.is_directory);1740 return os.windows.CreateSymbolicLinkW(sym_link_path_w, target_path_w, flags.is_directory);
1741}1741}
17421742
1743/// Same as `symLinkAbsolute` except the parameters are null-terminated pointers.1743/// Same as `symLinkAbsolute` except the parameters are null-terminated pointers.
...@@ -1748,7 +1748,7 @@ pub fn symLinkAbsoluteZ(target_path_c: [*:0]const u8, sym_link_path_c: [*:0]cons...@@ -1748,7 +1748,7 @@ pub fn symLinkAbsoluteZ(target_path_c: [*:0]const u8, sym_link_path_c: [*:0]cons
1748 if (builtin.os.tag == .windows) {1748 if (builtin.os.tag == .windows) {
1749 const target_path_w = try os.windows.cStrToWin32PrefixedFileW(target_path_c);1749 const target_path_w = try os.windows.cStrToWin32PrefixedFileW(target_path_c);
1750 const sym_link_path_w = try os.windows.cStrToWin32PrefixedFileW(sym_link_path_c);1750 const sym_link_path_w = try os.windows.cStrToWin32PrefixedFileW(sym_link_path_c);
1751 return os.windows.CreateSymbolicLinkW(target_path_w.span().ptr, sym_link_path_w.span().ptr, flags.is_directory);1751 return os.windows.CreateSymbolicLinkW(sym_link_path_w.span().ptr, target_path_w.span().ptr, flags.is_directory);
1752 }1752 }
1753 return os.symlinkZ(target_path_c, sym_link_path_c);1753 return os.symlinkZ(target_path_c, sym_link_path_c);
1754}1754}
lib/std/os/test.zig+1-1
...@@ -27,7 +27,7 @@ test "symlink with relative paths" {...@@ -27,7 +27,7 @@ test "symlink with relative paths" {
27 try cwd.writeFile("file.txt", "nonsense");27 try cwd.writeFile("file.txt", "nonsense");
2828
29 if (builtin.os.tag == .windows) {29 if (builtin.os.tag == .windows) {
30 try os.windows.CreateSymbolicLink("file.txt", "symlinked", false);30 try os.windows.CreateSymbolicLink("symlinked", "file.txt", false);
31 } else {31 } else {
32 try os.symlink("file.txt", "symlinked");32 try os.symlink("file.txt", "symlinked");
33 }33 }
lib/std/os/windows.zig+9-1
...@@ -602,7 +602,15 @@ pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 {...@@ -602,7 +602,15 @@ pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 {
602 return buffer[0..end_index];602 return buffer[0..end_index];
603}603}
604604
605pub const CreateSymbolicLinkError = error{ AccessDenied, PathAlreadyExists, FileNotFound, Unexpected };605pub const CreateSymbolicLinkError = error{
606 AccessDenied,
607 PathAlreadyExists,
608 FileNotFound,
609 NameTooLong,
610 InvalidUtf8,
611 BadPathName,
612 Unexpected
613};
606614
607pub fn CreateSymbolicLink(615pub fn CreateSymbolicLink(
608 sym_link_path: []const u8,616 sym_link_path: []const u8,