diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/dirs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
36 files changed, 3199 insertions, 0 deletions
diff --git a/vendor/dirs-next/.cargo-checksum.json b/vendor/dirs-next/.cargo-checksum.json new file mode 100644 index 000000000..e4bcb918b --- /dev/null +++ b/vendor/dirs-next/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"CHANGELOG.md":"154d14e845441ab50e77e39d27271b491ccdcf24abcefa5fba8849baf49d9752","Cargo.toml":"19b2a694823b5a551d9230dbc8dadcca52ba9ccd3f524e7302037c62be7781ea","LICENSE-APACHE":"d3174ad63e721d4c9dccb8ad4320848992d314369bc46319720b5802c9153fe9","LICENSE-MIT":"6a2e0ade09a7d5f816f11566fee2b151b32235a7fad52b41d49cce96f833c1a9","README.md":"8f3ae543f17fdc0aba26d76942abbfe9a165a36368d8897110734bde40d58bfd","src/lib.rs":"891ce8e700232d17bfb791d5435d9253abf26338b62a36ea1d84a8446c50e415","src/lin.rs":"e8d15b8e0ca88442572e6847df6e83aaa55eb516664cc8871f4ced20cc28cecc","src/mac.rs":"73bee8645d31c29cb882130be0e05d535cb62c0a90932176336553b7b47ba541","src/wasm.rs":"5cc16195a6f6c475cf849af2aff765085f1f70a9ba548d38d2cbf3fed4334007","src/win.rs":"c980eb7de59cbf683c50130290c312bcf83e8ea94e6231a83b2c189b889f9afc"},"package":"b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"}
\ No newline at end of file diff --git a/vendor/dirs-next/CHANGELOG.md b/vendor/dirs-next/CHANGELOG.md new file mode 100644 index 000000000..474a2d1a0 --- /dev/null +++ b/vendor/dirs-next/CHANGELOG.md @@ -0,0 +1,60 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +<!-- +# Guiding Principles + +* Changelogs are for _humans_, not machines. +* There should be an entry for every single version. +* The same types of changes should be grouped. +* Versions and sections should be linkable. +* The latest version comes first. +* The release date of each version is displayed. +* Mention whether you follow Semantic Versioning. + +# Types of changes + +* `Added` for new features. +* `Changed` for changes in existing functionality. +* `Deprecated` for soon-to-be removed features. +* `Removed` for now removed features. +* `Fixed` for any bug fixes. +* `Security` in case of vulnerabilities. + --> + +<!-- next-header --> +## [Unreleased] - ReleaseDate + +## [2.0.0] - 2020-10-22 +### Breaking changed +* Behavior of `config_dir` on macOS is changed. + According to [Apple guideline][appple-configdir], configuration files should be placed + in subdirectory of `Library/Application Support`. The old behavior of `config_dir` + returns `Library/Preferences`, which is incorrect. As users should use `CFPreferences` + API to get and set preference values for their app instead. + +[appple-configdir]: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW1 + +## [1.0.2] - 2020-10-13 +### Changed +* Bump cfg-if version to v1 + +## [1.0.1] +### Fixed +* Relax pinning `cfg-if` at `0.1.9`. Previously we inherited that from upstream repository when forking. + The original author wanted to keep minimum Rust version at 1.13 which we don't anymore. + +## [1.0.0] - 2020-05-17 + +This is the re-publish of `dirs` crate as is. + +<!-- next-url --> +[Unreleased]: https://github.com/xdg-rs/dirs/compare/dirs-v2.0.0...HEAD +[2.0.0]: https://github.com/xdg-rs/dirs/compare/dirs-v1.0.2...dirs-v2.0.0 +[1.0.2]: https://github.com/xdg-rs/dirs/compare/dirs-v1.0.1...dirs-v1.0.2 +[1.0.1]: https://github.com/xdg-rs/dirs/compare/dirs-v1.0.0...dirs-v1.0.1 +[1.0.0]: https://github.com/xdg-rs/dirs/releases/tag/dirs-v1.0.0 diff --git a/vendor/dirs-next/Cargo.toml b/vendor/dirs-next/Cargo.toml new file mode 100644 index 000000000..0a4b0392f --- /dev/null +++ b/vendor/dirs-next/Cargo.toml @@ -0,0 +1,30 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + +[package] +edition = "2018" +name = "dirs-next" +version = "2.0.0" +authors = ["The @xdg-rs members"] +include = ["CHANGELOG.md", "Cargo.toml", "LICENSE-APACHE", "LICENSE-MIT", "README.md", "/src/"] +description = "A tiny low-level library that provides platform-specific standard locations\nof directories for config, cache and other data on Linux, Windows, macOS\nand Redox by leveraging the mechanisms defined by the XDG base/user\ndirectory specifications on Linux, the Known Folder API on Windows,\nand the Standard Directory guidelines on macOS.\n" +readme = "README.md" +keywords = ["xdg", "basedir", "app_dirs", "path", "folder"] +license = "MIT OR Apache-2.0" +repository = "https://github.com/xdg-rs/dirs" +[dependencies.cfg-if] +version = "1.0.0" + +[dependencies.dirs-sys-next] +version = "0.1" +[badges.maintenance] +status = "passively-maintained" diff --git a/vendor/dirs-next/LICENSE-APACHE b/vendor/dirs-next/LICENSE-APACHE new file mode 100644 index 000000000..91e18a62b --- /dev/null +++ b/vendor/dirs-next/LICENSE-APACHE @@ -0,0 +1,174 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. diff --git a/vendor/dirs-next/LICENSE-MIT b/vendor/dirs-next/LICENSE-MIT new file mode 100644 index 000000000..1452dc143 --- /dev/null +++ b/vendor/dirs-next/LICENSE-MIT @@ -0,0 +1,19 @@ +Copyright (c) 2018-2019 dirs-rs contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/dirs-next/README.md b/vendor/dirs-next/README.md new file mode 100644 index 000000000..6de177246 --- /dev/null +++ b/vendor/dirs-next/README.md @@ -0,0 +1,167 @@ +[![crates.io](https://img.shields.io/crates/v/dirs-next.svg)](https://crates.io/crates/dirs-next) +[![API documentation](https://docs.rs/dirs-next/badge.svg)](https://docs.rs/dirs-next/) + +# `dirs-next` + +**Note**: This is a fork of once-abandoned `dirs` crate. + +There is a mid-level sister library, [directories-next]. + +## Introduction + +- a tiny low-level library with a minimal API +- that provides the platform-specific, user-accessible locations +- for retrieving and storing configuration, cache and other data +- on Linux, Redox, Windows (≥ Vista), macOS and other platforms. + +The library provides the location of these directories by leveraging the mechanisms defined by +- the [XDG base directory](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) and + the [XDG user directory](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/) specifications on Linux and Redox +- the [Known Folder](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457.aspx) API on Windows +- the [Standard Directories](https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW6) + guidelines on macOS + +## Platforms + +This library is written in Rust, and supports Linux, Redox, macOS and Windows. +Other platforms are also supported; they use the Linux conventions. + +## Minimum Rust version policy + +The minimal required version of Rust is `1.34.0`. + +We may bump the Rust version in major and minor releases (`x`/`y` in `x.y.z`). +Changing the Rust version will be written in the CHANGELOG. + +## Example + +Library run by user Alice: + +```rust +dirs_next::home_dir(); +// Lin: Some(/home/alice) +// Win: Some(C:\Users\Alice) +// Mac: Some(/Users/Alice) + +dirs_next::audio_dir(); +// Lin: Some(/home/alice/Music) +// Win: Some(C:\Users\Alice\Music) +// Mac: Some(/Users/Alice/Music) + +dirs_next::config_dir(); +// Lin: Some(/home/alice/.config) +// Win: Some(C:\Users\Alice\AppData\Roaming) +// Mac: Some(/Users/Alice/Library/Application Support) + +dirs_next::executable_dir(); +// Lin: Some(/home/alice/.local/bin) +// Win: None +// Mac: None +``` + +## Design Goals + +- The _dirs-next_ library is a low-level crate designed to provide the paths to standard directories + as defined by operating systems rules or conventions. If your requirements are more complex, + e. g. computing cache, config, etc. paths for specific applications or projects, consider using + [directories-next] instead. +- This library does not create directories or check for their existence. The library only provides + information on what the path to a certain directory _should_ be. How this information is used is + a decision that developers need to make based on the requirements of each individual application. +- This library is intentionally focused on providing information on user-writable directories only. + There is no discernible benefit in returning a path that points to a user-level, writable + directory on one operating system, but a system-level, read-only directory on another, that would + outweigh the confusion and unexpected failures such an approach would cause. + - `executable_dir` is specified to provide the path to a user-writable directory for binaries.<br/> + As such a directory only commonly exists on Linux, it returns `None` on macOS and Windows. + - `font_dir` is specified to provide the path to a user-writable directory for fonts.<br/> + As such a directory only exists on Linux and macOS, it returns `None` on Windows. + - `runtime_dir` is specified to provide the path to a directory for non-essential runtime data. + It is required that this directory is created when the user logs in, is only accessible by the + user itself, is deleted when the user logs out, and supports all filesystem features of the + operating system.<br/> + As such a directory only commonly exists on Linux, it returns `None` on macOS and Windows. + +## Features + +**If you want to compute the location of cache, config or data directories for your own application or project, +use `ProjectDirs` of the [directories-next] project instead.** + +| Function name | Value on Linux/Redox | Value on Windows | Value on macOS | +| ---------------- | ------------------------------------------------------------------------------------------------ | --------------------------------- | ------------------------------------------- | +| `home_dir` | `Some($HOME)` | `Some({FOLDERID_Profile})` | `Some($HOME)` | +| `cache_dir` | `Some($XDG_CACHE_HOME)` or `Some($HOME`/.cache`)` | `Some({FOLDERID_LocalAppData})` | `Some($HOME`/Library/Caches`)` | +| `config_dir` | `Some($XDG_CONFIG_HOME)` or `Some($HOME`/.config`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` | +| `data_dir` | `Some($XDG_DATA_HOME)` or `Some($HOME`/.local/share`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` | +| `data_local_dir` | `Some($XDG_DATA_HOME)` or `Some($HOME`/.local/share`)` | `Some({FOLDERID_LocalAppData})` | `Some($HOME`/Library/Application Support`)` | +| `executable_dir` | `Some($XDG_BIN_HOME`/../bin`)` or `Some($XDG_DATA_HOME`/../bin`)` or `Some($HOME`/.local/bin`)` | `None` | `None` | +| `runtime_dir` | `Some($XDG_RUNTIME_DIR)` or `None` | `None` | `None` | +| `audio_dir` | `Some(XDG_MUSIC_DIR)` or `None` | `Some({FOLDERID_Music})` | `Some($HOME`/Music/`)` | +| `desktop_dir` | `Some(XDG_DESKTOP_DIR)` or `None` | `Some({FOLDERID_Desktop})` | `Some($HOME`/Desktop/`)` | +| `document_dir` | `Some(XDG_DOCUMENTS_DIR)` or `None` | `Some({FOLDERID_Documents})` | `Some($HOME`/Documents/`)` | +| `download_dir` | `Some(XDG_DOWNLOAD_DIR)` or `None` | `Some({FOLDERID_Downloads})` | `Some($HOME`/Downloads/`)` | +| `font_dir` | `Some($XDG_DATA_HOME`/fonts/`)` or `Some($HOME`/.local/share/fonts/`)` | `None` | `Some($HOME`/Library/Fonts/`)` | +| `picture_dir` | `Some(XDG_PICTURES_DIR)` or `None` | `Some({FOLDERID_Pictures})` | `Some($HOME`/Pictures/`)` | +| `public_dir` | `Some(XDG_PUBLICSHARE_DIR)` or `None` | `Some({FOLDERID_Public})` | `Some($HOME`/Public/`)` | +| `template_dir` | `Some(XDG_TEMPLATES_DIR)` or `None` | `Some({FOLDERID_Templates})` | `None` | +| `video_dir` | `Some(XDG_VIDEOS_DIR)` or `None` | `Some({FOLDERID_Videos})` | `Some($HOME`/Movies/`)` | + +## Comparison + +There are other crates in the Rust ecosystem that try similar or related things. +Here is an overview of them, combined with ratings on properties that guided the design of this crate. + +Please take this table with a grain of salt: a different crate might very well be more suitable for your specific use case. + +| Library | Status | Lin | Mac | Win |Base|User|Proj|Conv| +| --------------------- | -------------- |:---:|:---:|:---:|:--:|:--:|:--:|:--:| +| `app_dirs` | Unmaintained | ✔ | ✔ | ✔ | 🞈 | ✖ | ✔ | ✖ | +| `app_dirs2` | Maintained | ✔ | ✔ | ✔ | 🞈 | ✖ | ✔ | ✖ | +| **dirs-next** | **Developed** | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | +| `directories-next` | Developed | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | +| `s_app_dir` | Unmaintained? | ✔ | ✖ | 🞈 | ✖ | ✖ | 🞈 | ✖ | +| `standard_paths` | Maintained | ✔ | ✖ | ✔ | ✔ | ✔ | ✔ | ✖ | +| `xdg` | Maintained | ✔ | ✖ | ✖ | ✔ | ✖ | ✔ | 🞈 | +| `xdg-basedir` | Unmaintained? | ✔ | ✖ | ✖ | ✔ | ✖ | ✖ | 🞈 | +| `xdg-rs` | Obsolete | ✔ | ✖ | ✖ | ✔ | ✖ | ✖ | 🞈 | + +- Lin: Linux support +- Mac: macOS support +- Win: Windows support +- Base: Supports [generic base directories](https://github.com/xdg-rs/dirs/tree/master/directories#basedirs) +- User: Supports [user directories](https://github.com/xdg-rs/dirs/tree/master/directories#userdirs) +- Proj: Supports [project-specific base directories](https://github.com/xdg-rs/dirs/tree/master/directories#projectdirs) +- Conv: Follows naming conventions of the operating system it runs on + +## Build + +It's possible to cross-compile this library if the necessary toolchains are installed with rustup. +This is helpful to ensure a change hasn't broken code on a different platform. + +The following commands will build this library on Linux, macOS and Windows: + +```console +cargo build --target=x86_64-unknown-linux-gnu +cargo build --target=x86_64-pc-windows-gnu +cargo build --target=x86_64-apple-darwin +cargo build --target=x86_64-unknown-redox +``` + +## License + +Licensed under either of + + * Apache License, Version 2.0 + ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) + * MIT license + ([LICENSE-MIT](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. + +[directories-next]: https://github.com/xdg-rs/dirs/tree/master/directories diff --git a/vendor/dirs-next/src/lib.rs b/vendor/dirs-next/src/lib.rs new file mode 100644 index 000000000..518ac60af --- /dev/null +++ b/vendor/dirs-next/src/lib.rs @@ -0,0 +1,272 @@ +//! The _dirs-next_ crate is +//! +//! - a tiny library with a minimal API (16 functions) +//! - that provides the platform-specific, user-accessible locations +//! - for finding and storing configuration, cache and other data +//! - on Linux, Redox, Windows (≥ Vista) and macOS. +//! +//! The library provides the location of these directories by leveraging the mechanisms defined by +//! +//! - the [XDG base directory](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) and the [XDG user directory](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/) specifications on Linux, +//! - the [Known Folder](https://msdn.microsoft.com/en-us/library/windows/desktop/bb776911(v=vs.85).aspx) system on Windows, and +//! - the [Standard Directories](https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW6) on macOS. + +#![deny(missing_docs)] +#![warn(rust_2018_idioms)] + +use cfg_if::cfg_if; + +use std::path::PathBuf; + +cfg_if! { + if #[cfg(target_os = "windows")] { + mod win; + use win as sys; + } else if #[cfg(any(target_os = "macos", target_os = "ios"))] { + mod mac; + use mac as sys; + } else if #[cfg(target_arch = "wasm32")] { + mod wasm; + use wasm as sys; + } else { + mod lin; + use crate::lin as sys; + } +} + +/// Returns the path to the user's home directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | -------------------- | -------------- | +/// | Linux | `$HOME` | /home/alice | +/// | macOS | `$HOME` | /Users/Alice | +/// | Windows | `{FOLDERID_Profile}` | C:\Users\Alice | +/// +/// ### Linux and macOS: +/// +/// - Use `$HOME` if it is set and not empty. +/// - If `$HOME` is not set or empty, then the function `getpwuid_r` is used to determine +/// the home directory of the current user. +/// - If `getpwuid_r` lacks an entry for the current user id or the home directory field is empty, +/// then the function returns `None`. +/// +/// ### Windows: +/// +/// This function retrieves the user profile folder using `SHGetKnownFolderPath`. +/// +/// All the examples on this page mentioning `$HOME` use this behavior. +/// +/// _Note:_ This function's behavior differs from [`std::env::home_dir`], +/// which works incorrectly on Linux, macOS and Windows. +/// +/// [`std::env::home_dir`]: https://doc.rust-lang.org/std/env/fn.home_dir.html +pub fn home_dir() -> Option<PathBuf> { + sys::home_dir() +} +/// Returns the path to the user's cache directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ----------------------------------- | ---------------------------- | +/// | Linux | `$XDG_CACHE_HOME` or `$HOME`/.cache | /home/alice/.cache | +/// | macOS | `$HOME`/Library/Caches | /Users/Alice/Library/Caches | +/// | Windows | `{FOLDERID_LocalAppData}` | C:\Users\Alice\AppData\Local | +pub fn cache_dir() -> Option<PathBuf> { + sys::cache_dir() +} +/// Returns the path to the user's config directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ------------------------------------- | -------------------------------- | +/// | Linux | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config | +/// | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support | +/// | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming | +pub fn config_dir() -> Option<PathBuf> { + sys::config_dir() +} +/// Returns the path to the user's data directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------------------------- | ---------------------------------------- | +/// | Linux | `$XDG_DATA_HOME` or `$HOME`/.local/share | /home/alice/.local/share | +/// | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support | +/// | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming | +pub fn data_dir() -> Option<PathBuf> { + sys::data_dir() +} +/// Returns the path to the user's local data directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------------------------- | ---------------------------------------- | +/// | Linux | `$XDG_DATA_HOME` or `$HOME`/.local/share | /home/alice/.local/share | +/// | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support | +/// | Windows | `{FOLDERID_LocalAppData}` | C:\Users\Alice\AppData\Local | +pub fn data_local_dir() -> Option<PathBuf> { + sys::data_local_dir() +} +/// Returns the path to the user's executable directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------------------------------------------------- | ---------------------- | +/// | Linux | `$XDG_BIN_HOME` or `$XDG_DATA_HOME`/../bin or `$HOME`/.local/bin | /home/alice/.local/bin | +/// | macOS | – | – | +/// | Windows | – | – | +pub fn executable_dir() -> Option<PathBuf> { + sys::executable_dir() +} +/// Returns the path to the user's runtime directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ------------------ | --------------- | +/// | Linux | `$XDG_RUNTIME_DIR` | /run/user/1001/ | +/// | macOS | – | – | +/// | Windows | – | – | +pub fn runtime_dir() -> Option<PathBuf> { + sys::runtime_dir() +} + +/// Returns the path to the user's audio directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ------------------ | -------------------- | +/// | Linux | `XDG_MUSIC_DIR` | /home/alice/Music | +/// | macOS | `$HOME`/Music | /Users/Alice/Music | +/// | Windows | `{FOLDERID_Music}` | C:\Users\Alice\Music | +pub fn audio_dir() -> Option<PathBuf> { + sys::audio_dir() +} +/// Returns the path to the user's desktop directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | -------------------- | ---------------------- | +/// | Linux | `XDG_DESKTOP_DIR` | /home/alice/Desktop | +/// | macOS | `$HOME`/Desktop | /Users/Alice/Desktop | +/// | Windows | `{FOLDERID_Desktop}` | C:\Users\Alice\Desktop | +pub fn desktop_dir() -> Option<PathBuf> { + sys::desktop_dir() +} +/// Returns the path to the user's document directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------- | ------------------------ | +/// | Linux | `XDG_DOCUMENTS_DIR` | /home/alice/Documents | +/// | macOS | `$HOME`/Documents | /Users/Alice/Documents | +/// | Windows | `{FOLDERID_Documents}` | C:\Users\Alice\Documents | +pub fn document_dir() -> Option<PathBuf> { + sys::document_dir() +} +/// Returns the path to the user's download directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------- | ------------------------ | +/// | Linux | `XDG_DOWNLOAD_DIR` | /home/alice/Downloads | +/// | macOS | `$HOME`/Downloads | /Users/Alice/Downloads | +/// | Windows | `{FOLDERID_Downloads}` | C:\Users\Alice\Downloads | +pub fn download_dir() -> Option<PathBuf> { + sys::download_dir() +} +/// Returns the path to the user's font directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------------------------------------- | ------------------------------ | +/// | Linux | `$XDG_DATA_HOME`/fonts or `$HOME`/.local/share/fonts | /home/alice/.local/share/fonts | +/// | macOS | `$HOME/Library/Fonts` | /Users/Alice/Library/Fonts | +/// | Windows | – | – | +pub fn font_dir() -> Option<PathBuf> { + sys::font_dir() +} +/// Returns the path to the user's picture directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | --------------------- | ----------------------- | +/// | Linux | `XDG_PICTURES_DIR` | /home/alice/Pictures | +/// | macOS | `$HOME`/Pictures | /Users/Alice/Pictures | +/// | Windows | `{FOLDERID_Pictures}` | C:\Users\Alice\Pictures | +pub fn picture_dir() -> Option<PathBuf> { + sys::picture_dir() +} +/// Returns the path to the user's public directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | --------------------- | ------------------- | +/// | Linux | `XDG_PUBLICSHARE_DIR` | /home/alice/Public | +/// | macOS | `$HOME`/Public | /Users/Alice/Public | +/// | Windows | `{FOLDERID_Public}` | C:\Users\Public | +pub fn public_dir() -> Option<PathBuf> { + sys::public_dir() +} +/// Returns the path to the user's template directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------- | ---------------------------------------------------------- | +/// | Linux | `XDG_TEMPLATES_DIR` | /home/alice/Templates | +/// | macOS | – | – | +/// | Windows | `{FOLDERID_Templates}` | C:\Users\Alice\AppData\Roaming\Microsoft\Windows\Templates | +pub fn template_dir() -> Option<PathBuf> { + sys::template_dir() +} + +/// Returns the path to the user's video directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ------------------- | --------------------- | +/// | Linux | `XDG_VIDEOS_DIR` | /home/alice/Videos | +/// | macOS | `$HOME`/Movies | /Users/Alice/Movies | +/// | Windows | `{FOLDERID_Videos}` | C:\Users\Alice\Videos | +pub fn video_dir() -> Option<PathBuf> { + sys::video_dir() +} + +#[cfg(test)] +mod tests { + #[test] + fn test_dirs() { + println!("home_dir: {:?}", crate::home_dir()); + println!("cache_dir: {:?}", crate::cache_dir()); + println!("config_dir: {:?}", crate::config_dir()); + println!("data_dir: {:?}", crate::data_dir()); + println!("data_local_dir: {:?}", crate::data_local_dir()); + println!("executable_dir: {:?}", crate::executable_dir()); + println!("runtime_dir: {:?}", crate::runtime_dir()); + println!("audio_dir: {:?}", crate::audio_dir()); + println!("home_dir: {:?}", crate::desktop_dir()); + println!("cache_dir: {:?}", crate::document_dir()); + println!("config_dir: {:?}", crate::download_dir()); + println!("font_dir: {:?}", crate::font_dir()); + println!("picture_dir: {:?}", crate::picture_dir()); + println!("public_dir: {:?}", crate::public_dir()); + println!("template_dir: {:?}", crate::template_dir()); + println!("video_dir: {:?}", crate::video_dir()); + } +} diff --git a/vendor/dirs-next/src/lin.rs b/vendor/dirs-next/src/lin.rs new file mode 100644 index 000000000..a3ca404a8 --- /dev/null +++ b/vendor/dirs-next/src/lin.rs @@ -0,0 +1,32 @@ +use std::env; +use std::path::PathBuf; + +pub fn home_dir() -> Option<PathBuf> { dirs_sys_next::home_dir() } +pub fn cache_dir() -> Option<PathBuf> { env::var_os("XDG_CACHE_HOME") .and_then(dirs_sys_next::is_absolute_path).or_else(|| home_dir().map(|h| h.join(".cache"))) } +pub fn config_dir() -> Option<PathBuf> { env::var_os("XDG_CONFIG_HOME").and_then(dirs_sys_next::is_absolute_path).or_else(|| home_dir().map(|h| h.join(".config"))) } +pub fn data_dir() -> Option<PathBuf> { env::var_os("XDG_DATA_HOME") .and_then(dirs_sys_next::is_absolute_path).or_else(|| home_dir().map(|h| h.join(".local/share"))) } +pub fn data_local_dir() -> Option<PathBuf> { data_dir() } +pub fn runtime_dir() -> Option<PathBuf> { env::var_os("XDG_RUNTIME_DIR").and_then(dirs_sys_next::is_absolute_path) } +pub fn executable_dir() -> Option<PathBuf> { + env::var_os("XDG_BIN_HOME").and_then(dirs_sys_next::is_absolute_path).or_else(|| { + data_dir().map(|mut e| { e.pop(); e.push("bin"); e }) + }) +} +pub fn audio_dir() -> Option<PathBuf> { dirs_sys_next::user_dir("MUSIC") } +pub fn desktop_dir() -> Option<PathBuf> { dirs_sys_next::user_dir("DESKTOP") } +pub fn document_dir() -> Option<PathBuf> { dirs_sys_next::user_dir("DOCUMENTS") } +pub fn download_dir() -> Option<PathBuf> { dirs_sys_next::user_dir("DOWNLOAD") } +pub fn font_dir() -> Option<PathBuf> { data_dir().map(|d| d.join("fonts")) } +pub fn picture_dir() -> Option<PathBuf> { dirs_sys_next::user_dir("PICTURES") } +pub fn public_dir() -> Option<PathBuf> { dirs_sys_next::user_dir("PUBLICSHARE") } +pub fn template_dir() -> Option<PathBuf> { dirs_sys_next::user_dir("TEMPLATES") } +pub fn video_dir() -> Option<PathBuf> { dirs_sys_next::user_dir("VIDEOS") } + +#[cfg(test)] +mod tests { + #[test] + fn test_file_user_dirs_exists() { + let user_dirs_file = crate::config_dir().unwrap().join("user-dirs.dirs"); + println!("{:?} exists: {:?}", user_dirs_file, user_dirs_file.exists()); + } +} diff --git a/vendor/dirs-next/src/mac.rs b/vendor/dirs-next/src/mac.rs new file mode 100644 index 000000000..914d96ecb --- /dev/null +++ b/vendor/dirs-next/src/mac.rs @@ -0,0 +1,18 @@ +use std::path::PathBuf; + +pub fn home_dir() -> Option<PathBuf> { dirs_sys_next::home_dir() } +pub fn cache_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Library/Caches")) } +pub fn config_dir() -> Option<PathBuf> { data_dir() } +pub fn data_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Library/Application Support")) } +pub fn data_local_dir() -> Option<PathBuf> { data_dir() } +pub fn executable_dir() -> Option<PathBuf> { None } +pub fn runtime_dir() -> Option<PathBuf> { None } +pub fn audio_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Music")) } +pub fn desktop_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Desktop")) } +pub fn document_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Documents")) } +pub fn download_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Downloads")) } +pub fn font_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Library/Fonts")) } +pub fn picture_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Pictures")) } +pub fn public_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Public")) } +pub fn template_dir() -> Option<PathBuf> { None } +pub fn video_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Movies")) } diff --git a/vendor/dirs-next/src/wasm.rs b/vendor/dirs-next/src/wasm.rs new file mode 100644 index 000000000..2ead7201b --- /dev/null +++ b/vendor/dirs-next/src/wasm.rs @@ -0,0 +1,20 @@ +// Stub definitions to make things *compile*. + +use std::path::PathBuf; + +pub fn home_dir() -> Option<PathBuf> { None } +pub fn cache_dir() -> Option<PathBuf> { None } +pub fn config_dir() -> Option<PathBuf> { None } +pub fn data_dir() -> Option<PathBuf> { None } +pub fn data_local_dir() -> Option<PathBuf> { None } +pub fn runtime_dir() -> Option<PathBuf> { None } +pub fn executable_dir() -> Option<PathBuf> { None } +pub fn audio_dir() -> Option<PathBuf> { None } +pub fn desktop_dir() -> Option<PathBuf> { None } +pub fn document_dir() -> Option<PathBuf> { None } +pub fn download_dir() -> Option<PathBuf> { None } +pub fn font_dir() -> Option<PathBuf> { None } +pub fn picture_dir() -> Option<PathBuf> { None } +pub fn public_dir() -> Option<PathBuf> { None } +pub fn template_dir() -> Option<PathBuf> { None } +pub fn video_dir() -> Option<PathBuf> { None } diff --git a/vendor/dirs-next/src/win.rs b/vendor/dirs-next/src/win.rs new file mode 100644 index 000000000..b2f8b6c2f --- /dev/null +++ b/vendor/dirs-next/src/win.rs @@ -0,0 +1,18 @@ +use std::path::PathBuf; + +pub fn home_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_profile() } +pub fn data_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_roaming_app_data() } +pub fn data_local_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_local_app_data() } +pub fn cache_dir() -> Option<PathBuf> { data_local_dir() } +pub fn config_dir() -> Option<PathBuf> { data_dir() } +pub fn executable_dir() -> Option<PathBuf> { None } +pub fn runtime_dir() -> Option<PathBuf> { None } +pub fn audio_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_music() } +pub fn desktop_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_desktop() } +pub fn document_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_documents() } +pub fn download_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_downloads() } +pub fn font_dir() -> Option<PathBuf> { None } +pub fn picture_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_pictures() } +pub fn public_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_public()} +pub fn template_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_templates() } +pub fn video_dir() -> Option<PathBuf> { dirs_sys_next::known_folder_videos() } diff --git a/vendor/dirs-sys-next/.cargo-checksum.json b/vendor/dirs-sys-next/.cargo-checksum.json new file mode 100644 index 000000000..511774523 --- /dev/null +++ b/vendor/dirs-sys-next/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"CHANGELOG.md":"6604e30611fe9cc5f307f622fd4d763c3e0284ee98355830a9d8adfe48b45734","Cargo.toml":"c175070c42d97fe11d1d684b4e47f6a3bcdfef2a1fa6afda44ef42279dbe93ab","LICENSE-APACHE":"d3174ad63e721d4c9dccb8ad4320848992d314369bc46319720b5802c9153fe9","LICENSE-MIT":"6a2e0ade09a7d5f816f11566fee2b151b32235a7fad52b41d49cce96f833c1a9","README.md":"ee16237514c143cd4e1496fb268a5bb1807d102511a54b27ec4c94f477ed9f28","src/lib.rs":"344d57bd4f20ac70ab7ef2cbeb4dc33ce443b8f4fdbddb92e846e4bf25027b62","src/xdg_user_dirs.rs":"a160d7f56fd346febcaa47cea27dc460dc89a0d4c12025673a8a322854bce207"},"package":"4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"}
\ No newline at end of file diff --git a/vendor/dirs-sys-next/CHANGELOG.md b/vendor/dirs-sys-next/CHANGELOG.md new file mode 100644 index 000000000..be802b3fd --- /dev/null +++ b/vendor/dirs-sys-next/CHANGELOG.md @@ -0,0 +1,44 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +<!-- +# Guiding Principles + +* Changelogs are for _humans_, not machines. +* There should be an entry for every single version. +* The same types of changes should be grouped. +* Versions and sections should be linkable. +* The latest version comes first. +* The release date of each version is displayed. +* Mention whether you follow Semantic Versioning. + +# Types of changes + +* `Added` for new features. +* `Changed` for changes in existing functionality. +* `Deprecated` for soon-to-be removed features. +* `Removed` for now removed features. +* `Fixed` for any bug fixes. +* `Security` in case of vulnerabilities. + --> + +<!-- next-header --> +## [Unreleased] - ReleaseDate + +## [0.1.2] - 2021-01-09 +### Changed +* Bump `redox_users` by @benesch. + +## [0.1.1] - 2020-10-13 +### Changed +* Use `default-features=false` for `redox_users` crate. This should cut out quite a few + unneeded dependencies. + +<!-- next-url --> +[Unreleased]: https://github.com/xdg-rs/dirs/compare/dirs-sys-v0.1.2...HEAD +[0.1.2]: https://github.com/xdg-rs/dirs/compare/dirs-sys-v0.1.1...dirs-sys-v0.1.2 +[0.1.1]: https://github.com/xdg-rs/dirs/releases/tag/dirs-sys-v0.1.1 diff --git a/vendor/dirs-sys-next/Cargo.toml b/vendor/dirs-sys-next/Cargo.toml new file mode 100644 index 000000000..e9d8d0ca9 --- /dev/null +++ b/vendor/dirs-sys-next/Cargo.toml @@ -0,0 +1,32 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + +[package] +edition = "2018" +name = "dirs-sys-next" +version = "0.1.2" +authors = ["The @xdg-rs members"] +include = ["/CHANGELOG.md", "/Cargo.toml", "/LICENSE-*", "/README.md", "/src"] +description = "system-level helper functions for the dirs and directories crates" +readme = "README.md" +license = "MIT OR Apache-2.0" +repository = "https://github.com/xdg-rs/dirs/tree/master/dirs-sys" +[target."cfg(target_os = \"redox\")".dependencies.redox_users] +version = "0.4.0" +default-features = false +[target."cfg(unix)".dependencies.libc] +version = "0.2" +[target."cfg(windows)".dependencies.winapi] +version = "0.3" +features = ["knownfolders", "objbase", "shlobj", "winbase", "winerror"] +[badges.maintenance] +status = "as-is" diff --git a/vendor/dirs-sys-next/LICENSE-APACHE b/vendor/dirs-sys-next/LICENSE-APACHE new file mode 100644 index 000000000..91e18a62b --- /dev/null +++ b/vendor/dirs-sys-next/LICENSE-APACHE @@ -0,0 +1,174 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. diff --git a/vendor/dirs-sys-next/LICENSE-MIT b/vendor/dirs-sys-next/LICENSE-MIT new file mode 100644 index 000000000..1452dc143 --- /dev/null +++ b/vendor/dirs-sys-next/LICENSE-MIT @@ -0,0 +1,19 @@ +Copyright (c) 2018-2019 dirs-rs contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/dirs-sys-next/README.md b/vendor/dirs-sys-next/README.md new file mode 100644 index 000000000..3c706d80f --- /dev/null +++ b/vendor/dirs-sys-next/README.md @@ -0,0 +1,65 @@ +[![crates.io](https://img.shields.io/crates/v/dirs-sys-next.svg)](https://crates.io/crates/dirs-sys-next) +[![API documentation](https://docs.rs/dirs-sys-next/badge.svg)](https://docs.rs/dirs-sys-next/) + +# `dirs-sys-next` + +**NOTE**: This crate is a fork of once-abandoned `dirs-sys` crate. + +_Do not use this library directly, use [`dirs-next`] or [`directories-next`]._ + +## Compatibility + +This crate only exists to facilitate code sharing between [`dirs-next`] +and [`directories-next`]. + +There are no compatibility guarantees whatsoever. +Functions may change or disappear without warning or any kind of deprecation period. + +## Platforms + +This library is written in Rust, and supports Linux, Redox, macOS and Windows. +Other platforms are also supported; they use the Linux conventions. + +## Minimum Rust version policy + +The minimal required version of Rust is `1.34.0`^. + +We may bump the Rust version in major and minor releases (`x`/`y` in `x.y.z`). +Changing the Rust version will be written in the CHANGELOG. + +^ Except for Redox, where the Rust version depends on the +[`redox_users`](https://crates.io/crates/redox_users) crate. + +## Build + +It's possible to cross-compile this library if the necessary toolchains are installed with rustup. +This is helpful to ensure a change has not broken compilation on a different platform. + +The following commands will build this library on Linux, macOS and Windows: + +```console +cargo build --target=x86_64-unknown-linux-gnu +cargo build --target=x86_64-pc-windows-gnu +cargo build --target=x86_64-apple-darwin +cargo build --target=x86_64-unknown-redox +``` + +## License + +Licensed under either of + + * Apache License, Version 2.0 + ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) + * MIT license + ([LICENSE-MIT](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. + +[`dirs-next`]: https://github.com/xdg-rs/dirs +[`directories-next`]: https://github.com/xdg-rs/dirs/tree/master/directories diff --git a/vendor/dirs-sys-next/src/lib.rs b/vendor/dirs-sys-next/src/lib.rs new file mode 100644 index 000000000..f76862e85 --- /dev/null +++ b/vendor/dirs-sys-next/src/lib.rs @@ -0,0 +1,198 @@ +#![warn(rust_2018_idioms)] + +use std::ffi::OsString; +use std::path::PathBuf; + +// we don't need to explicitly handle empty strings in the code above, +// because an empty string is not considered to be a absolute path here. +pub fn is_absolute_path(path: OsString) -> Option<PathBuf> { + let path = PathBuf::from(path); + if path.is_absolute() { + Some(path) + } else { + None + } +} + +#[cfg(all(unix, not(target_os = "redox")))] +mod target_unix_not_redox { + + use std::env; + use std::ffi::{CStr, OsString}; + use std::mem; + use std::os::unix::ffi::OsStringExt; + use std::path::PathBuf; + use std::ptr; + + // https://github.com/rust-lang/rust/blob/ef3e3863939217678e5f7e755c4234d224107c64/library/std/src/sys/unix/os.rs#L587 + pub fn home_dir() -> Option<PathBuf> { + return env::var_os("HOME") + .and_then(|h| if h.is_empty() { None } else { Some(h) }) + .or_else(|| unsafe { fallback() }) + .map(PathBuf::from); + + #[cfg(any(target_os = "android", target_os = "ios", target_os = "emscripten"))] + unsafe fn fallback() -> Option<OsString> { + None + } + #[cfg(not(any(target_os = "android", target_os = "ios", target_os = "emscripten")))] + unsafe fn fallback() -> Option<OsString> { + let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { + n if n < 0 => 512 as usize, + n => n as usize, + }; + let mut buf = Vec::with_capacity(amt); + let mut passwd: libc::passwd = mem::zeroed(); + let mut result = ptr::null_mut(); + match libc::getpwuid_r(libc::getuid(), &mut passwd, buf.as_mut_ptr(), buf.capacity(), &mut result) { + 0 if !result.is_null() => { + let ptr = passwd.pw_dir as *const _; + let bytes = CStr::from_ptr(ptr).to_bytes(); + if bytes.is_empty() { + None + } else { + Some(OsStringExt::from_vec(bytes.to_vec())) + } + } + _ => None, + } + } + } +} + +#[cfg(all(unix, not(target_os = "redox")))] +pub use self::target_unix_not_redox::home_dir; + +#[cfg(target_os = "redox")] +mod target_redox { + + use std::path::PathBuf; + + use redox_users::{All, AllUsers, Config}; + + pub fn home_dir() -> Option<PathBuf> { + let current_uid = redox_users::get_uid().ok()?; + let users = AllUsers::basic(Config::default()).ok()?; + let user = users.get_by_id(current_uid)?; + + Some(PathBuf::from(user.home.clone())) + } +} + +#[cfg(target_os = "redox")] +pub use self::target_redox::home_dir; + +#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))] +mod xdg_user_dirs; + +#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))] +mod target_unix_not_mac { + + use std::collections::HashMap; + use std::env; + use std::path::{Path, PathBuf}; + + use super::xdg_user_dirs; + use super::{home_dir, is_absolute_path}; + + fn user_dir_file(home_dir: &Path) -> PathBuf { + env::var_os("XDG_CONFIG_HOME") + .and_then(is_absolute_path) + .unwrap_or_else(|| home_dir.join(".config")) + .join("user-dirs.dirs") + } + + // this could be optimized further to not create a map and instead retrieve the requested path only + pub fn user_dir(user_dir_name: &str) -> Option<PathBuf> { + if let Some(home_dir) = home_dir() { + xdg_user_dirs::single(&home_dir, &user_dir_file(&home_dir), user_dir_name).remove(user_dir_name) + } else { + None + } + } + + pub fn user_dirs(home_dir_path: &Path) -> HashMap<String, PathBuf> { + xdg_user_dirs::all(home_dir_path, &user_dir_file(home_dir_path)) + } +} + +#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))] +pub use self::target_unix_not_mac::{user_dir, user_dirs}; + +#[cfg(target_os = "windows")] +mod target_windows { + + use std::ffi::OsString; + use std::os::windows::ffi::OsStringExt; + use std::path::PathBuf; + use std::ptr; + use std::slice; + + use winapi::shared::winerror; + use winapi::um::{combaseapi, knownfolders, shlobj, shtypes, winbase, winnt}; + + pub fn known_folder(folder_id: shtypes::REFKNOWNFOLDERID) -> Option<PathBuf> { + unsafe { + let mut path_ptr: winnt::PWSTR = ptr::null_mut(); + let result = shlobj::SHGetKnownFolderPath(folder_id, 0, ptr::null_mut(), &mut path_ptr); + if result == winerror::S_OK { + let len = winbase::lstrlenW(path_ptr) as usize; + let path = slice::from_raw_parts(path_ptr, len); + let ostr: OsString = OsStringExt::from_wide(path); + combaseapi::CoTaskMemFree(path_ptr as *mut winapi::ctypes::c_void); + Some(PathBuf::from(ostr)) + } else { + None + } + } + } + + pub fn known_folder_profile() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Profile) + } + + pub fn known_folder_roaming_app_data() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_RoamingAppData) + } + + pub fn known_folder_local_app_data() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_LocalAppData) + } + + pub fn known_folder_music() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Music) + } + + pub fn known_folder_desktop() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Desktop) + } + + pub fn known_folder_documents() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Documents) + } + + pub fn known_folder_downloads() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Downloads) + } + + pub fn known_folder_pictures() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Pictures) + } + + pub fn known_folder_public() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Public) + } + pub fn known_folder_templates() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Templates) + } + pub fn known_folder_videos() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Videos) + } +} + +#[cfg(target_os = "windows")] +pub use self::target_windows::{ + known_folder, known_folder_desktop, known_folder_documents, known_folder_downloads, known_folder_local_app_data, + known_folder_music, known_folder_pictures, known_folder_profile, known_folder_public, + known_folder_roaming_app_data, known_folder_templates, known_folder_videos, +}; diff --git a/vendor/dirs-sys-next/src/xdg_user_dirs.rs b/vendor/dirs-sys-next/src/xdg_user_dirs.rs new file mode 100644 index 000000000..4fabc81d9 --- /dev/null +++ b/vendor/dirs-sys-next/src/xdg_user_dirs.rs @@ -0,0 +1,248 @@ +use std::collections::HashMap; +use std::ffi::OsString; +use std::fs; +use std::io::{self, Read}; +use std::os::unix::ffi::OsStringExt; +use std::path::{Path, PathBuf}; +use std::str; + +/// Returns all XDG user directories obtained from $(XDG_CONFIG_HOME)/user-dirs.dirs. +pub fn all(home_dir_path: &Path, user_dir_file_path: &Path) -> HashMap<String, PathBuf> { + let bytes = read_all(user_dir_file_path).unwrap_or_default(); + parse_user_dirs(home_dir_path, None, &bytes) +} + +/// Returns a single XDG user directory obtained from $(XDG_CONFIG_HOME)/user-dirs.dirs. +pub fn single(home_dir_path: &Path, user_dir_file_path: &Path, user_dir_name: &str) -> HashMap<String, PathBuf> { + let bytes = read_all(user_dir_file_path).unwrap_or_default(); + parse_user_dirs(home_dir_path, Some(user_dir_name), &bytes) +} + +fn parse_user_dirs(home_dir: &Path, user_dir: Option<&str>, bytes: &[u8]) -> HashMap<String, PathBuf> { + let mut user_dirs = HashMap::new(); + + for line in bytes.split(|b| *b == b'\n') { + let mut single_dir_found = false; + let (key, value) = match split_once(line, b'=') { + Some(kv) => kv, + None => continue, + }; + + let key = trim_blank(key); + let key = if key.starts_with(b"XDG_") && key.ends_with(b"_DIR") { + match str::from_utf8(&key[4..key.len() - 4]) { + Ok(key) => { + if user_dir.is_some() && option_contains(user_dir, key) { + single_dir_found = true; + key + } else if user_dir.is_none() { + key + } else { + continue; + } + } + Err(_) => continue, + } + } else { + continue; + }; + + // xdg-user-dirs-update uses double quotes and we don't support anything else. + let value = trim_blank(value); + let mut value = + if value.starts_with(b"\"") && value.ends_with(b"\"") { &value[1..value.len() - 1] } else { continue }; + + // Path should be either relative to the home directory or absolute. + let is_relative = if value == b"$HOME/" { + // "Note: To disable a directory, point it to the homedir." + // Source: https://www.freedesktop.org/wiki/Software/xdg-user-dirs/ + // Additionally directory is reassigned to homedir when removed. + continue; + } else if value.starts_with(b"$HOME/") { + value = &value[b"$HOME/".len()..]; + true + } else if value.starts_with(b"/") { + false + } else { + continue; + }; + + let value = OsString::from_vec(shell_unescape(value)); + + let path = if is_relative { + let mut path = PathBuf::from(&home_dir); + path.push(value); + path + } else { + PathBuf::from(value) + }; + + user_dirs.insert(key.to_owned(), path); + if single_dir_found { + break; + } + } + + user_dirs +} + +/// Reads the entire contents of a file into a byte vector. +fn read_all(path: &Path) -> io::Result<Vec<u8>> { + let mut file = fs::File::open(path)?; + let mut bytes = Vec::with_capacity(1024); + file.read_to_end(&mut bytes)?; + Ok(bytes) +} + +/// Returns bytes before and after first occurrence of separator. +fn split_once(bytes: &[u8], separator: u8) -> Option<(&[u8], &[u8])> { + bytes.iter().position(|b| *b == separator).map(|i| (&bytes[..i], &bytes[i + 1..])) +} + +/// Returns a slice with leading and trailing <blank> characters removed. +fn trim_blank(bytes: &[u8]) -> &[u8] { + // Trim leading <blank> characters. + let i = bytes.iter().cloned().take_while(|b| *b == b' ' || *b == b'\t').count(); + let bytes = &bytes[i..]; + + // Trim trailing <blank> characters. + let i = bytes.iter().cloned().rev().take_while(|b| *b == b' ' || *b == b'\t').count(); + &bytes[..bytes.len() - i] +} + +/// Unescape bytes escaped with POSIX shell double-quotes rules (as used by xdg-user-dirs-update). +fn shell_unescape(escaped: &[u8]) -> Vec<u8> { + // We assume that byte string was created by xdg-user-dirs-update which + // escapes all characters that might potentially have special meaning, + // so there is no need to check if backslash is actually followed by + // $ ` " \ or a <newline>. + + let mut unescaped: Vec<u8> = Vec::with_capacity(escaped.len()); + let mut i = escaped.iter().cloned(); + + while let Some(b) = i.next() { + if b == b'\\' { + if let Some(b) = i.next() { + unescaped.push(b); + } + } else { + unescaped.push(b); + } + } + + unescaped +} + +fn option_contains<T: PartialEq>(option: Option<T>, value: T) -> bool { + match option { + Some(val) => val == value, + None => false, + } +} + +#[cfg(test)] +mod tests { + use super::{parse_user_dirs, shell_unescape, split_once, trim_blank}; + use std::collections::HashMap; + use std::path::{Path, PathBuf}; + + #[test] + fn test_trim_blank() { + assert_eq!(b"x", trim_blank(b"x")); + assert_eq!(b"", trim_blank(b" \t ")); + assert_eq!(b"hello there", trim_blank(b" \t hello there \t ")); + assert_eq!(b"\r\n", trim_blank(b"\r\n")); + } + + #[test] + fn test_split_once() { + assert_eq!(None, split_once(b"a b c", b'=')); + assert_eq!(Some((b"before".as_ref(), b"after".as_ref())), split_once(b"before=after", b'=')); + } + + #[test] + fn test_shell_unescape() { + assert_eq!(b"abc", shell_unescape(b"abc").as_slice()); + assert_eq!(b"x\\y$z`", shell_unescape(b"x\\\\y\\$z\\`").as_slice()); + } + + #[test] + fn test_parse_empty() { + assert_eq!(HashMap::new(), parse_user_dirs(Path::new("/root/"), None, b"")); + assert_eq!(HashMap::new(), parse_user_dirs(Path::new("/root/"), Some("MUSIC"), b"")); + } + + #[test] + fn test_absolute_path_is_accepted() { + let mut dirs = HashMap::new(); + dirs.insert("MUSIC".to_owned(), PathBuf::from("/media/music")); + let bytes = br#"XDG_MUSIC_DIR="/media/music""#; + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), None, bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), Some("MUSIC"), bytes)); + } + + #[test] + fn test_relative_path_is_rejected() { + let dirs = HashMap::new(); + let bytes = br#"XDG_MUSIC_DIR="music""#; + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), None, bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), Some("MUSIC"), bytes)); + } + + #[test] + fn test_relative_to_home() { + let mut dirs = HashMap::new(); + dirs.insert("MUSIC".to_owned(), PathBuf::from("/home/john/Music")); + let bytes = br#"XDG_MUSIC_DIR="$HOME/Music""#; + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), None, bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), Some("MUSIC"), bytes)); + } + + #[test] + fn test_disabled_directory() { + let dirs = HashMap::new(); + let bytes = br#"XDG_MUSIC_DIR="$HOME/""#; + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), None, bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), Some("MUSIC"), bytes)); + } + + #[test] + fn test_parse_user_dirs() { + let mut dirs: HashMap<String, PathBuf> = HashMap::new(); + dirs.insert("DESKTOP".to_string(), PathBuf::from("/home/bob/Desktop")); + dirs.insert("DOWNLOAD".to_string(), PathBuf::from("/home/bob/Downloads")); + dirs.insert("PICTURES".to_string(), PathBuf::from("/home/eve/pics")); + + let bytes = br#" +# This file is written by xdg-user-dirs-update +# If you want to change or add directories, just edit the line you're +# interested in. All local changes will be retained on the next run. +# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped +# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an +# absolute path. No other format is supported. +XDG_DESKTOP_DIR="$HOME/Desktop" +XDG_DOWNLOAD_DIR="$HOME/Downloads" +XDG_TEMPLATES_DIR="" +XDG_PUBLICSHARE_DIR="$HOME" +XDG_DOCUMENTS_DIR="$HOME/" +XDG_PICTURES_DIR="/home/eve/pics" +XDG_VIDEOS_DIR="$HOxyzME/Videos" +"#; + + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), None, bytes)); + + let mut dirs: HashMap<String, PathBuf> = HashMap::new(); + dirs.insert("DESKTOP".to_string(), PathBuf::from("/home/bob/Desktop")); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("DESKTOP"), bytes)); + + let mut dirs: HashMap<String, PathBuf> = HashMap::new(); + dirs.insert("PICTURES".to_string(), PathBuf::from("/home/eve/pics")); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("PICTURES"), bytes)); + + let dirs: HashMap<String, PathBuf> = HashMap::new(); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("TEMPLATES"), bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("PUBLICSHARE"), bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("DOCUMENTS"), bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("VIDEOS"), bytes)); + } +} diff --git a/vendor/dirs-sys/.cargo-checksum.json b/vendor/dirs-sys/.cargo-checksum.json new file mode 100644 index 000000000..d095c8ac5 --- /dev/null +++ b/vendor/dirs-sys/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"141e80efbaefa9322513f4900a2ac4c5209b135bb36bf7ca347e3deebc75965f","LICENSE-APACHE":"d3174ad63e721d4c9dccb8ad4320848992d314369bc46319720b5802c9153fe9","LICENSE-MIT":"6a2e0ade09a7d5f816f11566fee2b151b32235a7fad52b41d49cce96f833c1a9","README.md":"1c818a4ea3bf85aaafe27421528a285db92c1f20ae9651c669379cb603495f37","src/lib.rs":"5c1aff249eb1f6abd52785f58318c1b0641ca810c15ce349e9c3797d86b1c8c5","src/xdg_user_dirs.rs":"225ae21a97b839330a8c3bc8e0a0b48e40580cbae25bfc47581dff724bb0ebec"},"package":"03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780"}
\ No newline at end of file diff --git a/vendor/dirs-sys/Cargo.toml b/vendor/dirs-sys/Cargo.toml new file mode 100644 index 000000000..6c4100798 --- /dev/null +++ b/vendor/dirs-sys/Cargo.toml @@ -0,0 +1,28 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + +[package] +name = "dirs-sys" +version = "0.3.6" +authors = ["Simon Ochsenreither <simon@ochsenreither.de>"] +description = "System-level helper functions for the dirs and directories crates." +readme = "README.md" +license = "MIT OR Apache-2.0" +repository = "https://github.com/dirs-dev/dirs-sys-rs" +[target."cfg(target_os = \"redox\")".dependencies.redox_users] +version = "0.4" +default-features = false +[target."cfg(unix)".dependencies.libc] +version = "0.2" +[target."cfg(windows)".dependencies.winapi] +version = "0.3" +features = ["knownfolders", "objbase", "shlobj", "winbase", "winerror"] diff --git a/vendor/dirs-sys/LICENSE-APACHE b/vendor/dirs-sys/LICENSE-APACHE new file mode 100644 index 000000000..91e18a62b --- /dev/null +++ b/vendor/dirs-sys/LICENSE-APACHE @@ -0,0 +1,174 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. diff --git a/vendor/dirs-sys/LICENSE-MIT b/vendor/dirs-sys/LICENSE-MIT new file mode 100644 index 000000000..1452dc143 --- /dev/null +++ b/vendor/dirs-sys/LICENSE-MIT @@ -0,0 +1,19 @@ +Copyright (c) 2018-2019 dirs-rs contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/dirs-sys/README.md b/vendor/dirs-sys/README.md new file mode 100644 index 000000000..c1234148a --- /dev/null +++ b/vendor/dirs-sys/README.md @@ -0,0 +1,61 @@ +[![crates.io](https://img.shields.io/crates/v/dirs-sys.svg)](https://crates.io/crates/dirs-sys) +[![API documentation](https://docs.rs/dirs-sys/badge.svg)](https://docs.rs/dirs-sys/) +![actively developed](https://img.shields.io/badge/maintenance-as--is-yellow.svg) +[![TravisCI status](https://img.shields.io/travis/dirs-dev/dirs-sys-rs/master.svg?label=Linux/macOS%20build)](https://travis-ci.org/dirs-dev/dirs-sys-rs) +[![AppVeyor status](https://img.shields.io/appveyor/ci/soc/dirs-sys-rs/master.svg?label=Windows%20build)](https://ci.appveyor.com/project/soc/dirs-sys-rs/branch/master) +![License: MIT/Apache-2.0](https://img.shields.io/badge/license-MIT%2FApache--2.0-orange.svg) + +# `dirs-sys` + +System-level helper functions for the [`dirs`](https://github.com/dirs-dev/dirs-rs) +and [`directories`](https://github.com/dirs-dev/directories-rs) crates. + +_Do not use this library directly, use [`dirs`](https://github.com/dirs-dev/dirs-rs) +or [`directories`](https://github.com/dirs-dev/directories-rs)._ + +## Compatibility + +This crate only exists to facilitate code sharing between [`dirs`](https://github.com/dirs-dev/dirs-rs) +and [`directories`](https://github.com/dirs-dev/directories-rs). + +There are no compatibility guarantees whatsoever. +Functions may change or disappear without warning or any kind of deprecation period. + +## Platforms + +This library is written in Rust, and supports Linux, Redox, macOS and Windows. +Other platforms are also supported; they use the Linux conventions. + +The minimal required version of Rust is 1.13 except for Redox, where the minimum Rust version +depends on the [`redox_users`](https://crates.io/crates/redox_users) crate. + +## Build + +It's possible to cross-compile this library if the necessary toolchains are installed with rustup. +This is helpful to ensure a change has not broken compilation on a different platform. + +The following commands will build this library on Linux, macOS and Windows: + +``` +cargo build --target=x86_64-unknown-linux-gnu +cargo build --target=x86_64-pc-windows-gnu +cargo build --target=x86_64-apple-darwin +cargo build --target=x86_64-unknown-redox +``` + +## License + +Licensed under either of + + * Apache License, Version 2.0 + ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) + * MIT license + ([LICENSE-MIT](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. diff --git a/vendor/dirs-sys/src/lib.rs b/vendor/dirs-sys/src/lib.rs new file mode 100644 index 000000000..cd5bb4794 --- /dev/null +++ b/vendor/dirs-sys/src/lib.rs @@ -0,0 +1,216 @@ +use std::ffi::OsString; +use std::path::PathBuf; + +// we don't need to explicitly handle empty strings in the code above, +// because an empty string is not considered to be a absolute path here. +pub fn is_absolute_path(path: OsString) -> Option<PathBuf> { + let path = PathBuf::from(path); + if path.is_absolute() { + Some(path) + } else { + None + } +} + +#[cfg(all(unix, not(target_os = "redox")))] +extern crate libc; + +#[cfg(all(unix, not(target_os = "redox")))] +mod target_unix_not_redox { + +use std::env; +use std::ffi::{CStr, OsString}; +use std::mem; +use std::os::unix::ffi::OsStringExt; +use std::path::PathBuf; +use std::ptr; + +use super::libc; + +// https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/os.rs#L498 +pub fn home_dir() -> Option<PathBuf> { + return env::var_os("HOME") + .and_then(|h| if h.is_empty() { None } else { Some(h) }) + .or_else(|| unsafe { fallback() }) + .map(PathBuf::from); + + #[cfg(any(target_os = "android", target_os = "ios", target_os = "emscripten"))] + unsafe fn fallback() -> Option<OsString> { + None + } + #[cfg(not(any(target_os = "android", target_os = "ios", target_os = "emscripten")))] + unsafe fn fallback() -> Option<OsString> { + let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { + n if n < 0 => 512 as usize, + n => n as usize, + }; + let mut buf = Vec::with_capacity(amt); + let mut passwd: libc::passwd = mem::zeroed(); + let mut result = ptr::null_mut(); + match libc::getpwuid_r( + libc::getuid(), + &mut passwd, + buf.as_mut_ptr(), + buf.capacity(), + &mut result, + ) { + 0 if !result.is_null() => { + let ptr = passwd.pw_dir as *const _; + let bytes = CStr::from_ptr(ptr).to_bytes(); + if bytes.is_empty() { + None + } else { + Some(OsStringExt::from_vec(bytes.to_vec())) + } + } + _ => None, + } + } +} + +} + +#[cfg(all(unix, not(target_os = "redox")))] +pub use self::target_unix_not_redox::home_dir; + +#[cfg(target_os = "redox")] +extern crate redox_users; + +#[cfg(target_os = "redox")] +mod target_redox { + +use std::path::PathBuf; + +use super::redox_users::{All, AllUsers, Config}; + +pub fn home_dir() -> Option<PathBuf> { + let current_uid = redox_users::get_uid().ok()?; + let users = AllUsers::new(Config::default()).ok()?; + let user = users.get_by_id(current_uid)?; + + Some(PathBuf::from(user.home.clone())) +} + +} + +#[cfg(target_os = "redox")] +pub use self::target_redox::home_dir; + +#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))] +mod xdg_user_dirs; + +#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))] +mod target_unix_not_mac { + +use std::collections::HashMap; +use std::env; +use std::path::{Path, PathBuf}; + +use super::{home_dir, is_absolute_path}; +use super::xdg_user_dirs; + +fn user_dir_file(home_dir: &Path) -> PathBuf { + env::var_os("XDG_CONFIG_HOME").and_then(is_absolute_path).unwrap_or_else(|| home_dir.join(".config")).join("user-dirs.dirs") +} + +// this could be optimized further to not create a map and instead retrieve the requested path only +pub fn user_dir(user_dir_name: &str) -> Option<PathBuf> { + if let Some(home_dir) = home_dir() { + xdg_user_dirs::single(&home_dir, &user_dir_file(&home_dir), user_dir_name).remove(user_dir_name) + } else { + None + } +} + +pub fn user_dirs(home_dir_path: &Path) -> HashMap<String, PathBuf> { + xdg_user_dirs::all(home_dir_path, &user_dir_file(home_dir_path)) +} + +} + +#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))] +pub use self::target_unix_not_mac::{user_dir, user_dirs}; + +#[cfg(target_os = "windows")] +extern crate winapi; + +#[cfg(target_os = "windows")] +mod target_windows { + +use std::ffi::OsString; +use std::os::windows::ffi::OsStringExt; +use std::path::PathBuf; +use std::ptr; +use std::slice; + +use super::winapi; +use super::winapi::shared::winerror; +use super::winapi::um::{combaseapi, knownfolders, shlobj, shtypes, winbase, winnt}; + +pub fn known_folder(folder_id: shtypes::REFKNOWNFOLDERID) -> Option<PathBuf> { + unsafe { + let mut path_ptr: winnt::PWSTR = ptr::null_mut(); + let result = shlobj::SHGetKnownFolderPath(folder_id, 0, ptr::null_mut(), &mut path_ptr); + if result == winerror::S_OK { + let len = winbase::lstrlenW(path_ptr) as usize; + let path = slice::from_raw_parts(path_ptr, len); + let ostr: OsString = OsStringExt::from_wide(path); + combaseapi::CoTaskMemFree(path_ptr as *mut winapi::ctypes::c_void); + Some(PathBuf::from(ostr)) + } else { + combaseapi::CoTaskMemFree(path_ptr as *mut winapi::ctypes::c_void); + None + } + } +} + +pub fn known_folder_profile() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Profile) +} + +pub fn known_folder_roaming_app_data() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_RoamingAppData) +} + +pub fn known_folder_local_app_data() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_LocalAppData) +} + +pub fn known_folder_music() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Music) +} + +pub fn known_folder_desktop() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Desktop) +} + +pub fn known_folder_documents() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Documents) +} + +pub fn known_folder_downloads() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Downloads) +} + +pub fn known_folder_pictures() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Pictures) +} + +pub fn known_folder_public() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Public) +} +pub fn known_folder_templates() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Templates) +} +pub fn known_folder_videos() -> Option<PathBuf> { + known_folder(&knownfolders::FOLDERID_Videos) +} + +} + +#[cfg(target_os = "windows")] +pub use self::target_windows::{ + known_folder, known_folder_profile, known_folder_roaming_app_data, known_folder_local_app_data, + known_folder_music, known_folder_desktop, known_folder_documents, known_folder_downloads, + known_folder_pictures, known_folder_public, known_folder_templates, known_folder_videos +}; diff --git a/vendor/dirs-sys/src/xdg_user_dirs.rs b/vendor/dirs-sys/src/xdg_user_dirs.rs new file mode 100644 index 000000000..de7e9e9d2 --- /dev/null +++ b/vendor/dirs-sys/src/xdg_user_dirs.rs @@ -0,0 +1,252 @@ +use std::collections::HashMap; +use std::ffi::OsString; +use std::fs; +use std::io::{self, Read}; +use std::os::unix::ffi::OsStringExt; +use std::path::{Path, PathBuf}; +use std::str; + +/// Returns all XDG user directories obtained from $(XDG_CONFIG_HOME)/user-dirs.dirs. +pub fn all(home_dir_path: &Path, user_dir_file_path: &Path) -> HashMap<String, PathBuf> { + let bytes = read_all(user_dir_file_path).unwrap_or(Vec::new()); + parse_user_dirs(home_dir_path, None, &bytes) +} + +/// Returns a single XDG user directory obtained from $(XDG_CONFIG_HOME)/user-dirs.dirs. +pub fn single(home_dir_path: &Path, user_dir_file_path: &Path, user_dir_name: &str) -> HashMap<String, PathBuf> { + let bytes = read_all(user_dir_file_path).unwrap_or(Vec::new()); + parse_user_dirs(home_dir_path, Some(user_dir_name), &bytes) +} + +fn parse_user_dirs(home_dir: &Path, user_dir: Option<&str>, bytes: &[u8]) -> HashMap<String, PathBuf> { + let mut user_dirs = HashMap::new(); + + for line in bytes.split(|b| *b == b'\n') { + let mut single_dir_found = false; + let (key, value) = match split_once(line, b'=') { + Some(kv) => kv, + None => continue, + }; + + let key = trim_blank(key); + let key = if key.starts_with(b"XDG_") && key.ends_with(b"_DIR") { + match str::from_utf8(&key[4..key.len()-4]) { + Ok(key) => + if user_dir.is_some() && option_contains(user_dir, key) { + single_dir_found = true; + key + } else if user_dir.is_none() { + key + } else { + continue + }, + Err(_) => continue, + } + } else { + continue + }; + + // xdg-user-dirs-update uses double quotes and we don't support anything else. + let value = trim_blank(value); + let mut value = if value.starts_with(b"\"") && value.ends_with(b"\"") { + &value[1..value.len()-1] + } else { + continue + }; + + // Path should be either relative to the home directory or absolute. + let is_relative = if value == b"$HOME/" { + // "Note: To disable a directory, point it to the homedir." + // Source: https://www.freedesktop.org/wiki/Software/xdg-user-dirs/ + // Additionally directory is reassigned to homedir when removed. + continue + } else if value.starts_with(b"$HOME/") { + value = &value[b"$HOME/".len()..]; + true + } else if value.starts_with(b"/") { + false + } else { + continue + }; + + let value = OsString::from_vec(shell_unescape(value)); + + let path = if is_relative { + let mut path = PathBuf::from(&home_dir); + path.push(value); + path + } else { + PathBuf::from(value) + }; + + user_dirs.insert(key.to_owned(), path); + if single_dir_found { + break; + } + } + + user_dirs +} + +/// Reads the entire contents of a file into a byte vector. +fn read_all(path: &Path) -> io::Result<Vec<u8>> { + let mut file = fs::File::open(path)?; + let mut bytes = Vec::with_capacity(1024); + file.read_to_end(&mut bytes)?; + Ok(bytes) +} + +/// Returns bytes before and after first occurrence of separator. +fn split_once(bytes: &[u8], separator: u8) -> Option<(&[u8], &[u8])> { + bytes.iter().position(|b| *b == separator).map(|i| { + (&bytes[..i], &bytes[i+1..]) + }) +} + +/// Returns a slice with leading and trailing <blank> characters removed. +fn trim_blank(bytes: &[u8]) -> &[u8] { + // Trim leading <blank> characters. + let i = bytes.iter().cloned().take_while(|b| *b == b' ' || *b == b'\t').count(); + let bytes = &bytes[i..]; + + // Trim trailing <blank> characters. + let i = bytes.iter().cloned().rev().take_while(|b| *b == b' ' || *b == b'\t').count(); + &bytes[..bytes.len()-i] +} + +/// Unescape bytes escaped with POSIX shell double-quotes rules (as used by xdg-user-dirs-update). +fn shell_unescape(escaped: &[u8]) -> Vec<u8> { + // We assume that byte string was created by xdg-user-dirs-update which + // escapes all characters that might potentially have special meaning, + // so there is no need to check if backslash is actually followed by + // $ ` " \ or a <newline>. + + let mut unescaped: Vec<u8> = Vec::with_capacity(escaped.len()); + let mut i = escaped.iter().cloned(); + + while let Some(b) = i.next() { + if b == b'\\' { + if let Some(b) = i.next() { + unescaped.push(b); + } + } else { + unescaped.push(b); + } + } + + unescaped +} + +fn option_contains<T : PartialEq>(option: Option<T>, value: T) -> bool { + match option { + Some(val) => val == value, + None => false + } +} + +#[cfg(test)] +mod tests { + use std::collections::HashMap; + use std::path::{Path, PathBuf}; + use super::{trim_blank, shell_unescape, split_once, parse_user_dirs}; + + #[test] + fn test_trim_blank() { + assert_eq!(b"x", trim_blank(b"x")); + assert_eq!(b"", trim_blank(b" \t ")); + assert_eq!(b"hello there", trim_blank(b" \t hello there \t ")); + assert_eq!(b"\r\n", trim_blank(b"\r\n")); + } + + #[test] + fn test_split_once() { + assert_eq!(None, split_once(b"a b c", b'=')); + assert_eq!(Some((b"before".as_ref(), b"after".as_ref())), split_once(b"before=after", b'=')); + } + + #[test] + fn test_shell_unescape() { + assert_eq!(b"abc", shell_unescape(b"abc").as_slice()); + assert_eq!(b"x\\y$z`", shell_unescape(b"x\\\\y\\$z\\`").as_slice()); + } + + #[test] + fn test_parse_empty() { + assert_eq!(HashMap::new(), parse_user_dirs(Path::new("/root/"), None, b"")); + assert_eq!(HashMap::new(), parse_user_dirs(Path::new("/root/"), Some("MUSIC"), b"")); + } + + #[test] + fn test_absolute_path_is_accepted() { + let mut dirs = HashMap::new(); + dirs.insert("MUSIC".to_owned(), PathBuf::from("/media/music")); + let bytes = br#"XDG_MUSIC_DIR="/media/music""#; + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), None, bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), Some("MUSIC"), bytes)); + } + + #[test] + fn test_relative_path_is_rejected() { + let dirs = HashMap::new(); + let bytes = br#"XDG_MUSIC_DIR="music""#; + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), None, bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), Some("MUSIC"), bytes)); + } + + #[test] + fn test_relative_to_home() { + let mut dirs = HashMap::new(); + dirs.insert("MUSIC".to_owned(), PathBuf::from("/home/john/Music")); + let bytes = br#"XDG_MUSIC_DIR="$HOME/Music""#; + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), None, bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), Some("MUSIC"), bytes)); + } + + #[test] + fn test_disabled_directory() { + let dirs = HashMap::new(); + let bytes = br#"XDG_MUSIC_DIR="$HOME/""#; + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), None, bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/john"), Some("MUSIC"), bytes)); + } + + #[test] + fn test_parse_user_dirs() { + let mut dirs: HashMap<String, PathBuf> = HashMap::new(); + dirs.insert("DESKTOP".to_string(), PathBuf::from("/home/bob/Desktop")); + dirs.insert("DOWNLOAD".to_string(), PathBuf::from("/home/bob/Downloads")); + dirs.insert("PICTURES".to_string(), PathBuf::from("/home/eve/pics")); + + let bytes = br#" +# This file is written by xdg-user-dirs-update +# If you want to change or add directories, just edit the line you're +# interested in. All local changes will be retained on the next run. +# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped +# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an +# absolute path. No other format is supported. +XDG_DESKTOP_DIR="$HOME/Desktop" +XDG_DOWNLOAD_DIR="$HOME/Downloads" +XDG_TEMPLATES_DIR="" +XDG_PUBLICSHARE_DIR="$HOME" +XDG_DOCUMENTS_DIR="$HOME/" +XDG_PICTURES_DIR="/home/eve/pics" +XDG_VIDEOS_DIR="$HOxyzME/Videos" +"#; + + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), None, bytes)); + + let mut dirs: HashMap<String, PathBuf> = HashMap::new(); + dirs.insert("DESKTOP".to_string(), PathBuf::from("/home/bob/Desktop")); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("DESKTOP"), bytes)); + + let mut dirs: HashMap<String, PathBuf> = HashMap::new(); + dirs.insert("PICTURES".to_string(), PathBuf::from("/home/eve/pics")); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("PICTURES"), bytes)); + + let dirs: HashMap<String, PathBuf> = HashMap::new(); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("TEMPLATES"), bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("PUBLICSHARE"), bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("DOCUMENTS"), bytes)); + assert_eq!(dirs, parse_user_dirs(Path::new("/home/bob"), Some("VIDEOS"), bytes)); + } +} diff --git a/vendor/dirs/.cargo-checksum.json b/vendor/dirs/.cargo-checksum.json new file mode 100644 index 000000000..c2d4c80af --- /dev/null +++ b/vendor/dirs/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"5bb02a35a3ac857c60ab16972decfea610ec3bed296a41d0235dc663a64495f6","LICENSE-APACHE":"d3174ad63e721d4c9dccb8ad4320848992d314369bc46319720b5802c9153fe9","LICENSE-MIT":"6a2e0ade09a7d5f816f11566fee2b151b32235a7fad52b41d49cce96f833c1a9","README.md":"84fdbe7a22dd22574249330ce2146d4237391989e66377f087f66eca6313c032","src/lib.rs":"d0c92741b50d0b793591e9731a71053b88a8a6e8d0e808f2d3afb127eab04b6f","src/lin.rs":"4b556c3f8a02571cd62756ff542172e5c438395c600582abb76be049c3d570c8","src/mac.rs":"4ee036a83508eae7c51ae9ccdb8165603df96a580501c11c9c2d98cd672e7940","src/wasm.rs":"6b7edb4a708fef10d95ac32aa4f7a81d465794edeb805dc7c2168e351daaca2c","src/win.rs":"8296c5f68e85ba456b48a5153cffded163d12e431a0929daa873ae09e5ce3d10"},"package":"ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"}
\ No newline at end of file diff --git a/vendor/dirs/Cargo.toml b/vendor/dirs/Cargo.toml new file mode 100644 index 000000000..b6151d10b --- /dev/null +++ b/vendor/dirs/Cargo.toml @@ -0,0 +1,22 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +name = "dirs" +version = "4.0.0" +authors = ["Simon Ochsenreither <simon@ochsenreither.de>"] +description = "A tiny low-level library that provides platform-specific standard locations of directories for config, cache and other data on Linux, Windows, macOS and Redox by leveraging the mechanisms defined by the XDG base/user directory specifications on Linux, the Known Folder API on Windows, and the Standard Directory guidelines on macOS." +readme = "README.md" +keywords = ["xdg", "basedir", "app_dirs", "path", "folder"] +license = "MIT OR Apache-2.0" +repository = "https://github.com/soc/dirs-rs" +[dependencies.dirs-sys] +version = "0.3.6" diff --git a/vendor/dirs/LICENSE-APACHE b/vendor/dirs/LICENSE-APACHE new file mode 100644 index 000000000..91e18a62b --- /dev/null +++ b/vendor/dirs/LICENSE-APACHE @@ -0,0 +1,174 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. diff --git a/vendor/dirs/LICENSE-MIT b/vendor/dirs/LICENSE-MIT new file mode 100644 index 000000000..1452dc143 --- /dev/null +++ b/vendor/dirs/LICENSE-MIT @@ -0,0 +1,19 @@ +Copyright (c) 2018-2019 dirs-rs contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/dirs/README.md b/vendor/dirs/README.md new file mode 100644 index 000000000..c1458bf86 --- /dev/null +++ b/vendor/dirs/README.md @@ -0,0 +1,218 @@ +[![crates.io](https://img.shields.io/crates/v/dirs.svg)](https://crates.io/crates/dirs) +[![API documentation](https://docs.rs/dirs/badge.svg)](https://docs.rs/dirs/) +![actively developed](https://img.shields.io/badge/maintenance-actively--developed-brightgreen.svg) +[![TravisCI status](https://img.shields.io/travis/dirs-dev/dirs-rs/master.svg?label=Linux/macOS%20build)](https://travis-ci.org/dirs-dev/dirs-rs) +[![AppVeyor status](https://img.shields.io/appveyor/ci/soc/dirs-rs/master.svg?label=Windows%20build)](https://ci.appveyor.com/project/soc/dirs-rs/branch/master) +![License: MIT/Apache-2.0](https://img.shields.io/badge/license-MIT%2FApache--2.0-orange.svg) + +# `dirs` + +## Introduction + +- a tiny low-level library with a minimal API +- that provides the platform-specific, user-accessible locations +- for retrieving and storing configuration, cache and other data +- on Linux, Redox, Windows (≥ Vista), macOS and other platforms. + +The library provides the location of these directories by leveraging the mechanisms defined by +- the [XDG base directory](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) and + the [XDG user directory](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/) specifications on Linux and Redox +- the [Known Folder](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457.aspx) API on Windows +- the [Standard Directories](https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW6) + guidelines on macOS + +## Platforms + +This library is written in Rust, and supports Linux, Redox, macOS and Windows. +Other platforms are also supported; they use the Linux conventions. + +The minimal required version of Rust is 1.13 except for Redox, where the minimum Rust version +depends on the [`redox_users`](https://crates.io/crates/redox_users) crate. + +It's mid-level sister library, _directories_, is available for Rust ([directories-rs](https://github.com/dirs-dev/directories-rs)) +and on the JVM ([directories-jvm](https://github.com/dirs-dev/directories-jvm)). + +## Usage + +#### Dependency + +Add the library as a dependency to your project by inserting + +```toml +dirs = "4.0" +``` + +into the `[dependencies]` section of your Cargo.toml file. + +If you are upgrading from version 2, please read the [section on breaking changes](#3) first. + +#### Example + +Library run by user Alice: + +```rust +extern crate dirs; + +dirs::home_dir(); +// Lin: Some(/home/alice) +// Win: Some(C:\Users\Alice) +// Mac: Some(/Users/Alice) + +dirs::audio_dir(); +// Lin: Some(/home/alice/Music) +// Win: Some(C:\Users\Alice\Music) +// Mac: Some(/Users/Alice/Music) + +dirs::config_dir(); +// Lin: Some(/home/alice/.config) +// Win: Some(C:\Users\Alice\AppData\Roaming) +// Mac: Some(/Users/Alice/Library/Application Support) + +dirs::executable_dir(); +// Lin: Some(/home/alice/.local/bin) +// Win: None +// Mac: None +``` + +## Design Goals + +- The _dirs_ library is a low-level crate designed to provide the paths to standard directories + as defined by operating systems rules or conventions.<br/> + If your requirements are more complex, e. g. computing cache, config, etc. paths for specific + applications or projects, consider using [directories](https://github.com/dirs-dev/directories-rs) + instead. +- This library does not create directories or check for their existence. The library only provides + information on what the path to a certain directory _should_ be.<br/> + How this information is used is a decision that developers need to make based on the requirements + of each individual application. +- This library is intentionally focused on providing information on user-writable directories only, + as there is no discernible benefit in returning a path that points to a user-level, writable + directory on one operating system, but a system-level, read-only directory on another.<br/> + The confusion and unexpected failure modes of such an approach would be immense. + - `executable_dir` is specified to provide the path to a user-writable directory for binaries.<br/> + As such a directory only commonly exists on Linux, it returns `None` on macOS and Windows. + - `font_dir` is specified to provide the path to a user-writable directory for fonts.<br/> + As such a directory only exists on Linux and macOS, it returns `None` on Windows. + - `runtime_dir` is specified to provide the path to a directory for non-essential runtime data. + It is required that this directory is created when the user logs in, is only accessible by the + user itself, is deleted when the user logs out, and supports all filesystem features of the + operating system.<br/> + As such a directory only commonly exists on Linux, it returns `None` on macOS and Windows. + +## Features + +**If you want to compute the location of cache, config or data directories for your own application or project, +use `ProjectDirs` of the [directories](https://github.com/dirs-dev/directories-rs) project instead.** + +| Function name | Value on Linux/Redox | Value on Windows | Value on macOS | +| ---------------- | ---------------------------------------------------------------------- | --------------------------------- | ------------------------------------------- | +| `home_dir` | `Some($HOME)` | `Some({FOLDERID_Profile})` | `Some($HOME)` | +| `cache_dir` | `Some($XDG_CACHE_HOME)` or `Some($HOME`/.cache`)` | `Some({FOLDERID_LocalAppData})` | `Some($HOME`/Library/Caches`)` | +| `config_dir` | `Some($XDG_CONFIG_HOME)` or `Some($HOME`/.config`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` | +| `data_dir` | `Some($XDG_DATA_HOME)` or `Some($HOME`/.local/share`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` | +| `data_local_dir` | `Some($XDG_DATA_HOME)` or `Some($HOME`/.local/share`)` | `Some({FOLDERID_LocalAppData})` | `Some($HOME`/Library/Application Support`)` | +| `executable_dir` | `Some($XDG_BIN_HOME)` or `Some($HOME`/.local/bin`)` | `None` | `None` | +| `preference_dir` | `Some($XDG_CONFIG_HOME)` or `Some($HOME`/.config`)` | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Preferences`)` | +| `runtime_dir` | `Some($XDG_RUNTIME_DIR)` or `None` | `None` | `None` | +| `state_dir` | `Some($XDG_STATE_HOME)` or `Some($HOME`/.local/state`)` | `None` | `None` | +| `audio_dir` | `Some(XDG_MUSIC_DIR)` or `None` | `Some({FOLDERID_Music})` | `Some($HOME`/Music/`)` | +| `desktop_dir` | `Some(XDG_DESKTOP_DIR)` or `None` | `Some({FOLDERID_Desktop})` | `Some($HOME`/Desktop/`)` | +| `document_dir` | `Some(XDG_DOCUMENTS_DIR)` or `None` | `Some({FOLDERID_Documents})` | `Some($HOME`/Documents/`)` | +| `download_dir` | `Some(XDG_DOWNLOAD_DIR)` or `None` | `Some({FOLDERID_Downloads})` | `Some($HOME`/Downloads/`)` | +| `font_dir` | `Some($XDG_DATA_HOME`/fonts/`)` or `Some($HOME`/.local/share/fonts/`)` | `None` | `Some($HOME`/Library/Fonts/`)` | +| `picture_dir` | `Some(XDG_PICTURES_DIR)` or `None` | `Some({FOLDERID_Pictures})` | `Some($HOME`/Pictures/`)` | +| `public_dir` | `Some(XDG_PUBLICSHARE_DIR)` or `None` | `Some({FOLDERID_Public})` | `Some($HOME`/Public/`)` | +| `template_dir` | `Some(XDG_TEMPLATES_DIR)` or `None` | `Some({FOLDERID_Templates})` | `None` | +| `video_dir` | `Some(XDG_VIDEOS_DIR)` or `None` | `Some({FOLDERID_Videos})` | `Some($HOME`/Movies/`)` | + +## Comparison + +There are other crates in the Rust ecosystem that try similar or related things. +Here is an overview of them, combined with ratings on properties that guided the design of this crate. + +Please take this table with a grain of salt: a different crate might very well be more suitable for your specific use case. +(Of course _my_ crate achieves _my_ design goals better than other crates, which might have had different design goals.) + +| Library | Status | Lin | Mac | Win |Base|User|Proj|Conv| +| --------------------------------------------------------- | -------------- |:---:|:---:|:---:|:--:|:--:|:--:|:--:| +| [app_dirs](https://crates.io/crates/app_dirs) | Unmaintained | ✔ | ✔ | ✔ | 🞈 | ✖ | ✔ | ✖ | +| [app_dirs2](https://crates.io/crates/app_dirs2) | Maintained | ✔ | ✔ | ✔ | 🞈 | ✖ | ✔ | ✖ | +| **dirs** | **Developed** | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | +| [directories](https://crates.io/crates/directories) | Developed | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | +| [s_app_dir](https://crates.io/crates/s_app_dir) | Unmaintained? | ✔ | ✖ | 🞈 | ✖ | ✖ | 🞈 | ✖ | +| [standard_paths](https://crates.io/crates/standard_paths) | Maintained | ✔ | ✖ | ✔ | ✔ | ✔ | ✔ | ✖ | +| [xdg](https://crates.io/crates/xdg) | Maintained | ✔ | ✖ | ✖ | ✔ | ✖ | ✔ | 🞈 | +| [xdg-basedir](https://crates.io/crates/xdg-basedir) | Unmaintained? | ✔ | ✖ | ✖ | ✔ | ✖ | ✖ | 🞈 | +| [xdg-rs](https://crates.io/crates/xdg-rs) | Obsolete | ✔ | ✖ | ✖ | ✔ | ✖ | ✖ | 🞈 | + +- Lin: Linux support +- Mac: macOS support +- Win: Windows support +- Base: Supports [generic base directories](https://github.com/dirs-dev/directories-rs#basedirs) +- User: Supports [user directories](https://github.com/dirs-dev/directories-rs#userdirs) +- Proj: Supports [project-specific base directories](https://github.com/dirs-dev/directories-rs#projectdirs) +- Conv: Follows naming conventions of the operating system it runs on + +## Build + +It's possible to cross-compile this library if the necessary toolchains are installed with rustup. +This is helpful to ensure a change hasn't broken code on a different platform. + +The following commands will build this library on Linux, macOS and Windows: + +``` +cargo build --target=x86_64-unknown-linux-gnu +cargo build --target=x86_64-pc-windows-gnu +cargo build --target=x86_64-apple-darwin +cargo build --target=x86_64-unknown-redox +``` + +## Changelog + +### 4 + +- **BREAKING CHANGE** The behavior of `executable_dir` has been adjusted to not depend on `$XDG_DATA_HOME`. + Code, which assumed that setting the `$XDG_DATA_HOME` environment variable also impacted `executable_dir` if + the `$XDG_BIN_HOME` environment variable was not set, requires adjustment. +- Add support for `XDG_STATE_HOME`. + +### 3 + +- **BREAKING CHANGE** The behavior of `config_dir` on macOS has been adjusted + (thanks to [everyone involved](https://github.com/dirs-dev/directories-rs/issues/62)): + - The existing `config_dir` function has been changed to return the `Application Support` + directory on macOS, as suggested by Apple documentation. + - The behavior of the `config_dir` function on non-macOS platforms has not been changed. + - If you have used the `config_dir` function to store files, it may be necessary to write code + that migrates the files to the new location on macOS.<br/> + (Alternative: change uses of the `config_dir` function to uses of the `preference_dir` function + to retain the old behavior.) +- The newly added `preference_dir` function returns the `Preferences` directory on macOS now, + which – according to Apple documentation – shall only be used to store .plist files using + Apple-proprietary APIs. + – `preference_dir` and `config_dir` behave identical on non-macOS platforms. + +### 2 + +**BREAKING CHANGE** The behavior of deactivated, missing or invalid [_XDG User Dirs_](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/) +entries on Linux has been improved (contributed by @tmiasko, thank you!): + +- Version 1 returned the user's home directory (`Some($HOME)`) for such faulty entries, except for a faulty `XDG_DESKTOP_DIR` entry which returned (`Some($HOME/Desktop)`). +- Version 2 returns `None` for such entries. + +## License + +Licensed under either of + + * Apache License, Version 2.0 + ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) + * MIT license + ([LICENSE-MIT](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. diff --git a/vendor/dirs/src/lib.rs b/vendor/dirs/src/lib.rs new file mode 100644 index 000000000..3828b4fe7 --- /dev/null +++ b/vendor/dirs/src/lib.rs @@ -0,0 +1,316 @@ +//! The _dirs_ crate is +//! +//! - a tiny library with a minimal API (18 public functions) +//! - that provides the platform-specific, user-accessible locations +//! - for finding and storing configuration, cache and other data +//! - on Linux, Redox, Windows (≥ Vista) and macOS. +//! +//! The library provides the location of these directories by leveraging the mechanisms defined by +//! +//! - the [XDG base directory](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) and the [XDG user directory](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/) specifications on Linux, +//! - the [Known Folder](https://msdn.microsoft.com/en-us/library/windows/desktop/bb776911(v=vs.85).aspx) system on Windows, and +//! - the [Standard Directories](https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW6) on macOS. + +#![deny(missing_docs)] + +use std::path::PathBuf; + +#[cfg(target_os = "windows")] +mod win; +#[cfg(target_os = "windows")] +use win as sys; + +#[cfg(any(target_os = "macos", target_os = "ios"))] +mod mac; +#[cfg(any(target_os = "macos", target_os = "ios"))] +use mac as sys; + +#[cfg(target_arch = "wasm32")] +mod wasm; +#[cfg(target_arch = "wasm32")] +use wasm as sys; + +#[cfg(not(any( + target_os = "windows", + target_os = "macos", target_os = "ios", + target_arch = "wasm32" +)))] +mod lin; +#[cfg(not(any( + target_os = "windows", + target_os = "macos", target_os = "ios", + target_arch = "wasm32" +)))] +use lin as sys; + +/// Returns the path to the user's home directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | -------------------- | -------------- | +/// | Linux | `$HOME` | /home/alice | +/// | macOS | `$HOME` | /Users/Alice | +/// | Windows | `{FOLDERID_Profile}` | C:\Users\Alice | +/// +/// ### Linux and macOS: +/// +/// - Use `$HOME` if it is set and not empty. +/// - If `$HOME` is not set or empty, then the function `getpwuid_r` is used to determine +/// the home directory of the current user. +/// - If `getpwuid_r` lacks an entry for the current user id or the home directory field is empty, +/// then the function returns `None`. +/// +/// ### Windows: +/// +/// This function retrieves the user profile folder using `SHGetKnownFolderPath`. +/// +/// All the examples on this page mentioning `$HOME` use this behavior. +/// +/// _Note:_ This function's behavior differs from [`std::env::home_dir`], +/// which works incorrectly on Linux, macOS and Windows. +/// +/// [`std::env::home_dir`]: https://doc.rust-lang.org/std/env/fn.home_dir.html +pub fn home_dir() -> Option<PathBuf> { + sys::home_dir() +} +/// Returns the path to the user's cache directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ----------------------------------- | ---------------------------- | +/// | Linux | `$XDG_CACHE_HOME` or `$HOME`/.cache | /home/alice/.cache | +/// | macOS | `$HOME`/Library/Caches | /Users/Alice/Library/Caches | +/// | Windows | `{FOLDERID_LocalAppData}` | C:\Users\Alice\AppData\Local | +pub fn cache_dir() -> Option<PathBuf> { + sys::cache_dir() +} +/// Returns the path to the user's config directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ------------------------------------- | ---------------------------------------- | +/// | Linux | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config | +/// | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support | +/// | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming | +pub fn config_dir() -> Option<PathBuf> { + sys::config_dir() +} +/// Returns the path to the user's data directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------------------------- | ---------------------------------------- | +/// | Linux | `$XDG_DATA_HOME` or `$HOME`/.local/share | /home/alice/.local/share | +/// | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support | +/// | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming | +pub fn data_dir() -> Option<PathBuf> { + sys::data_dir() +} +/// Returns the path to the user's local data directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------------------------- | ---------------------------------------- | +/// | Linux | `$XDG_DATA_HOME` or `$HOME`/.local/share | /home/alice/.local/share | +/// | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support | +/// | Windows | `{FOLDERID_LocalAppData}` | C:\Users\Alice\AppData\Local | +pub fn data_local_dir() -> Option<PathBuf> { + sys::data_local_dir() +} +/// Returns the path to the user's executable directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------------------------------------------------- | ---------------------- | +/// | Linux | `$XDG_BIN_HOME` or `$XDG_DATA_HOME`/../bin or `$HOME`/.local/bin | /home/alice/.local/bin | +/// | macOS | – | – | +/// | Windows | – | – | +pub fn executable_dir() -> Option<PathBuf> { + sys::executable_dir() +} +/// Returns the path to the user's preference directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ------------------------------------- | -------------------------------- | +/// | Linux | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config | +/// | macOS | `$HOME`/Library/Preferences | /Users/Alice/Library/Preferences | +/// | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming | +pub fn preference_dir() -> Option<PathBuf> { + sys::preference_dir() +} +/// Returns the path to the user's runtime directory. +/// +/// The runtime directory contains transient, non-essential data (like sockets or named pipes) that +/// is expected to be cleared when the user's session ends. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ------------------ | --------------- | +/// | Linux | `$XDG_RUNTIME_DIR` | /run/user/1001/ | +/// | macOS | – | – | +/// | Windows | – | – | +pub fn runtime_dir() -> Option<PathBuf> { + sys::runtime_dir() +} +/// Returns the path to the user's state directory. +/// +/// The state directory contains data that should be retained between sessions (unlike the runtime +/// directory), but may not be important/portable enough to be synchronized across machines (unlike +/// the config/preferences/data directories). +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ----------------------------------------- | ------------------------ | +/// | Linux | `$XDG_STATE_HOME` or `$HOME`/.local/state | /home/alice/.local/state | +/// | macOS | – | – | +/// | Windows | – | – | +pub fn state_dir() -> Option<PathBuf> { + sys::state_dir() +} + +/// Returns the path to the user's audio directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ------------------ | -------------------- | +/// | Linux | `XDG_MUSIC_DIR` | /home/alice/Music | +/// | macOS | `$HOME`/Music | /Users/Alice/Music | +/// | Windows | `{FOLDERID_Music}` | C:\Users\Alice\Music | +pub fn audio_dir() -> Option<PathBuf> { + sys::audio_dir() +} +/// Returns the path to the user's desktop directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | -------------------- | ---------------------- | +/// | Linux | `XDG_DESKTOP_DIR` | /home/alice/Desktop | +/// | macOS | `$HOME`/Desktop | /Users/Alice/Desktop | +/// | Windows | `{FOLDERID_Desktop}` | C:\Users\Alice\Desktop | +pub fn desktop_dir() -> Option<PathBuf> { + sys::desktop_dir() +} +/// Returns the path to the user's document directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------- | ------------------------ | +/// | Linux | `XDG_DOCUMENTS_DIR` | /home/alice/Documents | +/// | macOS | `$HOME`/Documents | /Users/Alice/Documents | +/// | Windows | `{FOLDERID_Documents}` | C:\Users\Alice\Documents | +pub fn document_dir() -> Option<PathBuf> { + sys::document_dir() +} +/// Returns the path to the user's download directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------- | ------------------------ | +/// | Linux | `XDG_DOWNLOAD_DIR` | /home/alice/Downloads | +/// | macOS | `$HOME`/Downloads | /Users/Alice/Downloads | +/// | Windows | `{FOLDERID_Downloads}` | C:\Users\Alice\Downloads | +pub fn download_dir() -> Option<PathBuf> { + sys::download_dir() +} +/// Returns the path to the user's font directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------------------------------------- | ------------------------------ | +/// | Linux | `$XDG_DATA_HOME`/fonts or `$HOME`/.local/share/fonts | /home/alice/.local/share/fonts | +/// | macOS | `$HOME/Library/Fonts` | /Users/Alice/Library/Fonts | +/// | Windows | – | – | +pub fn font_dir() -> Option<PathBuf> { + sys::font_dir() +} +/// Returns the path to the user's picture directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | --------------------- | ----------------------- | +/// | Linux | `XDG_PICTURES_DIR` | /home/alice/Pictures | +/// | macOS | `$HOME`/Pictures | /Users/Alice/Pictures | +/// | Windows | `{FOLDERID_Pictures}` | C:\Users\Alice\Pictures | +pub fn picture_dir() -> Option<PathBuf> { + sys::picture_dir() +} +/// Returns the path to the user's public directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | --------------------- | ------------------- | +/// | Linux | `XDG_PUBLICSHARE_DIR` | /home/alice/Public | +/// | macOS | `$HOME`/Public | /Users/Alice/Public | +/// | Windows | `{FOLDERID_Public}` | C:\Users\Public | +pub fn public_dir() -> Option<PathBuf> { + sys::public_dir() +} +/// Returns the path to the user's template directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ---------------------- | ---------------------------------------------------------- | +/// | Linux | `XDG_TEMPLATES_DIR` | /home/alice/Templates | +/// | macOS | – | – | +/// | Windows | `{FOLDERID_Templates}` | C:\Users\Alice\AppData\Roaming\Microsoft\Windows\Templates | +pub fn template_dir() -> Option<PathBuf> { + sys::template_dir() +} + +/// Returns the path to the user's video directory. +/// +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. +/// +/// |Platform | Value | Example | +/// | ------- | ------------------- | --------------------- | +/// | Linux | `XDG_VIDEOS_DIR` | /home/alice/Videos | +/// | macOS | `$HOME`/Movies | /Users/Alice/Movies | +/// | Windows | `{FOLDERID_Videos}` | C:\Users\Alice\Videos | +pub fn video_dir() -> Option<PathBuf> { + sys::video_dir() +} + +#[cfg(test)] +mod tests { + #[test] + fn test_dirs() { + println!("home_dir: {:?}", ::home_dir()); + println!(); + println!("cache_dir: {:?}", ::cache_dir()); + println!("config_dir: {:?}", ::config_dir()); + println!("data_dir: {:?}", ::data_dir()); + println!("data_local_dir: {:?}", ::data_local_dir()); + println!("executable_dir: {:?}", ::executable_dir()); + println!("preference_dir: {:?}", ::preference_dir()); + println!("runtime_dir: {:?}", ::runtime_dir()); + println!("state_dir: {:?}", ::state_dir()); + println!(); + println!("audio_dir: {:?}", ::audio_dir()); + println!("desktop_dir: {:?}", ::desktop_dir()); + println!("cache_dir: {:?}", ::document_dir()); + println!("config_dir: {:?}", ::download_dir()); + println!("font_dir: {:?}", ::font_dir()); + println!("picture_dir: {:?}", ::picture_dir()); + println!("public_dir: {:?}", ::public_dir()); + println!("template_dir: {:?}", ::template_dir()); + println!("video_dir: {:?}", ::video_dir()); + } +} diff --git a/vendor/dirs/src/lin.rs b/vendor/dirs/src/lin.rs new file mode 100644 index 000000000..fb4fbd9b5 --- /dev/null +++ b/vendor/dirs/src/lin.rs @@ -0,0 +1,34 @@ +extern crate dirs_sys; + +use std::env; +use std::path::PathBuf; + +pub fn home_dir() -> Option<PathBuf> { dirs_sys::home_dir() } + +pub fn cache_dir() -> Option<PathBuf> { env::var_os("XDG_CACHE_HOME") .and_then(dirs_sys::is_absolute_path).or_else(|| home_dir().map(|h| h.join(".cache"))) } +pub fn config_dir() -> Option<PathBuf> { env::var_os("XDG_CONFIG_HOME").and_then(dirs_sys::is_absolute_path).or_else(|| home_dir().map(|h| h.join(".config"))) } +pub fn data_dir() -> Option<PathBuf> { env::var_os("XDG_DATA_HOME") .and_then(dirs_sys::is_absolute_path).or_else(|| home_dir().map(|h| h.join(".local/share"))) } +pub fn data_local_dir() -> Option<PathBuf> { data_dir() } +pub fn preference_dir() -> Option<PathBuf> { config_dir() } +pub fn runtime_dir() -> Option<PathBuf> { env::var_os("XDG_RUNTIME_DIR").and_then(dirs_sys::is_absolute_path) } +pub fn state_dir() -> Option<PathBuf> { env::var_os("XDG_STATE_HOME") .and_then(dirs_sys::is_absolute_path).or_else(|| home_dir().map(|h| h.join(".local/state"))) } +pub fn executable_dir() -> Option<PathBuf> { env::var_os("XDG_BIN_HOME") .and_then(dirs_sys::is_absolute_path).or_else(|| home_dir().map(|h| h.join(".local/bin"))) } + +pub fn audio_dir() -> Option<PathBuf> { dirs_sys::user_dir("MUSIC") } +pub fn desktop_dir() -> Option<PathBuf> { dirs_sys::user_dir("DESKTOP") } +pub fn document_dir() -> Option<PathBuf> { dirs_sys::user_dir("DOCUMENTS") } +pub fn download_dir() -> Option<PathBuf> { dirs_sys::user_dir("DOWNLOAD") } +pub fn font_dir() -> Option<PathBuf> { data_dir().map(|d| d.join("fonts")) } +pub fn picture_dir() -> Option<PathBuf> { dirs_sys::user_dir("PICTURES") } +pub fn public_dir() -> Option<PathBuf> { dirs_sys::user_dir("PUBLICSHARE") } +pub fn template_dir() -> Option<PathBuf> { dirs_sys::user_dir("TEMPLATES") } +pub fn video_dir() -> Option<PathBuf> { dirs_sys::user_dir("VIDEOS") } + +#[cfg(test)] +mod tests { + #[test] + fn test_file_user_dirs_exists() { + let user_dirs_file = ::config_dir().unwrap().join("user-dirs.dirs"); + println!("{:?} exists: {:?}", user_dirs_file, user_dirs_file.exists()); + } +} diff --git a/vendor/dirs/src/mac.rs b/vendor/dirs/src/mac.rs new file mode 100644 index 000000000..3d8274ecc --- /dev/null +++ b/vendor/dirs/src/mac.rs @@ -0,0 +1,24 @@ +extern crate dirs_sys; + +use std::path::PathBuf; + +pub fn home_dir() -> Option<PathBuf> { dirs_sys::home_dir() } + +pub fn cache_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Library/Caches")) } +pub fn config_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Library/Application Support")) } +pub fn data_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Library/Application Support")) } +pub fn data_local_dir() -> Option<PathBuf> { data_dir() } +pub fn preference_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Library/Preferences")) } +pub fn executable_dir() -> Option<PathBuf> { None } +pub fn runtime_dir() -> Option<PathBuf> { None } +pub fn state_dir() -> Option<PathBuf> { None } + +pub fn audio_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Music")) } +pub fn desktop_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Desktop")) } +pub fn document_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Documents")) } +pub fn download_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Downloads")) } +pub fn font_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Library/Fonts")) } +pub fn picture_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Pictures")) } +pub fn public_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Public")) } +pub fn template_dir() -> Option<PathBuf> { None } +pub fn video_dir() -> Option<PathBuf> { home_dir().map(|h| h.join("Movies")) } diff --git a/vendor/dirs/src/wasm.rs b/vendor/dirs/src/wasm.rs new file mode 100644 index 000000000..b4a8dd2fb --- /dev/null +++ b/vendor/dirs/src/wasm.rs @@ -0,0 +1,24 @@ +// Stub definitions to make things *compile*. + +use std::path::PathBuf; + +pub fn home_dir() -> Option<PathBuf> { None } + +pub fn cache_dir() -> Option<PathBuf> { None } +pub fn config_dir() -> Option<PathBuf> { None } +pub fn data_dir() -> Option<PathBuf> { None } +pub fn data_local_dir() -> Option<PathBuf> { None } +pub fn preference_dir() -> Option<PathBuf> { None } +pub fn runtime_dir() -> Option<PathBuf> { None } +pub fn executable_dir() -> Option<PathBuf> { None } +pub fn state_dir() -> Option<PathBuf> { None } + +pub fn audio_dir() -> Option<PathBuf> { None } +pub fn desktop_dir() -> Option<PathBuf> { None } +pub fn document_dir() -> Option<PathBuf> { None } +pub fn download_dir() -> Option<PathBuf> { None } +pub fn font_dir() -> Option<PathBuf> { None } +pub fn picture_dir() -> Option<PathBuf> { None } +pub fn public_dir() -> Option<PathBuf> { None } +pub fn template_dir() -> Option<PathBuf> { None } +pub fn video_dir() -> Option<PathBuf> { None } diff --git a/vendor/dirs/src/win.rs b/vendor/dirs/src/win.rs new file mode 100644 index 000000000..f28693c01 --- /dev/null +++ b/vendor/dirs/src/win.rs @@ -0,0 +1,24 @@ +extern crate dirs_sys; + +use std::path::PathBuf; + +pub fn home_dir() -> Option<PathBuf> { dirs_sys::known_folder_profile() } + +pub fn data_dir() -> Option<PathBuf> { dirs_sys::known_folder_roaming_app_data() } +pub fn data_local_dir() -> Option<PathBuf> { dirs_sys::known_folder_local_app_data() } +pub fn cache_dir() -> Option<PathBuf> { data_local_dir() } +pub fn config_dir() -> Option<PathBuf> { data_dir() } +pub fn executable_dir() -> Option<PathBuf> { None } +pub fn preference_dir() -> Option<PathBuf> { data_dir() } +pub fn runtime_dir() -> Option<PathBuf> { None } +pub fn state_dir() -> Option<PathBuf> { None } + +pub fn audio_dir() -> Option<PathBuf> { dirs_sys::known_folder_music() } +pub fn desktop_dir() -> Option<PathBuf> { dirs_sys::known_folder_desktop() } +pub fn document_dir() -> Option<PathBuf> { dirs_sys::known_folder_documents() } +pub fn download_dir() -> Option<PathBuf> { dirs_sys::known_folder_downloads() } +pub fn font_dir() -> Option<PathBuf> { None } +pub fn picture_dir() -> Option<PathBuf> { dirs_sys::known_folder_pictures() } +pub fn public_dir() -> Option<PathBuf> { dirs_sys::known_folder_public()} +pub fn template_dir() -> Option<PathBuf> { dirs_sys::known_folder_templates() } +pub fn video_dir() -> Option<PathBuf> { dirs_sys::known_folder_videos() } |