Skip to content

Commit

Permalink
XDG is only intelligible on Unix
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdy committed May 14, 2022
1 parent aa23b72 commit a0466f8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zerostash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rprompt = "1.0.5"
serde = { version = "1", features = ["serde_derive"] }
toml = "0.5"
xdg = "2.2"
dirs = "4.0"
ignore = "0.4"

humansize = "1.1.1"
Expand Down
3 changes: 2 additions & 1 deletion zerostash/src/commands/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use abscissa_core::{
use chrono::{DateTime, Utc};
use clap::Parser;
use humansize::{file_size_opts, FileSize};
use nix::unistd::{Gid, Group, Uid, User};
use std::{io::Write, sync::Arc};
use termcolor::{Color, ColorSpec, WriteColor};
use zerostash_files::*;
Expand Down Expand Up @@ -119,6 +118,7 @@ impl Ls {

#[cfg(unix)]
fn get_uid(uid: Option<u32>) -> String {
use nix::unistd::{Uid, User};
uid.and_then(|uid| User::from_uid(Uid::from_raw(uid)).ok())
.flatten()
.map(|u| u.name)
Expand All @@ -127,6 +127,7 @@ fn get_uid(uid: Option<u32>) -> String {

#[cfg(unix)]
fn get_gid(gid: Option<u32>) -> String {
use nix::unistd::{Gid, Group};
gid.and_then(|gid| Group::from_gid(Gid::from_raw(gid)).ok())
.flatten()
.map(|g| g.name)
Expand Down
13 changes: 13 additions & 0 deletions zerostash/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,26 @@ pub enum Backend {

impl ZerostashConfig {
/// Path to the configuration directory
#[cfg(unix)]
pub fn path() -> PathBuf {
xdg::BaseDirectories::with_prefix("zerostash")
.unwrap()
.place_config_file("config.toml")
.expect("cannot create configuration directory")
}

/// Path to the configuration directory
#[cfg(windows)]
pub fn path() -> PathBuf {
let mut p = dirs::home_dir().expect("cannot find home directory");

p.push(".zerostash");
std::fs::create_dir_all(&p).expect("failed to create config dir");

p.push("config.toml");
p
}

/// Write the config file to the file system
pub fn write(&self) -> Result<()> {
unimplemented!()
Expand Down

0 comments on commit a0466f8

Please sign in to comment.