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
Binary file added docs/images/Scorpio_Commit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion scorpio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ thiserror = "2.0.12"
crossbeam = "0.8.4"
fs_extra = "1.2"
dashmap = "6.1.0"

chrono = { workspace = true }


[features]
Expand Down
141 changes: 123 additions & 18 deletions scorpio/doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ This server provides endpoints to manage file system mounting and configuration
**Response (JSON)**:
```json
{
"status": "Success",
"status": "Success",
"message": "Directory unmounted successfully"
}
```
Expand All @@ -85,7 +85,7 @@ This server provides endpoints to manage file system mounting and configuration
{
"status": "Success",
"config": {
"mega_url": "http://example.com",
"mega_url": "http://example.com",
"mount_path": "path/to/mount",
"store_path": "path/to/store"
}
Expand All @@ -100,7 +100,7 @@ This server provides endpoints to manage file system mounting and configuration
**Request Body (JSON)**:
```json
{
"mega_url": "http://example.com",
"mega_url": "http://example.com",
"mount_path": "new/mount/path",
"store_path": "new/store/path"
}
Expand All @@ -111,54 +111,92 @@ This server provides endpoints to manage file system mounting and configuration
{
"status": "Success",
"config": {
"mega_url": "http://example.com",
"mega_url": "http://example.com",
"mount_path": "new/mount/path",
"store_path": "new/store/path"
}
}
```

### 6. **Git Status**
### 6. **Git Add**
**URL**: `/api/git/add`
**Method**: POST
**Description**: Add added, deleted, and modified files to the temporary storage area.

**Request Body (JSON)**:
```json
{
"mono_path": "path/to/add",
}
```

**Response (JSON)**:
```json
{
"status_code": 200,
}
```

### 7. **Git Status**
**URL**: `/api/git/status`
**Method**: GET
**Description**: Retrieves the status of the Git repository.

**Query Parameters**:
- `filter` (optional): Filter specific output based on the input string.
- `path` : The target path whose status needs to be checked.

**Response (JSON)**:
```json
{
"status_code": 200,
"output": "Git status output"
"status": "Success",
"mono_path": "target/path",
"upper_path": "upper/folder/of/mono_path",
"lower_path": "lower/folder/of/mono_path",
"message": "Status of mono_path",
}
```

### 7. **Git Commit**
**URL**: `/api/git/commit`
**Method**: POST
### 8. **Git Commit**
**URL**: `/api/git/commit`
**Method**: POST
**Description**: Commits changes in the Git repository with a given message.

**Request Body (JSON)**:
```json
{
"message": "Commit message"
"mono_path": "commit/path",
"message": "Commit message",
}
```

**Response (JSON)**:
```json
{
"status_code": 200,
"output": "Commit successful"
"status": "Success",
"commit": {
"id": "The Commit hash",
"tree_id": "New hash of root tree",
"parent_commit_ids": "The hash of last version",
"author": "The author of this repository",
committer: "The committer of current Commit",
message: "Commit message",
},
"msg": "Detailed information",
}
```

### 8. **Git Push**
**URL**: `/api/git/push`
**Method**: POST
### 9. **Git Push**
**URL**: `/api/git/push`
**Method**: POST
**Description**: Pushes committed changes to the remote repository.

**Request Body (JSON)**:
```json
{
"mono_path": "push/path",
}
```

**Response (JSON)**:
```json
{
Expand All @@ -167,6 +205,25 @@ This server provides endpoints to manage file system mounting and configuration
}
```

### 10. **Git Reset**
**URL**: `/api/git/reset`
**Method**: POST
**Description**: Reset the repository, undoing all modifications.

**Request Body (JSON)**:
```json
{
"path": "reset/path",
}
```

**Response (JSON)**:
```json
{
"status_code": 200,
}
```

## Data Structures
### MountRequest
```rust
Expand Down Expand Up @@ -210,10 +267,58 @@ struct ConfigRequest {
}
```

### AddReq
```rust
struct AddReq {
mono_path: String,
}
```

### GitStatus
```rust
struct GitStatus {
status: String,
mono_path: String,
upper_path: String,
lower_path: String,
message: String,
}
```

### GitStatusParams
```rust
struct GitStatusParams {
filter: Option<String>,
path: String,
}
```

### CommitPayload
```rust
struct CommitPayload {
mono_path: String,
message: String,
}
```

### CommitResp
```rust
struct CommitResp {
status: String,
commit: Option<Commit>,
msg: String,
}
```

### PushRequest
```rust
struct PushRequest {
mono_path: String,
}
```

### ResetReq
```rust
struct ResetReq {
path: String,
}
```
10 changes: 8 additions & 2 deletions scorpio/src/daemon/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(super) struct GitStatusParams {
path: String,
}

/// Handles the git status request.
pub(super) async fn git_status_handler(
Query(params): Query<GitStatusParams>,
State(state): State<ScoState>,
Expand Down Expand Up @@ -76,6 +77,8 @@ pub(super) struct CommitResp {
commit: Option<Commit>,
msg: String,
}

/// Handles the git commit request.
#[axum::debug_handler]
pub(super) async fn git_commit_handler(
State(state): State<ScoState>,
Expand Down Expand Up @@ -106,6 +109,7 @@ pub(super) struct AddReq {
mono_path: String,
}

/// Handles the git add request.
pub(super) async fn git_add_handler(
State(state): State<ScoState>,
axum::Json(req): axum::Json<AddReq>,
Expand All @@ -127,6 +131,7 @@ pub(super) struct ResetReq {
path: String,
}

/// Handles the git reset request.
pub(super) async fn git_reset_handler(
State(state): State<ScoState>,
axum::Json(req): axum::Json<ResetReq>,
Expand Down Expand Up @@ -159,9 +164,10 @@ pub(super) async fn git_reset_handler(

#[derive(serde::Deserialize)]
pub(super) struct PushRequest {
monopath: String,
mono_path: String,
}

/// Handles the git push request.
pub(super) async fn git_push_handler(
State(state): State<ScoState>,
axum::Json(payload): axum::Json<PushRequest>,
Expand All @@ -170,7 +176,7 @@ pub(super) async fn git_push_handler(
.manager
.lock()
.await
.push_commit(&payload.monopath)
.push_commit(&payload.mono_path)
.await
{
Ok(response) => {
Expand Down
44 changes: 7 additions & 37 deletions scorpio/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ impl ScorpioManager {
fs::write(file_path, content)?;
Ok(())
}

/// Integrate the temporary storage area files, merge
/// them into a Tree object and output Commit
pub async fn mono_commit(
&self,
mono_path: String,
Expand Down Expand Up @@ -151,6 +154,7 @@ impl ScorpioManager {
Err(Box::from("WorkDir not found"))
}

/// Pushes a commit to the remote mono repository.
pub async fn push_commit(
&self,
mono_path: &str,
Expand All @@ -162,48 +166,13 @@ impl ScorpioManager {
let temp_store_area = TempStoreArea::new(&modified_path)?;
println!("OK1");
let base_url = config::base_url();
let url = format!("{}/{}/git-receive-pack", base_url, mono_path);
let url = format!("{}/{}.git/git-receive-pack", base_url, mono_path);

println!("START");
let res = push::push(&work_path, &url, &temp_store_area.index_db).await?;
let res = push::push_core(&work_path, &url, &temp_store_area.index_db).await?;
println!("END");
Ok(res)
}
/*
pub async fn push_commit(
&self,
mono_path: &str,
) -> Result<reqwest::Response, Box<dyn std::error::Error>> {
let work_dir = self.select_work(mono_path)?; // TODO : deal with error.
let store_path = config::store_path();
let mut path = store_path.to_string();
path.push_str(&work_dir.hash);
path.push_str("commit");

// check path is exist
if !tokio::fs::try_exists(&path).await.unwrap_or(false) {
eprintln!("Path does not exist: {}", path);
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("Path does not exist: {}", path),
)));
}
// read the file as the body to send
let commit_data = tokio::fs::read(&path).await?;

// Send Commit data to remote mono.
let base_url = config::base_url();
let url = format!("{}/{}/git-receive-pack", base_url, mono_path);
let client = reqwest::Client::new();
client
.post(&url)
.header("Content-Type", "application/x-git-receive-pack-request")
.body(Bytes::from(commit_data))
.send()
.await
.map_err(|e| Box::new(e) as Box<dyn std::error::Error>)
}
*/

pub fn check_before_mount(&self, mono_path: &str) -> Result<(), String> {
for work in &self.works {
Expand All @@ -227,6 +196,7 @@ impl ScorpioManager {
}
}

/// Adds a mono file to the Scorpio manager's workspace.
pub async fn mono_add(&self, mono_path: &str) -> Result<(), Box<dyn std::error::Error>> {
// The OS path cannot be used, and should be mapped from
// the FUSE system to the path under Upper.
Expand Down
Loading
Loading