about summary refs log tree commit diff
path: root/src/libstd/fs.rs
AgeCommit message (Collapse)AuthorLines
2015-07-15Add specializations of read_to_end for Stdin, TcpStream and File,Alisdair Owens-0/+4
allowing them to read into a buffer containing uninitialized data, rather than pay the cost of zeroing.
2015-07-11Change std::fs::File.set_len example and documentationjethrogb-2/+6
The File object needs to be writable for the truncate to succeed.
2015-07-10Auto merge of #26751 - retep998:copy-that-floppy, r=alexcrichtonbors-15/+27
Using the OS mechanism for copying files allows the OS to optimize the transfer using stuff such as [Offloaded Data Transfers (ODX)](https://msdn.microsoft.com/en-us/library/windows/desktop/hh848056%28v=vs.85%29.aspx). Also preserves a lot more information, including NTFS [File Streams](https://msdn.microsoft.com/en-us/library/windows/desktop/aa364404%28v=vs.85%29.aspx), which the manual implementation threw away. In addition, it is an atomic operation, unlike the manual implementation which has extra calls for copying over permissions. r? @alexcrichton
2015-07-10Use CopyFileEx for fs::copy on WindowsPeter Atashian-15/+27
Adds a couple more tests for fs::copy Signed-off-by: Peter Atashian <retep998@gmail.com>
2015-07-09Add FileTypeUnix trait to add unix special file typesJesús Espino-0/+4
2015-06-28Add `.write(true)` to append and truncate examplesRemi Rampin-2/+2
Setting append without write doesn't give you a writeable file. Showing it as an example in the docs is confusing at best. Using truncate on a read-only file is an error on POSIX systems (note however that using create with read-only flags is fine).
2015-06-09std: Stabilize a number of new fs featuresAlex Crichton-57/+31
This commit stabilizes the following APIs, slating them all to be cherry-picked into the 1.1 release. * fs::FileType (and transitively the derived trait implementations) * fs::Metadata::file_type * fs::FileType::is_dir * fs::FileType::is_file * fs::FileType::is_symlink * fs::DirEntry::metadata * fs::DirEntry::file_type * fs::DirEntry::file_name * fs::set_permissions * fs::symlink_metadata * os::raw::{self, *} * os::{android, bitrig, linux, ...}::raw::{self, *} * os::{android, bitrig, linux, ...}::fs::MetadataExt * os::{android, bitrig, linux, ...}::fs::MetadataExt::as_raw_stat * os::unix::fs::PermissionsExt * os::unix::fs::PermissionsExt::mode * os::unix::fs::PermissionsExt::set_mode * os::unix::fs::PermissionsExt::from_mode * os::unix::fs::OpenOptionsExt * os::unix::fs::OpenOptionsExt::mode * os::unix::fs::DirEntryExt * os::unix::fs::DirEntryExt::ino * os::windows::fs::MetadataExt * os::windows::fs::MetadataExt::file_attributes * os::windows::fs::MetadataExt::creation_time * os::windows::fs::MetadataExt::last_access_time * os::windows::fs::MetadataExt::last_write_time * os::windows::fs::MetadataExt::file_size The `os::unix::fs::Metadata` structure was also removed entirely, moving all of its associated methods into the `os::unix::fs::MetadataExt` trait instead. The methods are all marked as `#[stable]` still. As some minor cleanup, some deprecated and unstable fs apis were also removed: * File::path * Metadata::accessed * Metadata::modified Features that were explicitly left unstable include: * fs::WalkDir - the semantics of this were not considered in the recent fs expansion RFC. * fs::DirBuilder - it's still not 100% clear if the naming is right here and if the set of functionality exposed is appropriate. * fs::canonicalize - the implementation on Windows here is specifically in question as it always returns a verbatim path. Additionally the Unix implementation is susceptible to buffer overflows on long paths unfortunately. * fs::PathExt - as this is just a convenience trait, it is not stabilized at this time. * fs::set_file_times - this funciton is still waiting on a time abstraction.
2015-05-28Rollup merge of #25128 - steveklabnik:gh24816, r=alexcrichtonManish Goregaokar-0/+2
Fixes #24816 r? @alexcrichton
2015-05-26Add note about filesystems to fs::renameSteve Klabnik-0/+2
Fixes #24816
2015-05-20Fix stability and deprecation markers on soft_link and symlinkBrian Campbell-1/+1
The change to split up soft_link to OS-specific symlink, symlink_file, and symlink_dir didn't actually land in 1.0.0. Update the stability and deprecation attributes to correctly indicate that these changes happend in 1.1.0.
2015-05-18[doc] Add a reference from PathExt to fs::metadataMatt Brubeck-2/+3
2015-05-16fs::walk_dir example without unstable featuresJohannes Hoff-6/+5
The current version of the example won't compile due to unstable features. This is an attempt to fix that, at the cost of slightly more verbose code.
2015-05-07std: Rename sys::foo2 modules to sys::fooAlex Crichton-1/+1
Now that `std::old_io` has been removed for quite some time the naming real estate here has opened up to allow these modules to move back to their proper names.
2015-04-30Remove unnecessary 'mut' qualifier on doc-comment varCorey Farwell-1/+1
The variable doesn't need to be mutable.
2015-04-28std: Implement fs::DirBuilderAlex Crichton-5/+57
This is the last remaining portion of #24796
2015-04-27std: Expand the area of std::fsAlex Crichton-14/+218
This commit is an implementation of [RFC 1044][rfc] which adds additional surface area to the `std::fs` module. All new APIs are `#[unstable]` behind assorted feature names for each one. [rfc]: https://github.com/rust-lang/rfcs/pull/1044 The new APIs added are: * `fs::canonicalize` - bindings to `realpath` on unix and `GetFinalPathNameByHandle` on windows. * `fs::symlink_metadata` - similar to `lstat` on unix * `fs::FileType` and accessor methods as `is_{file,dir,symlink}` * `fs::Metadata::file_type` - accessor for the raw file type * `fs::DirEntry::metadata` - acquisition of metadata which is free on Windows but requires a syscall on unix. * `fs::DirEntry::file_type` - access the file type which may not require a syscall on most platforms. * `fs::DirEntry::file_name` - access just the file name without leading components. * `fs::PathExt::symlink_metadata` - convenience method for the top-level function. * `fs::PathExt::canonicalize` - convenience method for the top-level function. * `fs::PathExt::read_link` - convenience method for the top-level function. * `fs::PathExt::read_dir` - convenience method for the top-level function. * `std::os::raw` - type definitions for raw OS/C types available on all platforms. * `std::os::$platform` - new modules have been added for all currently supported platforms (e.g. those more specific than just `unix`). * `std::os::$platform::raw` - platform-specific type definitions. These modules are populated with the bare essentials necessary for lowing I/O types into their raw representations, and currently largely consist of the `stat` definition for unix platforms. This commit also deprecates `Metadata::{modified, accessed}` in favor of inspecting the raw representations via the lowering methods of `Metadata`.
2015-04-21rollup merge of #24222: lambda/rename-soft-link-to-symlinkAlex Crichton-7/+14
Implement [RFC #1048][rfc]. On Windows, when you create a symbolic link you must specify whether it points to a directory or a file, even if it is created dangling, while on Unix, the same symbolic link could point to a directory, a file, or nothing at all. Furthermore, on Windows special privilege is necessary to use a symbolic link, while on Unix, you can generally create a symbolic link in any directory you have write privileges to. This means that it is unlikely to be able to use symbolic links purely portably; anyone who uses them will need to think about the cross platform implications. This means that using platform-specific APIs will make it easier to see where code will need to differ between the platforms, rather than trying to provide some kind of compatibility wrapper. Furthermore, `soft_link` has no precedence in any other API, so to avoid confusion, move back to the more standard `symlink` terminology. Create a `std::os::unix::symlink` for the Unix version that is destination type agnostic, as well as `std::os::windows::{symlink_file, symlink_dir}` for Windows. Because this is a stable API, leave a compatibility wrapper in `std::fs::soft_link`, which calls `symlink` on Unix and `symlink_file` on Windows, preserving the existing behavior of `soft_link`. [rfc]: https://github.com/rust-lang/rfcs/pull/1048
2015-04-21Deprecate std::fs::soft_link in favor of platform-specific versionsBrian Campbell-7/+14
On Windows, when you create a symbolic link you must specify whether it points to a directory or a file, even if it is created dangling, while on Unix, the same symbolic link could point to a directory, a file, or nothing at all. Furthermore, on Windows special privilege is necessary to use a symbolic link, while on Unix, you can generally create a symbolic link in any directory you have write privileges to. This means that it is unlikely to be able to use symbolic links purely portably; anyone who uses them will need to think about the cross platform implications. This means that using platform-specific APIs will make it easier to see where code will need to differ between the platforms, rather than trying to provide some kind of compatibility wrapper. Furthermore, `soft_link` has no precedence in any other API, so to avoid confusion, move back to the more standard `symlink` terminology. Create a `std::os::unix::symlink` for the Unix version that is destination type agnostic, as well as `std::os::windows::{symlink_file, symlink_dir}` for Windows. Because this is a stable API, leave a compatibility wrapper in `std::fs::soft_link`, which calls `symlink` on Unix and `symlink_file` on Windows, preserving the existing behavior of `soft_link`.
2015-04-21Implement Debug for FileChris Wong-0/+7
This patch adds a `Debug` impl for `std::fs::File`. On all platforms (Unix and Windows) it shows the file descriptor. On Linux, it displays the path and access mode as well. Ideally we should show the path/mode for all platforms, not just Linux, but this will do for now. cc #24570
2015-04-17Rollup merge of #24452 - tbu-:pr_file_path, r=aturonManish Goregaokar-7/+6
Fixes #22190.
2015-04-15Fix some typos.Ms2ger-2/+2
2015-04-15Remove one allocation for the file path in file openingTobias Bucher-7/+6
Fixes #22190.
2015-04-14rollup merge of #24377: apasel422/docsAlex Crichton-13/+13
Conflicts: src/libstd/net/ip.rs src/libstd/sys/unix/fs.rs src/libstd/sys/unix/mod.rs src/libstd/sys/windows/mod.rs
2015-04-14test: Fixup many library unit testsAlex Crichton-2/+3
2015-04-13pluralize doc comment verbs and add missing periodsAndrew Paseltiner-13/+13
2015-04-07std: Deny most warnings in doctestsAlex Crichton-11/+14
Allow a few specific ones but otherwise this helps ensure that our examples are squeaky clean! Closes #18199
2015-04-02Auto merge of #23931 - steveklabnik:doc_std_fs, r=alexcrichtonbors-42/+306
2015-04-02Add more examples and documentation for std::fsSteve Klabnik-42/+306
2015-04-02Test fixes and rebase conflicts, round 2Alex Crichton-1/+1
Conflicts: src/libcore/num/mod.rs
2015-03-31rollup merge of #23919: alexcrichton/stabilize-io-errorAlex Crichton-2/+1
Conflicts: src/libstd/fs/tempdir.rs src/libstd/io/error.rs
2015-03-31rollup merge of #23873: alexcrichton/remove-deprecatedAlex Crichton-0/+1647
Conflicts: src/libcollectionstest/fmt.rs src/libcollectionstest/lib.rs src/libcollectionstest/str.rs src/libcore/error.rs src/libstd/fs.rs src/libstd/io/cursor.rs src/libstd/os.rs src/libstd/process.rs src/libtest/lib.rs src/test/run-pass-fulldeps/compiler-calls.rs
2015-03-31std: Clean out #[deprecated] APIsAlex Crichton-0/+1641
This commit cleans out a large amount of deprecated APIs from the standard library and some of the facade crates as well, updating all users in the compiler and in tests as it goes along.
2015-02-24std: Move std::env to the new I/O APIsAlex Crichton-1503/+0
This commit moves `std::env` away from the `std::old_io` error type as well as the `std::old_path` module. Methods returning an error now return `io::Error` and methods consuming or returning paths use `std::path` instead of `std::old_path`. This commit does not yet mark these APIs as `#[stable]`. This commit also migrates `std::old_io::TempDir` to `std::fs::TempDir` with essentially the exact same API. This type was added to interoperate with the new path API and has its own `tempdir` feature. Finally, this commit reverts the deprecation of `std::os` APIs returning the old path API types. This deprecation can come back once the entire `std::old_path` module is deprecated. [breaking-change]
2015-02-20try to reduce bajillion warningsAlexis-2/+4
2015-02-17Fix a small typo in libstd/fs.rsMarkus Siemens-1/+1
2015-02-15doc: fix and expand File::create explanationTshepang Lekhonkhobe-3/+3
2015-02-09std: Add a new `fs` moduleAlex Crichton-0/+1501
This commit is an implementation of [RFC 739][rfc] which adds a new `std::fs` module to the standard library. This module provides much of the same functionality as `std::old_io::fs` but it has many tweaked APIs as well as uses the new `std::path` module. [rfc]: https://github.com/rust-lang/rfcs/pull/739
2012-03-12Libc/os/run/rand/io reorganization. Close #1373. Close #1638.Graydon Hoare-765/+0
- Move io, run and rand to core. - Remove incorrect ctypes module (use libc). - Remove os-specific modules for os and fs. - Split fs between core::path and core::os.
2012-03-08Rename last to last_opt, last_unsafe to lastTim Chevalier-1/+1
As per discussion on IRC. I am about to file an RFC for further discussion about the more general issue of whether to enforce invariants through types, typestate, or dynamic checks, but for now, removing the misleading name "last_unsafe".
2012-03-08Rename last_total to last_unsafeTim Chevalier-1/+2
See Issue 1943 for any discussion (reopen it if necessary). Closes #1943
2012-03-02std: add a fs::remove_file function.Erick Tryzelaar-0/+21
2012-02-29std: DeCamelCase fs::splitDirnameBasenameBrian Anderson-3/+3
2012-02-23Finish cleanup of core::strMarijn Haverbeke-12/+8
Closes #1849
2012-02-23Various cleanups and optimizations in core::strMarijn Haverbeke-13/+5
2012-02-23(core::str) remove len_bytes aliasKevin Cantu-6/+6
2012-02-23(core::str) do some replacementsKevin Cantu-4/+4
2012-02-23(core::char) rename slice -> slice_charsKevin Cantu-2/+2
2012-02-23(core::str) rename rindex -> rindex_charsKevin Cantu-2/+2
2012-02-23(core::str) mostly rename len -> len_charsKevin Cantu-1/+1
2012-02-22Remove preconditions from librariesMarijn Haverbeke-2/+1
Closes #1805