Commit Graph

314 Commits

Author SHA1 Message Date
Alexis Bourget
ec63f9d99b Added the note to Metadata too 2020-06-11 18:15:57 +02:00
Alexis Bourget
93cbad6ed5 Add documentation to point to !is_dir instead of is_file 2020-06-11 17:44:33 +02:00
Steven Fackler
07443f17d4 Update name 2020-04-26 04:24:16 -07:00
Steven Fackler
15262ec6be Add Read/Write::can_read/write_vectored
When working with an arbitrary reader or writer, code that uses vectored
operations may end up being slower than code that copies into a single
buffer when the underlying reader or writer doesn't actually support
vectored operations. These new methods allow you to ask the reader or
witer up front if vectored operations are efficiently supported.

Currently, you have to use some heuristics to guess by e.g. checking if
the read or write only accessed the first buffer. Hyper is one concrete
example of a library that has to do this dynamically:
0eaf304644/src/proto/h1/io.rs (L582-L594)
2020-04-26 04:23:39 -07:00
Lzu Tao
f87afec2ce Use Self over specific type in return position 2020-04-02 03:55:35 +00:00
Lukas
31183bbd5a
Fix missing ` in doc for File::with_options 2020-03-06 14:27:09 +00:00
jumbatm
c899dc1401 Reword OpenOptions::{create, create_new} doc. 2020-02-19 19:57:32 +10:00
Lzu Tao
3a2ef17194 tidy: change msdn links to newer locations
see accouncement at https://docs.microsoft.com/welcome-to-docs
2019-12-25 15:35:54 +00:00
Patrick Wang
b65c6ec10f
Fix incorrect example code of OpenOptions::open 2019-12-14 03:12:50 +08:00
Umesh Kalappa
dc1a428d87 Modified the testcases for VxWorks 2019-12-03 11:58:03 -08:00
David Tolnay
4436c9d354
Format libstd with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd *that are not involved in any currently open PR* to
minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8

With the list of files from the script in outstanding_files, the
relevant commands were:

    $ find src/libstd -name '*.rs' \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ rg libstd outstanding_files | xargs git checkout --

Repeating this process several months apart should get us coverage of
most of the rest of libstd.

To confirm no funny business:

    $ git checkout $THIS_COMMIT^
    $ git show --pretty= --name-only $THIS_COMMIT \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ git diff $THIS_COMMIT  # there should be no difference
2019-11-29 18:43:27 -08:00
bors
91fd6283e6 Auto merge of #65429 - Timmmm:withoptions, r=Mark-Simulacrum
Add File::with_options

This provides a more fluent API to create files with options, and also avoids the need to import OpenOptions.

This implements @aldanor's [suggestion](https://github.com/rust-lang/rfcs/pull/2615#issuecomment-448591304) which was popular.
2019-11-02 18:22:32 +00:00
oxalica
43f398be6d
Prefer statx on linux if available 2019-10-18 10:32:27 +08:00
Tim Hutt
c8150cb159 Fix read/write links hopefully! 2019-10-16 09:03:52 +01:00
Tim Hutt
6cefcb0b54 Add File::with_options
This provides a more fluent API to create files with options, and also avoids the need to import OpenOptions.
2019-10-15 21:19:08 +01:00
BaoshanPang
45f7186de3 use 'invalid argument' for vxWorks 2019-10-07 11:52:30 -07:00
Mazdak Farrokhzad
c623aa4a54
Rollup merge of #63356 - ali-raheem:issue#63183, r=KodrAus
Issue#63183: Add fs::read_dir() and ReadDir warning about iterator order + example

As per https://github.com/rust-lang/rust/issues/63183

Add warning about iterator order to read_dir and ReadDir, add example of explicitly ordering direntrys.
2019-09-24 23:45:13 +02:00
Mazdak Farrokhzad
0a2e07ec1d
Rollup merge of #63872 - marmistrz:readdir, r=jonas-schievink
Document platform-specific behavior of the iterator returned by std::fs::read_dir
2019-09-15 19:35:58 +02:00
Ali Raheem
1161aeb2b4 Replace println statements with explanatory comments 2019-09-09 20:38:21 +01:00
Mateusz Mikuła
32101ad3b3 Upgrade rand to 0.7 2019-09-06 14:45:28 +02:00
Ali Raheem
3c820fef9f Comment out println in read_dir sorting example 2019-08-26 11:24:08 +01:00
Marcin Mielniczuk
c8619ae791
Document platform-specific behavior of the iterator returned by std::fs::read_dir 2019-08-25 00:09:12 +02:00
Ali Raheem
53c504650d Fix gramitcal error in read_dir example 2019-08-15 10:53:29 +01:00
Ali Raheem
8068812d04 Remove Iteration order heading 2019-08-08 15:33:39 +01:00
Ali Raheem
9755fe80ee Add fs::read_dir() and ReadDir warning about iterator order + example 2019-08-07 15:59:18 +01:00
Marcin Mielniczuk
3cd9f3f6ab
Add an overflow check in truncate implementation for Unix. 2019-08-06 19:35:54 +02:00
Alex Crichton
8d7fb87e65 std: Fix a failing fs test on Windows
In testing 4-core machines on Azure the `realpath_works_tricky` test in
the standard library is failing with "The directory name is invalid". In
attempting to debug this test I was able to reproduce the failure
locally on my machine, and after inspecing the test it I believe is
exploiting Unix-specific behavior that seems to only sometimes work on
Windows. Specifically the test basically executes:

    mkdir -p a/b
    mkdir -p a/d
    touch a/f
    ln -s a/b/c ../d/e
    ln -s a/d/e ../f

and then asserts that `canonicalize("a/b/c")` and
`canonicalize("a/d/e")` are equivalent to `a/f`. On Windows however the
first symlink is a "directory symlink" and the second is a file symlink.
In both cases, though, they're pointing to files. This means that for
whatever reason locally and on the 4-core environment the call to
`canonicalize` is failing. On Azure today it seems to be passing, and
I'm not entirely sure why. I'm sort of presuming that there's some sort
of internals going on here where there's some global Windows setting
which makes symlinks behavior more unix-like and ignore the directory
hint.

In any case this should keep the test working and also fixes the test
locally for me.
2019-07-29 10:53:47 -07:00
memoryruins
83660b6273 Update libstd doctests to use dyn 2019-05-29 00:57:42 -04:00
Taiki Endo
ccb9dac5ed Fix intra-doc link resolution failure on re-exporting libstd 2019-05-04 23:48:57 +09:00
Edward Barnard
0fd446ea78 Make std::fs::copy attempt to create copy-on-write clones of files on MacOS. 2019-05-02 09:41:37 +01:00
Steven Fackler
bd177f3ea3 Stabilized vectored IO
This renames `std::io::IoVec` to `std::io::IoSlice` and
`std::io::IoVecMut` to `std::io::IoSliceMut`, and stabilizes
`std::io::IoSlice`, `std::io::IoSliceMut`,
`std::io::Read::read_vectored`, and `std::io::Write::write_vectored`.

Closes #58452
2019-04-27 08:34:08 -07:00
varkor
aa388f1d11 ignore-tidy-filelength on all files with greater than 3000 lines 2019-04-25 21:39:09 +01:00
Jan Nils Ferner
379c5412ef
Simplify the returning of a Result a bit 2019-04-18 07:33:31 +02:00
Alex Crichton
acf3ddb5ad std: Add {read,write}_vectored for more types
This commit implements the `{read,write}_vectored` methods on more types
in the standard library, namely:

* `std::fs::File`
* `std::process::ChildStd{in,out,err}`
* `std::io::Std{in,out,err}`
* `std::io::Std{in,out,err}Lock`
* `std::io::Std{in,out,err}Raw`

Where supported the OS implementations hook up to native support,
otherwise it falls back to the already-defaulted implementation.
2019-04-10 12:51:25 -07:00
bors
52980d0fb3 Auto merge of #59695 - Centril:rollup-88qffc2, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #59470 (Document std::fs::File close behavior ignoring errors)
 - #59555 (update miri)
 - #59556 (update stdsimd)
 - #59596 (Forward formatter settings to bounds of `Range<T>` in `fmt::Debug` impl)
 - #59639 (Never return uninhabited values at all)
 - #59671 (Make some of lexer's API private)
 - #59685 (Add description for -Os and -Oz in rustc.1)
 - #59686 (Temporarily disable stack probing for gnux32.)

Failed merges:

r? @ghost
2019-04-04 15:36:17 +00:00
Mazdak Farrokhzad
886456deab
Rollup merge of #59470 - czipperz:document-fs-file-close, r=dtolnay
Document std::fs::File close behavior ignoring errors

Resolves #52685
2019-04-04 15:08:59 +02:00
Chris Gregory
a969d40987 File: Add documentation about dropping to sync_all 2019-04-03 23:21:10 -04:00
Alex Crichton
61b487ca8b wasi: Fill out std::fs module for WASI
This commit fills out the `std::fs` module and implementation for WASI.
Not all APIs are implemented, such as permissions-related ones and
`canonicalize`, but all others APIs have been implemented and very
lightly tested so far. We'll eventually want to run a more exhaustive
test suite!

For now the highlights of this commit are:

* The `std::fs::File` type is now backed by `WasiFd`, a raw WASI file
  descriptor.
* All APIs in `std::fs` (except permissions/canonicalize) have
  implementations for the WASI target.
* A suite of unstable extension traits were added to
  `std::os::wasi::fs`. These traits expose the raw filesystem
  functionality of WASI, namely `*at` syscalls (opening a file relative
  to an already opened one, for example). Additionally metadata only
  available on wasi is exposed through these traits.

Perhaps one of the most notable parts is the implementation of
path-taking APIs. WASI actually has no fundamental API that just takes a
path, but rather everything is relative to a previously opened file
descriptor. To allow existing APIs to work (that only take a path) WASI
has a few syscalls to learn about "pre opened" file descriptors by the
runtime. We use these to build a map of existing directory names to file
descriptors, and then when using a path we try to anchor it at an
already-opened file.

This support is very rudimentary though and is intended to be shared
with C since it's likely to be so tricky. For now though the C library
doesn't expose quite an API for us to use, so we implement it for now
and will swap it out as soon as one is available.
2019-04-03 08:05:46 -07:00
Chris Gregory
76e82d6f52 Link to sync_all 2019-04-02 22:26:11 -04:00
Chris Gregory
b6ebe1bd9e Document using sync_all 2019-04-01 22:34:57 -04:00
Mazdak Farrokhzad
379c380a60 libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
Chris Gregory
f48a5dcf8f Document std::fs::File close behavior ignoring errors 2019-03-27 16:37:50 -04:00
Jethro Beekman
f229422cc1 SGX target: fix std unit tests 2019-03-25 11:31:19 -07:00
kennytm
d1744728a0
Rollup merge of #59082 - alexreg:cosmetic-2-doc-comments, r=Centril
A few improvements to comments in user-facing crates

Not too many this time, and all concern comments (almost all doc comments) in user-facing crates (libstd, libcore, liballoc).

r? @steveklabnik
2019-03-16 22:39:56 +08:00
Alexander Regueiro
8629fd3e4e Improvements to comments in libstd, libcore, liballoc. 2019-03-11 02:25:44 +00:00
Edward Barnard
124ab2a4d8 Fix typo 2019-03-04 12:53:54 +00:00
Edward Barnard
0a991e424a Add test for the behaviour of fs::copy when to is a symlink 2019-03-04 12:35:46 +00:00
Edward Barnard
c82a42c155 Change std::fs::copy to use copyfile on MacOS and iOS 2019-03-04 12:33:15 +00:00
Taiki Endo
93b6d9e086 libstd => 2018 2019-02-28 04:06:15 +09:00
kennytm
e3a8f7db47
Rollup merge of #58553 - scottmcm:more-ihle, r=Centril
Use more impl header lifetime elision

Inspired by seeing explicit lifetimes on these two:

- https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator
- https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not

And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore.

Most of the changes in here fall into two big categories:

- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`)

- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)

I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm).

I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
2019-02-20 11:59:10 +08:00