Use the directories crate instead of app_dirs (#1782)

The app_dirs crate is abandonned since quite a bit of time. Use the directories
crate instead, which is maintained and have more OS support.
This commit is contained in:
Xavier L'Heureux 2020-05-14 04:17:23 -04:00 committed by GitHub
parent f78536333a
commit 5fbe5cf785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 68 deletions

54
Cargo.lock generated
View File

@ -33,18 +33,6 @@ dependencies = [
"winapi 0.3.8",
]
[[package]]
name = "app_dirs"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e73a24bad9bd6a94d6395382a6c69fe071708ae4409f763c5475e14ee896313d"
dependencies = [
"ole32-sys",
"shell32-sys",
"winapi 0.2.8",
"xdg",
]
[[package]]
name = "arc-swap"
version = "0.4.5"
@ -752,6 +740,16 @@ dependencies = [
"winapi 0.3.8",
]
[[package]]
name = "directories"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "551a778172a450d7fc12e629ca3b0428d00f6afa9a43da1b630d54604e97371c"
dependencies = [
"cfg-if",
"dirs-sys",
]
[[package]]
name = "dirs"
version = "1.0.5"
@ -2121,7 +2119,6 @@ name = "nu-cli"
version = "0.14.1"
dependencies = [
"ansi_term 0.12.1",
"app_dirs",
"async-stream",
"base64 0.12.0",
"bigdecimal",
@ -2136,6 +2133,7 @@ dependencies = [
"csv",
"ctrlc",
"derive-new",
"directories 2.0.2",
"dirs 2.0.2",
"dunce",
"eml-parser",
@ -2303,7 +2301,7 @@ dependencies = [
name = "nu-test-support"
version = "0.14.1"
dependencies = [
"app_dirs",
"directories 2.0.2",
"dunce",
"getset",
"glob",
@ -2600,16 +2598,6 @@ dependencies = [
"objc",
]
[[package]]
name = "ole32-sys"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d2c49021782e5233cd243168edfa8037574afed4eba4bbaf538b3d8d1789d8c"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "once_cell"
version = "1.3.1"
@ -2906,7 +2894,7 @@ checksum = "6b0a3be00b19ee7bd33238c1c523a7ab4df697345f6b36f90827a7860ea938d4"
dependencies = [
"ansi_term 0.11.0",
"config",
"directories",
"directories 1.0.2",
"isatty",
"petgraph",
"serde 1.0.106",
@ -3421,16 +3409,6 @@ dependencies = [
"yaml-rust",
]
[[package]]
name = "shell32-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ee04b46101f57121c9da2b151988283b6beb79b34f5bb29a58ee48cb695122c"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "shellexpand"
version = "2.0.0"
@ -4199,12 +4177,6 @@ dependencies = [
"log",
]
[[package]]
name = "xdg"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"
[[package]]
name = "xml-rs"
version = "0.8.2"

View File

@ -20,7 +20,7 @@ nu-test-support = { version = "0.14.1", path = "../nu-test-support" }
ansi_term = "0.12.1"
app_dirs = "1.2.1"
directories = "2.0.2"
async-stream = "0.2"
base64 = "0.12.0"
bigdecimal = { version = "0.1.0", features = ["serde"] }

View File

@ -10,7 +10,7 @@ pub(crate) use nuconfig::NuConfig;
use crate::commands::from_toml::convert_toml_value_to_nu_value;
use crate::commands::to_toml::value_to_toml_value;
use crate::prelude::*;
use app_dirs::*;
use directories::ProjectDirs;
use indexmap::IndexMap;
use log::trace;
use nu_errors::ShellError;
@ -20,13 +20,8 @@ use std::fs::{self, OpenOptions};
use std::io;
use std::path::{Path, PathBuf};
pub const APP_INFO: AppInfo = AppInfo {
name: "nu",
author: "nu shell developers",
};
pub fn config_path() -> Result<PathBuf, ShellError> {
app_path(AppDataType::UserConfig, "config")
app_path("config", ProjectDirs::config_dir)
}
pub fn default_path() -> Result<PathBuf, ShellError> {
@ -34,28 +29,26 @@ pub fn default_path() -> Result<PathBuf, ShellError> {
}
pub fn default_path_for(file: &Option<PathBuf>) -> Result<PathBuf, ShellError> {
let filename = &mut config_path()?;
let filename = match file {
None => {
filename.push("config.toml");
filename
}
Some(file) => {
filename.push(file);
filename
}
};
let mut filename = config_path()?;
let file: &Path = file
.as_ref()
.map(AsRef::as_ref)
.unwrap_or_else(|| "config.toml".as_ref());
filename.push(file);
Ok(filename.clone())
Ok(filename)
}
pub fn user_data() -> Result<PathBuf, ShellError> {
app_path(AppDataType::UserData, "user data")
app_path("user data", ProjectDirs::data_local_dir)
}
pub fn app_path(app_data_type: AppDataType, display: &str) -> Result<PathBuf, ShellError> {
let path = app_root(app_data_type, &APP_INFO).map_err(|err| {
ShellError::untagged_runtime_error(&format!("Couldn't open {} path:\n{}", display, err))
fn app_path<F: FnOnce(&ProjectDirs) -> &Path>(display: &str, f: F) -> Result<PathBuf, ShellError> {
let dir = ProjectDirs::from("org", "nushell", "nu")
.ok_or_else(|| ShellError::untagged_runtime_error("Couldn't find project directory"))?;
let path = f(&dir).to_owned();
std::fs::create_dir_all(&path).map_err(|err| {
ShellError::untagged_runtime_error(&format!("Couldn't create {} path:\n{}", display, err))
})?;
Ok(path)

View File

@ -14,7 +14,7 @@ nu-parser = { path = "../nu-parser", version = "0.14.1" }
nu-source = { path = "../nu-source", version = "0.14.1" }
nu-protocol = { path = "../nu-protocol", version = "0.14.1" }
app_dirs = "1.2.1"
directories = "2.0.2"
dunce = "1.0.0"
getset = "0.1.0"
glob = "0.3.0"

View File

@ -41,7 +41,7 @@ path = "/home/shaurya/Desktop"
> open cargo_sample.toml | to toml
[dependencies]
ansi_term = "0.11.0"
app_dirs = "1.2.1"
directories = "2.0.2"
byte-unit = "2.1.0"
bytes = "0.4.12"
chrono-humanize = "0.0.11"

View File

@ -43,7 +43,7 @@ getset = "0.0.7"
logos = "0.10.0-rc2"
logos-derive = "0.10.0-rc2"
language-reporting = "0.3.0"
app_dirs = "1.2.1"
directories = "2.0.2"
toml = "0.5.1"
toml-query = "0.9.0"
clap = "2.33.0"