| ... | ... | @@ -1520,6 +1520,14 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { |
| 1520 | 1520 | } |
| 1521 | 1521 | } |
| 1522 | 1522 | |
| 1523 | /// Use with `symlink` to specify whether the symlink will point to a file |
| 1524 | /// or a directory. This value is ignored on all hosts except Windows where |
| 1525 | /// creating symlinks to different resource types, requires different flags. |
| 1526 | /// By default, symlink is assumed to point to a file. |
| 1527 | pub const SymlinkFlags = struct{ |
| 1528 | is_directory: bool = false, |
| 1529 | }; |
| 1530 | |
| 1523 | 1531 | pub const SymLinkError = error{ |
| 1524 | 1532 | /// In WASI, this error may occur when the file descriptor does |
| 1525 | 1533 | /// not hold the required rights to create a new symbolic link relative to it. |
| ... | ... | @@ -1541,39 +1549,34 @@ pub const SymLinkError = error{ |
| 1541 | 1549 | /// Creates a symbolic link named `sym_link_path` which contains the string `target_path`. |
| 1542 | 1550 | /// A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent |
| 1543 | 1551 | /// one; the latter case is known as a dangling link. |
| 1544 | | /// On Windows, it is only legal to create a symbolic link to an existing resource. Furthermore, |
| 1545 | | /// this function will by default try creating a symbolic link to a file. If you would like to |
| 1546 | | /// create a symbolic link to a directory instead, see `symlinkW` for more information how to |
| 1547 | | /// do that. |
| 1548 | 1552 | /// If `sym_link_path` exists, it will not be overwritten. |
| 1549 | 1553 | /// See also `symlinkC` and `symlinkW`. |
| 1550 | | pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!void { |
| 1554 | pub fn symlink(target_path: []const u8, sym_link_path: []const u8, flags: SymlinkFlags) SymLinkError!void { |
| 1551 | 1555 | if (builtin.os.tag == .wasi) { |
| 1552 | 1556 | @compileError("symlink is not supported in WASI; use symlinkat instead"); |
| 1553 | 1557 | } |
| 1554 | 1558 | if (builtin.os.tag == .windows) { |
| 1555 | 1559 | const target_path_w = try windows.sliceToPrefixedFileW(target_path); |
| 1556 | 1560 | const sym_link_path_w = try windows.sliceToPrefixedFileW(sym_link_path); |
| 1557 | | return symlinkW(target_path_w.span().ptr, sym_link_path_w.span().ptr); |
| 1561 | return symlinkW(target_path_w.span().ptr, sym_link_path_w.span().ptr, flags); |
| 1558 | 1562 | } |
| 1559 | 1563 | const target_path_c = try toPosixPath(target_path); |
| 1560 | 1564 | const sym_link_path_c = try toPosixPath(sym_link_path); |
| 1561 | | return symlinkZ(&target_path_c, &sym_link_path_c); |
| 1565 | return symlinkZ(&target_path_c, &sym_link_path_c, flags); |
| 1562 | 1566 | } |
| 1563 | 1567 | |
| 1564 | 1568 | pub const symlinkC = @compileError("deprecated: renamed to symlinkZ"); |
| 1565 | 1569 | |
| 1566 | 1570 | /// Windows-only. Same as `symlink` except the parameters are null-terminated, WTF16 encoded. |
| 1567 | 1571 | /// Note that this function will by default try creating a symbolic link to a file. If you would |
| 1568 | | /// like to create a symbolic link to a directory, use `std.os.windows.CreateSymbolicLinkW` directly |
| 1569 | | /// specifying as flags `std.os.windows.CreateSymbolicLinkFlags.Directory`. |
| 1570 | | pub fn symlinkW(target_path: [*:0]const u16, sym_link_path: [*:0]const u16) SymLinkError!void { |
| 1571 | | return windows.CreateSymbolicLinkW(sym_link_path, target_path, false); |
| 1572 | /// like to create a symbolic link to a directory, specify this with `SymlinkFlags{ .is_directory = true }`. |
| 1573 | pub fn symlinkW(target_path: [*:0]const u16, sym_link_path: [*:0]const u16, flags: SymlinkFlags) SymLinkError!void { |
| 1574 | return windows.CreateSymbolicLinkW(sym_link_path, target_path, flags.is_directory); |
| 1572 | 1575 | } |
| 1573 | 1576 | |
| 1574 | 1577 | /// This is the same as `symlink` except the parameters are null-terminated pointers. |
| 1575 | 1578 | /// See also `symlink`. |
| 1576 | | pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void { |
| 1579 | pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8, flags: SymlinkFlags) SymLinkError!void { |
| 1577 | 1580 | if (builtin.os.tag == .windows) { |
| 1578 | 1581 | const target_path_w = try windows.cStrToPrefixedFileW(target_path); |
| 1579 | 1582 | const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path); |