158 Commits

Author SHA1 Message Date
Luna
5f7b97e84c add AddressFamilyNotSupported to SendError 2020-12-07 16:40:03 -05:00
LemonBoy
ac443b941d std: Restore file locking test on Windows
Make it even more robust wrt timing problems.

Closes #7010
2020-12-04 12:24:50 -08:00
christian-stephen
abc729a5f9 Add readAllArrayListAligned to Reader which can accept an arbitrary alignment 2020-11-27 17:00:50 -08:00
LemonBoy
f8ddc3d873 std: Fix file locking logic for BSD targets 2020-11-23 18:00:05 +01:00
g-w1
a0226ab05b
std: openDirAbsolute and accessAbsolute (#7082)
* add more abosolutes

* added wrong files

* adding 2 tests and changing the function signatures because of lazy analysis not checking them

* fix a bug that got uncovered by lazy eval

* Add compile error when using WASI with openDirAbsolute and accessAbsolute

* typo
2020-11-18 08:42:35 +01:00
Andrew Kelley
bf03ae7acc std.fs.path.dirname: return null when input path is root
This intentionally diverges from the unix dirname command, as well as
Python and Node.js standard libraries, which all have this edge case
return the input path, unmodified. This is a footgun, and nobody should
have ever done it this way.

Even the man page contradicts the behavior. It says:
"strip last component from file name". Now consider, if you
remove the last item from an array of length 1, then you
have now an array of length 0. After you strip the last component, there
should be no components remaining. Clearly, returning the input parameter
unmodified in this case does not match the documented behavior. This is
my justification for taking a stand on this API design.

closes #6746
closes #6727
closes #6584
closes #6592
closes #6602
2020-11-13 17:36:49 -07:00
Sébastien Marie
ab4b34f75f openbsd: skip tests using Dir.realpath 2020-11-13 12:30:14 -05:00
Andrew Kelley
ceaa569bfa disable flaky file locking test on Windows
See #7010
2020-11-06 17:00:51 -07:00
LemonBoy
b9391c9564 std: Make file locking tests less fragile 2020-11-06 14:02:11 -05:00
Andrew Kelley
ede41759be std.fs.File.writeFileAll: support unseekable files
With this commit, the function tries to use more efficient syscalls, and
then falls back to non-positional reads.

The motivating use case for this change is to support something like the
following:

try io.getStdOut().writeFileAll(dest_file, .{});
2020-11-03 15:25:43 -07:00
Sebastien Marie
35a7247a2c
Merge branch 'master' into openbsd-minimal 2020-10-17 17:38:23 +02:00
Andrew Kelley
27b04d5905 disable the failing std lib freebsd tests
enable std lib freebsd tests on the CI

See #1759
2020-10-12 20:08:23 -07:00
Vignesh Rajagopalan
2ab0c7391a Rename .macosx to .macos 2020-10-12 18:56:25 -04:00
Sébastien Marie
f33a610c84 add minimal openbsd support 2020-10-11 08:23:36 +00:00
Andrew Kelley
b2b0bf0506 fixups for the previous commit
* std.fs.File.copyRange and copyRangeAll return u64 instead of usize -
   the returned value is how much of the `len` is transferred, so the
   types should match. This removes the need for an `@intCast`.
 * fix typo that removed a subtraction
 * Fix the size of codegen.AnyMCValue which gave me a compile error when
   I tried to build self-hosted for i386-linux.
 * restore the coercion to u64 of syms_sect.sh_info. We want to make
   sure the multiplication happens with 64 bits and not the smaller type
   used by the ELF format.
 * fix another offset parameter in link/Elf.zig to be u64 instead of usize
 * add a nice little TODO note to help out Jakub
 * FmtError already has FileTooBig in it; we just need to return it.
2020-10-07 00:39:13 -07:00
Timon Kruiper
bd7eab573a Fix building the zig compiler for 32-bit targets 2020-10-06 23:39:58 -07:00
Ryan Liptak
bd449b184a Add deleteDir test with exception for not-empty directory on Windows
Re-adds the test that was added and then reverted in https://github.com/ziglang/zig/pull/6397, but with the test for https://github.com/ziglang/zig/issues/5537 skipped for now since that issue is no longer fixed.
2020-09-30 02:35:17 -04:00
Jakub Konka
bb636cb3bf Revert "Fix for Windows: std.os.windows.DeleteFile()" 2020-09-29 19:35:44 -04:00
Jakub Konka
e60939bfaa
Merge pull request #6397 from suirad/fix-5537
Fix for Windows: std.os.windows.DeleteFile()
2020-09-27 21:59:29 +02:00
Suirad
f78652484a Stdlib fix for os.windows.deleteFile to fail with
a proper error when attempting to delete a directory that isnt empty
2020-09-25 18:09:05 -05:00
Loris Cro
dc01ef7388
Remove noop check
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-09-25 23:21:20 +02:00
Loris Cro
7fec5b3def pwritev
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:06:41 +02:00
Loris Cro
7a07c62a07 pwrite
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:06:21 +02:00
Loris Cro
18f6629bd8 writev
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:06:03 +02:00
Loris Cro
9075f8e5a1 write
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:05:41 +02:00
Loris Cro
59ecdaea12 preadv
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:04:43 +02:00
Loris Cro
bd9f2369d5 pread
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:04:05 +02:00
Loris Cro
bc35435ca6 readv
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:03:12 +02:00
Loris Cro
08364ac773 read
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:00:55 +02:00
Ryan Liptak
5e3fa0e94f Add rename to std.fs API
- Moves fs.rename functions to fs.renameAbsolute to match other functions outside of fs.Dir
- Adds fs.Dir.rename that takes two paths relative to the given Dir
- Adds fs.rename that takes two separate Dir's that the given paths are relative to (for renaming across directories without having to make the second path relative to a single directory)
- Fixes FileNotFound error return in std.os.windows.MoveFileExW
- Returns error.RenameAcrossMountPoints from renameatW
  + Matches the RenameAcrossMountPoints error return in renameatWasi/renameatZ
2020-09-17 17:22:26 -04:00
Andrew Kelley
c41cd3e13a std.fs.File: fix typo in writeFileAll 2020-09-10 18:53:20 -07:00
Christian Wesselhoeft
ea9b38c93c fs/file.zig: Update reader to use type alias
This is a minor cosmetic change which updates `reader` and `inStream`
to match `writer` and `outStream` below.
2020-09-10 15:42:24 -04:00
LemonBoy
90743881cf std: Minor changes to the fs module
* Add a size_hint parameter to the read{toEnd,File}AllocOptions fns
* Rename readAllAlloc{,Options} to readToEndAlloc{,Options} as they
  don't rewind the file before reading
* Fix missing rewind in test case
2020-09-04 10:17:00 +02:00
LemonBoy
73a8c9beaa std: Don't trust stat() size in readAllAlloc fns
Some files such as the ones in /proc report a st_size of zero, try to
read the file anyway if we hit that case.
2020-09-02 11:11:57 +02:00
Sahnvour
ac85befbb4 handle lack of privilege to create symbolic links on windows 2020-08-30 06:52:53 +02:00
daurnimator
129d3e274d
std: use O_NOCTTY flag 2020-08-24 02:28:31 +10:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Jakub Konka
3e2e6baee5 Add std.os.getFdPath and std.fs.Dir.realpath
`std.os.getFdPath` is very platform-specific and can be used to query
the OS for a canonical path to a file handle. Currently supported hosts
are Linux, macOS and Windows.

`std.fs.Dir.realpath` (and null-terminated, plus WTF16 versions) are
similar to `std.os.realpath`, however, they resolve a path wrt to this
`Dir` instance.

If the input pathname argument turns out to be an absolute path, this
function reverts to calling `realpath` on that pathname completely
ignoring this `Dir`.
2020-08-13 07:08:39 +02:00
Maciej Walczak
6febe7e977
copy_file_range linux syscall (#6010) 2020-08-11 15:49:43 -04:00
Jakub Konka
8981b18fee Move delete file logic into windows.DeleteFile fn
This way, we can remove more `kernel32` calls such as `RemoveDirectoryW`
or `DeleteFileW`, and use `std.os.windows.DeleteFile` instead which
is purely NT-based.
2020-07-31 16:31:51 +02:00
Jakub Konka
a89d5cfc3e Remove CreateDirectoryW and CreateFileW calls
Replace them with `std.os.windows.OpenFile` instead. To allow
creation/opening of directories, `std.os.windows.OpenFileOptions`
now features a `.expect_dir: bool` member which is meant to emualate
POSIX's `O_DIRECTORY` flag.
2020-07-31 16:31:23 +02:00
Jakub Konka
aa6fcaf76f Add missing cross-platform Dir.readLink fns 2020-07-22 08:51:23 +02:00
Jakub Konka
e0b77a6b77 Ensure Dir.deleteTree does not dereference symlinks
Otherwise, the behaviour can lead to unexpected results, resulting
in removing an entire tree that's not necessarily under the root.
Furthermore, this change is needed if are to properly handle dir
symlinks on Windows. Without explicitly requiring that a directory
or file is opened with `FILE_OPEN_REPARSE_POINT`, Windows automatically
dereferences all symlinks along the way. This commit adds another
option to `OpenDirOptions`, namely `.no_follow`, which defaults to
`false` and can be used to specifically open a directory symlink on
Windows or call `openat` with `O_NOFOLLOW` flag in POSIX.
2020-07-22 08:51:22 +02:00
Jakub Konka
fc7d87fef1 Move symlink to fs.symlinkAbsolute with SymlinkFlags
This way `std.fs.symlinkAbsolute` becomes cross-platform and we can
legally include `SymlinkFlags` as an argument that's only used on
Windows. Also, now `std.os.symlink` generates a compile error on
Windows with a message to instead use `std.os.windows.CreateSymbolicLink`.
Finally, this PR also reshuffles the tests between `std.os.test` and
`std.fs.test`.
2020-07-22 08:51:22 +02:00
Jakub Konka
eea7271c4e Fix incorrect continue condition in PreopeonList
Also, check for overflow on incremented file descriptors. Previously,
we'd trigger a panic if we exceeded the `fd_t` resolution. Now, instead,
we throw an `error.Overflow` to signal that there can be no more
file descriptors available from the runtime. This way we give the user
the ability to still be able to check if their desired preopen exists
in the list or not.
2020-07-12 21:02:33 +00:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
Andrew Kelley
597a363673
Merge pull request #5755 from kubkon/dir-iter-tests
[libstd]: add Dir.Iterator tests
2020-07-07 23:13:58 +00:00
joachimschmidt557
0ae1157e45 std.mem.dupe is deprecated, move all references in std
Replaced all occurences of std.mem.dupe in stdlib with
Allocator.dupe/std.mem.dupeZ -> Allocator.dupeZ
2020-07-04 21:40:06 +03:00
Jakub Konka
e7d02eae4d
Update lib/std/fs/test.zig
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-02 20:54:57 +02:00
Jakub Konka
b5badd1122 Fix memory corruption in Dir.Iterator test 2020-07-02 10:35:44 +02:00