fs-more
Convenient file and directory operations built on top of std::fs with improved error handling.
Includes copying and moving files or directories with progress reporting.
Main features
- copying and moving files or directories with:
- in-depth configuration options (existing destination file behaviour, IO buffering settings, copying depth, etc.), and
- progress reporting, if needed,
- scan directories (with options such as scan depth and symlink behaviour), and
- calculate file or directory sizes.
Usage
To add fs-more into your project, specify it as a dependency in your Cargo.toml file:
= "0.5.1"
Examples
Copying a file and getting updates on the progress:
use Path;
use ExistingFileBehaviour;
use FileCopyWithProgressOptions;
use FileCopyFinished;
let source_path = new;
let destination_path = new;
let finished_copy = copy_file_with_progress.unwrap;
match finished_copy ;
Moving a directory and getting updates on the progress:
use Path;
use DirectoryMoveWithProgressOptions;
use DestinationDirectoryRule;
let source_path = new;
let destination_path = new;
let moved = move_directory_with_progress.unwrap;
println!;
Feature flags
The following feature flags are available:
dunce(enabled by default): enables the optionalduncesupport: This automatically strips Windows' UNC paths if they can be represented using the usual type of path (e.g.\\?\C:\foo -> C:\foo). This is used both internally and in e.g.DirectoryScan's file and directory paths. This feature flag is enabled by default and recommended because because path canonicalization very commonly returns UNC paths. This crate only has an effect when compiling for Windows targets.fs-err(disabled by default): enablesfs-errsupport, which means more helpful underlying IO error messages (thoughfs-morealready provides many on its own).
Project status
fs-more does lack some thorough battle-testing; as such, use it with care.
The majority of common features are present. For now, we plan on keeping
the version below stable (1.0.0) to imply that this crate hasn't gone through a lot.
Quite a number of unit-, doc- and integration tests have been written.
They cover a wide array of the base functionality, but fringe cases might not be covered yet —
contributions are welcome.
The quite comprehensive test harness is available in subcrates/test-harness.
How to contribute
Found a bug or just want to improve fs-more by developing new features or writing tests? Awesome!
Start by going over the contribution guide: CONTRIBUTING.md.
Contributions for the ideas below are most welcome!
Some of these ideas and/or missing features are simpler, some are more of a long shot. However, note that even though they are stated below, they probably haven't been thought out deeply enough. If you decide to contribute, it would probably be best to first open an issue, so various approaches can be discussed before something is developed.
-
Cross-platform: allow copying file and directory permissions.
This partially already exists in some functions, but it inconsistent across the API. The reason is that
std::fs::copyalready copies permission bits, but we don't use that in several places, since copying with progress reporting makes usingstd::fs::copyimpossible. Ideally, we should expose a new option through the existing*Optionsstructs and make this consistent.I think this should be reasonably simple to do, but it might take some thinking about edge cases and implementing some platform-specifics (i.e. on Windows, we probably want to copy the hidden file flag, etc).
-
On Unix: allow copying file and directory owners and groups.
Depending on how deep the implementation rabbit-hole goes, perhaps using
file-ownerornixcould suffice? Perhaps we should feature-gate these kinds of things so the average user doesn't need to pull in so many dependencies? -
Cross-platform: allow copying creation/access/modification time of files and directories (across the entire API). This could also include various other metadata.
Ideally, this should be highly configurable through the existing
*Optionsstructs. This might take some more work though due to various platform differences (see: Unix, Linux, Windows).It might be more feasible to simply delegate this to some existing crate, i.e.
filetime(but this one covers only timestamps). Perhaps we should start with just creation/access/modification timestamps and expand later? -
On Windows: allow copying the ACL of files and directories.
This seems like a long shot and would need some concrete use cases before proceeding. Maybe
windows-aclcould help? If this feature is to be developed, I think we should not expose any underlying ACL API and allow purely for mirroring it when copying or moving. This should definitely be under a feature flag.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.