use std::path::{ Path, PathBuf };
#[ derive( Debug ) ]
pub struct PersistPaths
{
base : PathBuf,
}
impl PersistPaths
{
#[ inline ]
pub fn new() -> Result< Self, std::io::Error >
{
let root = Self::resolve_root()?;
Ok( Self { base : root.join( ".persistent" ).join( "claude_profile" ) } )
}
#[ must_use ]
#[ inline ]
pub fn base( &self ) -> &Path
{
&self.base
}
#[ must_use ]
#[ inline ]
pub fn credential_store( &self ) -> PathBuf
{
let root = self.base
.parent()
.expect( "base must have a .persistent parent" )
.parent()
.expect( ".persistent must have a root parent" );
root.join( ".persistent" ).join( "claude" ).join( "credential" )
}
#[ inline ]
pub fn ensure_exists( &self ) -> Result< (), std::io::Error >
{
std::fs::create_dir_all( &self.base )
}
fn resolve_root() -> Result< PathBuf, std::io::Error >
{
if let Some( pro ) = std::env::var_os( "PRO" )
{
let path = PathBuf::from( pro );
if path.is_dir()
{
return Ok( path );
}
}
std::env::var_os( "HOME" )
.or_else( || std::env::var_os( "USERPROFILE" ) )
.map( PathBuf::from )
.ok_or_else( || std::io::Error::new( std::io::ErrorKind::NotFound, "neither $PRO nor $HOME is set" ) )
}
}