Skip to content

Commit

Permalink
pass cloned url to session
Browse files Browse the repository at this point in the history
  • Loading branch information
ducaale committed Jul 16, 2023
1 parent 09d912b commit 220b326
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ fn run(args: Cli) -> Result<i32> {

let mut session = match &args.session {
Some(name_or_path) => Some(
Session::load_session(&url, name_or_path.clone(), args.is_session_read_only)
Session::load_session(url.clone(), name_or_path.clone(), args.is_session_read_only)
.with_context(|| {
format!("couldn't load session {:?}", name_or_path.to_string_lossy())
})?,
Expand Down
15 changes: 6 additions & 9 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,21 @@ impl Content {
}
}

pub struct Session<'a> {
url: &'a Url,
pub struct Session {
url: Url,
pub path: PathBuf,
read_only: bool,
content: Content,
}

impl<'a> Session<'a> {
pub fn load_session(url: &'a Url, mut name_or_path: OsString, read_only: bool) -> Result<Self> {
impl Session {
pub fn load_session(url: Url, mut name_or_path: OsString, read_only: bool) -> Result<Self> {
let path = if is_path(&name_or_path) {
PathBuf::from(name_or_path)
} else {
let mut path = config_dir()
.context("couldn't get config directory")?
.join::<PathBuf>(["sessions", &path_from_url(url)?].iter().collect());
.join::<PathBuf>(["sessions", &path_from_url(&url)?].iter().collect());
name_or_path.push(".json");
path.push(name_or_path);
path
Expand Down Expand Up @@ -374,12 +374,9 @@ mod tests {
use anyhow::Result;
use reqwest::header::HeaderValue;

static SESSION_URL: once_cell::sync::Lazy<Url> =
once_cell::sync::Lazy::new(|| Url::parse("http://example.net").unwrap());

fn load_session_from_str(s: &str) -> Result<Session> {
Ok(Session {
url: &SESSION_URL,
url: Url::parse("http://example.net")?,
content: serde_json::from_str::<Content>(s)?.migrate(),
path: PathBuf::new(),
read_only: false,
Expand Down

0 comments on commit 220b326

Please sign in to comment.