pub fn add(&self, name: &str, store_path: &PathBuf) -> Result<PathBuf, AddRootError> {
        let mut path = self.root_dir.clone();
        path.push(name);

        debug!("Adding root from {:?} to {:?}", store_path, path,);
        std::fs::remove_file(&path).or_else(|e| AddRootError::remove(e, &path))?;

        std::fs::remove_file(&path).or_else(|e| AddRootError::remove(e, &path))?;

        symlink(&store_path, &path).map_err(|e| AddRootError::symlink(e, &store_path, &path))?;

        let mut root = if let Ok(path) = env::var("NIX_STATE_DIR") {
            PathBuf::from(path)
        } else {
            PathBuf::from("/nix/var/nix/")
        };
        root.push("gcroots");
        root.push("per-user");

        // TODO: check on start
        root.push(env::var("USER").expect("env var 'USER' must be set"));

        // The user directory sometimes doesn’t exist,
        // but we can create it (it’s root but `rwxrwxrwx`)
        if !root.is_dir() {
            std::fs::create_dir_all(&root).map_err(|e| AddRootError::create_dir_all(e, &root))?;
        }

        root.push(format!("{}-{}", self.id, name));

        debug!("Connecting root from {:?} to {:?}", path, root,);
        std::fs::remove_file(&root).or_else(|e| AddRootError::remove(e, &root))?;

        symlink(&path, &root).map_err(|e| AddRootError::symlink(e, &path, &root))?;

        Ok(path)
    }
/// Store a new root under name
Store a new root under name
Store a new root under name
pub fn add(&self, name: &str, store_path: &PathBuf) -> Result<PathBuf, AddRootError> {
        let mut path = self.root_dir.clone();
        path.push(name);
        debug!("Adding root from {:?} to {:?}", store_path, path,);
        std::fs::remove_file(&path).or_else(|e| AddRootError::remove(e, &path))?;
        std::fs::remove_file(&path).or_else(|e| AddRootError::remove(e, &path))?;
        symlink(&store_path, &path).map_err(|e| AddRootError::symlink(e, &store_path, &path))?;
        let mut root = if let Ok(path) = env::var("NIX_STATE_DIR") {
            PathBuf::from(path)
        } else {
            PathBuf::from("/nix/var/nix/")
        };
        root.push("gcroots");
        root.push("per-user");
        // TODO: check on start
        root.push(env::var("USER").expect("env var 'USER' must be set"));
        // The user directory sometimes doesn’t exist,
        // but we can create it (it’s root but `rwxrwxrwx`)
        if !root.is_dir() {
            std::fs::create_dir_all(&root).map_err(|e| AddRootError::create_dir_all(e, &root))?;
        }
        root.push(format!("{}-{}", self.id, name));
        debug!("Connecting root from {:?} to {:?}", path, root,);
        std::fs::remove_file(&root).or_else(|e| AddRootError::remove(e, &root))?;
        symlink(&path, &root).map_err(|e| AddRootError::symlink(e, &path, &root))?;
        Ok(path)
    }
pub fn add ( & self , name : & str , store_path : & PathBuf ) -> Result < PathBuf , AddRootError > { let mut path = self . root_dir . clone ( ) ; path . push ( name ) ; debug ! ( " " store_path path ) ; std :: fs :: remove_file ( & path ) . or_else ( | e | AddRootError :: remove ( e , & path ) ) ? ; std :: fs :: remove_file ( & path ) . or_else ( | e | AddRootError :: remove ( e , & path ) ) ? ; symlink ( & store_path , & path ) . map_err ( | e | AddRootError :: symlink ( e , & store_path , & path ) ) ? ; let mut root = if let Ok ( path ) = env :: var ( " " ) { PathBuf :: from ( path ) } else { PathBuf :: from ( " " ) } ; root . push ( " " ) ; root . push ( " " ) ; // TODO: check on start root . push ( env :: var ( " " ) . expect ( " " ) ) ; // The user directory sometimes doesn’t exist, // but we can create it (it’s root but `rwxrwxrwx`) if ! root . is_dir ( ) { std :: fs :: create_dir_all ( & root ) . map_err ( | e | AddRootError :: create_dir_all ( e , & root ) ) ? ; } root . push ( format ! ( " " self id name ) ) ; debug ! ( " " path root ) ; std :: fs :: remove_file ( & root ) . or_else ( | e | AddRootError :: remove ( e , & root ) ) ? ; symlink ( & path , & root ) . map_err ( | e | AddRootError :: symlink ( e , & path , & root ) ) ? ; Ok ( path ) }
Store a new root under name
Store a new root under name
&self
name
&str
store_path
&PathBuf
&self
name
&str
store_path
&PathBuf