201 Commits

Author SHA1 Message Date
Mathieu Guay-Paquet
4c8632e244 fix the tinyest typo 2020-12-02 19:08:25 +02:00
Jonathan Marler
48660371a2 std.meta: add assumeSentinel 2020-11-29 10:36:02 -08:00
LemonBoy
8ed7561422 std: Re-enable the use of O_EXLOCK/O_SHLOCK on macos 2020-11-24 10:23:54 +01:00
LemonBoy
26d20e39fc std: Close dangling fd on error
This patch was already submitted for openFileZ, createFileZ was left
unpatched.
2020-11-23 18:00:05 +01:00
LemonBoy
0d4f05bb8a std: Remove O_NONBLOCK flag after locking
We only need O_NONBLOCK when O_SHLOCK/O_EXLOCK are used and we don't
want open() to block, don't let this bit leak to the user fd.
2020-11-23 18:00:05 +01:00
LemonBoy
f8ddc3d873 std: Fix file locking logic for BSD targets 2020-11-23 18:00:05 +01:00
Sébastien Marie
b174942e6a openbsd, netbsd: getdents: entry with d_fileno==0 should be skipped 2020-11-19 13:55:46 +00:00
Sébastien Marie
7579ce180f Iterator: rename freebsd_entry to bsd_entry to reflect that nextBsd is not freebsd only 2020-11-19 13:54:47 +00:00
Sébastien Marie
ad2ff9e65d darwin: getdents: entry with d_ino==0 should be skipped 2020-11-19 13:54:29 +00:00
Veikka Tuominen
6d5b76a75d
Merge pull request #7005 from jshholland/deprecate-span
Remove ArrayList.span
2020-11-18 13:14:48 +02: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
Josh Holland
c25b157dda remove deprecated uses of ArrayList.span 2020-11-07 11:15:44 +00:00
Alex Cameron
ecdd636605 Fix file descriptor leak in fs.openFileZ. 2020-11-02 13:28:29 -05:00
Sébastien Marie
3115d2f2cd readd original code from #6638. realpathZ() is expected to take a [*:0]const u8 2020-10-25 10:02:10 +01:00
Andrew Kelley
05b1a7414e code cleanups
* in selfExePath, return errors instead of defaulting to bogus data
 * less invasive edits to the logic of link/Elf.zig
 * less indentation
2020-10-17 17:52:09 -07:00
Sebastien Marie
35a7247a2c
Merge branch 'master' into openbsd-minimal 2020-10-17 17:38:23 +02:00
Vignesh Rajagopalan
2ab0c7391a Rename .macosx to .macos 2020-10-12 18:56:25 -04:00
Sébastien Marie
a6dc2b7fcc openbsd: selfExePath adjustements 2020-10-11 12:23:52 +00:00
Sébastien Marie
97ec9fdd79 opensd: selfExePath: do not rely on environment as it could be inherited 2020-10-11 08:23:37 +00:00
Sébastien Marie
78a7543056 openbsd: use mem.span() + mem.indexOf() instead of defining custom function 2020-10-11 08:23:37 +00:00
Sébastien Marie
f33a610c84 add minimal openbsd support 2020-10-11 08:23:36 +00:00
Andrew Kelley
9f8f446435 fixups to previous commit
* std.fs.Dir.readFile: add doc comments to explain what it means when
   the returned slice has the same length as the supplied buffer.
 * introduce readSmallFile / writeSmallFile to abstract over the
   decision to use symlink or file contents to store data.
2020-10-09 16:45:39 -07:00
mlarouche
57912964af Use regular file for caching stage 1 hash digest instead of symlink, fix zig build caching on Windows
Fix #6500
2020-10-09 16:50:43 -04:00
Andrew Kelley
76a195473d
Merge pull request #6516 from LemonBoy/fastfilecopy
std: Make file copy ops use zero-copy mechanisms
2020-10-08 20:14:47 -04:00
LemonBoy
03762da2af New review round 2020-10-07 11:13:26 +02:00
LemonBoy
1f7ec0de70 Address review comments & fix compilation errors 2020-10-06 11:57:23 +02:00
LemonBoy
a419a1aabc Move copy_file to fs namespace
Now it is a private API.
Also handle short writes in copy_file_range fallback implementation.
2020-10-06 09:38:59 +02:00
Noah Altunian
c507c7862e Fix spelling in code comment
Changed **an handle** -> **a handle**.
2020-10-05 22:25:07 -04:00
LemonBoy
8b4f5f039d Alternative strategy to avoid calling stat()
This is an optimization as it avoids an extra syscall, but it's also a
workaround for fstat being not available on Windows.
2020-10-03 19:51:22 +02:00
LemonBoy
0f248e0988 std: Make file copy ops use zero-copy mechanisms
Use copy_file_range on Linux (if available), fcopyfile on Darwin,
sendfile on *BSDs (and on Linux kernels without copy_file_range).
2020-10-03 12:31:17 +02:00
Loris Cro
276598346a provide the full buffer length to _NSGetExecutablePath
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-03 12:03:22 +02:00
Loris Cro
f841ea77e2 make symlink buffer null-terminated
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-02 19:33:14 +02:00
Loris Cro
a2074c1ec3 fix symlink path not being resolved in darwin
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-02 17:06:29 +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
LemonBoy
3c8e1bc25b std: Fix for 32bit systems 2020-09-04 12:48:36 +02: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
daurnimator
129d3e274d
std: use O_NOCTTY flag 2020-08-24 02:28:31 +10:00
daurnimator
23a81b4396
std: refactor fs.openFileZ flag handling 2020-08-24 02:27:26 +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
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
66bbe4ec4c Refactor internal Win routines to reuse OpenFile
This covers mainly `ReadLink` and `CreateSymolicLink` functions.
2020-07-31 16:31:44 +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
Felix (xq) Queißner
606b6462ce Fixes atomicSymLink looping when new_path already exists. 2020-07-28 17:04:46 +00:00
Jakub Konka
aa6fcaf76f Add missing cross-platform Dir.readLink fns 2020-07-22 08:51:23 +02:00
Jakub Konka
4887350bf4 Finish drafting CreateSymolicLink using NT calls 2020-07-22 08:51:23 +02:00
Jakub Konka
2c9c13f624 Add various build fixes
Fix WASI build, fix atomicSymlink by using `cwd().symLink`, add
`Dir.symLink` on supported targets.
2020-07-22 08:51:22 +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
3c8ceb674e Fix Windows build 2020-07-22 08:51:22 +02:00