Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions scorpio/src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;

use crate::fuse::MegaFuse;
use crate::manager::fetch::fetch;
use crate::manager::{ScorpioManager, WorkDir};
use crate::manager::{mr, ScorpioManager, WorkDir};
use crate::util::{config, GPath};
use axum::extract::State;
use axum::routing::{get, post};
Expand All @@ -18,6 +18,7 @@ const FAIL: &str = "Fail";
#[derive(Debug, Deserialize, Serialize)]
struct MountRequest {
path: String,
mr: Option<String>, // mr is the mount request, used for buck2 temp mount.
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -153,7 +154,7 @@ async fn mount_handler(
};

let store_path = PathBuf::from(store_path).join(&temp_hash);
let _ = state.fuse.overlay_mount(inode, store_path).await;
let _ = state.fuse.overlay_mount(inode, store_path,false).await;
let mount_info = MountInfo {
hash: temp_hash.clone(),
path: mono_path.clone(),
Expand All @@ -171,12 +172,21 @@ async fn mount_handler(
message: "Directory mounted successfully".to_string(),
});
}

if let Some(m) = &req.mr {

// if mr is provided, we need to fetch the mr info from mono.
mr::build_mr_layer(m, store_path.into()).await.unwrap();

}

// fetch the dionary node info from mono.
let work_dir = fetch(&mut ml, inode, mono_path).await.unwrap();

let store_path = PathBuf::from(store_path).join(&work_dir.hash);
// checkout / mount this dictionary.

let _ = state.fuse.overlay_mount(inode, store_path).await;
let _ = state.fuse.overlay_mount(inode, store_path,false).await;

let mount_info = MountInfo {
hash: work_dir.hash,
Expand Down
12 changes: 10 additions & 2 deletions scorpio/src/fuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl MegaFuse {
// mount user works.
for dir in &manager.works {
let _lower = PathBuf::from(store_path).join(&dir.hash);
megafuse.overlay_mount(dir.node, &_lower).await.unwrap();
megafuse.overlay_mount(dir.node, &_lower,false).await.unwrap();
}

megafuse
Expand All @@ -92,10 +92,16 @@ impl MegaFuse {
&self,
inode: u64,
store_path: P,
need_mr:bool, // if need mr, then create mr layer.
) -> std::io::Result<()> {
let lower = store_path.as_ref().join("lower");
let upper = store_path.as_ref().join("upper");
let lowerdir = vec![lower];
let mut lowerdir = vec![lower];
if need_mr {
let mr_path = store_path.as_ref().join("mr");
let _ = std::fs::create_dir_all(&mr_path);
lowerdir.push(mr_path);
}
let upperdir = upper;

let config = config::Config {
Expand Down Expand Up @@ -145,6 +151,8 @@ impl MegaFuse {
Ok(())
}



/// Unmounts the overlay filesystem associated with a given inode asynchronously.
///
/// This function removes the overlay filesystem mapped to the specified inode from
Expand Down
2 changes: 2 additions & 0 deletions scorpio/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub mod push;
pub mod reset;
pub mod status;
pub mod store;
pub mod mr;

#[derive(Serialize, Deserialize)]
pub struct ScorpioManager {
// pub url:String,
Expand Down
71 changes: 71 additions & 0 deletions scorpio/src/manager/mr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use std::path::PathBuf;

use reqwest::Client;
use serde::Deserialize;

use crate::util::config;

/// Single file record
#[derive(Debug, Deserialize)]
struct FileInfo {
action: String,
path: String,
_sha: String,
}

/// Response body for /files-list endpoint
#[derive(Debug, Deserialize)]
struct FilesListResp {
data: Vec<FileInfo>,
err_message: String,
req_result: bool,
}

pub async fn build_mr_layer(
link: &str,
_mr_path:PathBuf
) -> Result<(), reqwest::Error> {
let files_list = fetch_files_list(link).await?;

if !files_list.req_result {
println!("{}", files_list.err_message);
return Ok(());
}

for file in files_list.data {
if file.action == "remove" {
// ! ! ! Attention:
// As for deleted files, the path should create a `whiteout file`, refer to create_whiteout in other files .
println!("{}", file.path);
}
}
//TODO: Implement the logic to build the MR layer
// This could involve checking out the MR branch, applying changes, etc.
// such as fetch::fetch_by_hashs(&files_list.data, &mr_path)

println!("MR layer built for link: {link}");
Ok(())
}

/// Fetch the list of files for a Merge Request (MR)
///
/// - `link`: unique identifier for the MR (used in the path)
///
/// Returns `FilesListResp` on success, or `reqwest::Error` on failure.
async fn fetch_files_list(
link: &str,
) -> Result<FilesListResp, reqwest::Error> {
let url = format!(
"{}/api/v1/mr/{}/files-list",
config::base_url(),
link
);

Client::new()
.get(&url)
.send()
.await?
.error_for_status()?
.json::<FilesListResp>()
.await
}
Loading