mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-06 08:14:07 +00:00
Added configs for snap daemons (#1204)
This commit is contained in:
+29
-17
@@ -14,19 +14,24 @@ use directories::ProjectDirs;
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Default configuration file path
|
||||
pub fn get_default_config_path() -> Option<PathBuf> {
|
||||
pub fn get_default_config_path(config_file: &str) -> Option<PathBuf> {
|
||||
// config.json in the current working directory ($PWD)
|
||||
let config_files = vec![config_file, "config.json"];
|
||||
if let Ok(mut path) = env::current_dir() {
|
||||
path.push("config.json");
|
||||
|
||||
if path.exists() {
|
||||
return Some(path);
|
||||
for filename in &config_files {
|
||||
path.push(filename);
|
||||
if path.exists() {
|
||||
return Some(path);
|
||||
}
|
||||
path.pop();
|
||||
}
|
||||
} else {
|
||||
// config.json in the current working directory (relative path)
|
||||
let relative_path = PathBuf::from("config.json");
|
||||
if relative_path.exists() {
|
||||
return Some(relative_path);
|
||||
for filename in &config_files {
|
||||
let relative_path = PathBuf::from(filename);
|
||||
if relative_path.exists() {
|
||||
return Some(relative_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,10 +43,12 @@ pub fn get_default_config_path() -> Option<PathBuf> {
|
||||
// Windows: {FOLDERID_RoamingAppData}/shadowsocks/shadowsocks-rust/config/config.json
|
||||
|
||||
let mut config_path = project_dirs.config_dir().to_path_buf();
|
||||
config_path.push("config.json");
|
||||
|
||||
if config_path.exists() {
|
||||
return Some(config_path);
|
||||
for filename in &config_files {
|
||||
config_path.push(filename);
|
||||
if config_path.exists() {
|
||||
return Some(config_path);
|
||||
}
|
||||
config_path.pop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,17 +58,22 @@ pub fn get_default_config_path() -> Option<PathBuf> {
|
||||
if let Ok(base_directories) = xdg::BaseDirectories::with_prefix("shadowsocks-rust") {
|
||||
// $XDG_CONFIG_HOME/shadowsocks-rust/config.json
|
||||
// for dir in $XDG_CONFIG_DIRS; $dir/shadowsocks-rust/config.json
|
||||
if let Some(config_path) = base_directories.find_config_file("config.json") {
|
||||
return Some(config_path);
|
||||
for filename in &config_files {
|
||||
if let Some(config_path) = base_directories.find_config_file(filename) {
|
||||
return Some(config_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UNIX global configuration file
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let global_config_path = Path::new("/etc/shadowsocks-rust/config.json");
|
||||
if global_config_path.exists() {
|
||||
return Some(global_config_path.to_path_buf());
|
||||
for filename in &config_files {
|
||||
let path_str = "/etc/shadowsocks-rust/".to_owned() + filename;
|
||||
let global_config_path = Path::new(&path_str);
|
||||
if global_config_path.exists() {
|
||||
return Some(global_config_path.to_path_buf());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -500,7 +500,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode {
|
||||
let (config, runtime) = {
|
||||
let config_path_opt = matches.get_one::<PathBuf>("CONFIG").cloned().or_else(|| {
|
||||
if !matches.contains_id("SERVER_CONFIG") {
|
||||
match crate::config::get_default_config_path() {
|
||||
match crate::config::get_default_config_path("local.json") {
|
||||
None => None,
|
||||
Some(p) => {
|
||||
println!("loading default config {p:?}");
|
||||
|
||||
@@ -260,7 +260,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode {
|
||||
let (config, runtime) = {
|
||||
let config_path_opt = matches.get_one::<PathBuf>("CONFIG").cloned().or_else(|| {
|
||||
if !matches.contains_id("SERVER_CONFIG") {
|
||||
match crate::config::get_default_config_path() {
|
||||
match crate::config::get_default_config_path("manager.json") {
|
||||
None => None,
|
||||
Some(p) => {
|
||||
println!("loading default config {p:?}");
|
||||
|
||||
@@ -272,7 +272,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode {
|
||||
let (config, runtime) = {
|
||||
let config_path_opt = matches.get_one::<PathBuf>("CONFIG").cloned().or_else(|| {
|
||||
if !matches.contains_id("SERVER_CONFIG") {
|
||||
match crate::config::get_default_config_path() {
|
||||
match crate::config::get_default_config_path("server.json") {
|
||||
None => None,
|
||||
Some(p) => {
|
||||
println!("loading default config {p:?}");
|
||||
|
||||
Reference in New Issue
Block a user