Skip to content

Commit

Permalink
zfs send is working. But may crash the application
Browse files Browse the repository at this point in the history
  • Loading branch information
manoeldesouza committed Jul 31, 2020
1 parent 94ce384 commit 5979f3e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zc"
version = "0.9.3"
version = "0.9.4"
authors = ["Manoel de Souza <[email protected]>"]
edition = "2018"

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Use TAB key to switch between the modes available.

Use LEFT or RIGHT keys to navigate in between the two windows.


**Function Keys per Mode**

| Key | Pool | Dataset | Snapshot | Volume |
Expand Down
30 changes: 30 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

use std::io::*;
use std::process;

pub struct CommandResult {
Expand Down Expand Up @@ -127,6 +128,35 @@ pub fn zfs_diff(snapshot_1: String, snapshot_2: String) -> String {
run_command("zfs", &arguments)
}

pub fn zfs_send(snapshot_source: String, snapshot_stream: String) {

let send_arguments = vec!["send", snapshot_source.as_str()];

let mut send_command = process::Command::new("zfs")
.args(send_arguments)
.stdout(process::Stdio::piped())
.spawn()
.unwrap();

let stream_cmd: Vec<&str> = snapshot_stream.split_whitespace().collect();
let stream_arguments = stream_cmd.get(1..).unwrap();

let mut recv_command = process::Command::new(stream_cmd.get(0).unwrap())
.args(stream_arguments)
.stdin(process::Stdio::piped())
.stdout(process::Stdio::piped())
.spawn()
.unwrap();

if let Some(ref mut stdout) = send_command.stdout {
if let Some(ref mut stdin) = recv_command.stdin {
let mut buf: Vec<u8> = Vec::new();
stdout.read_to_end(&mut buf).unwrap();
stdin.write_all(&buf).unwrap();
}
}
}

pub fn zpool_get_all(dataset: String) -> String {

let arguments = vec!["get", "all", dataset.as_str()];
Expand Down
29 changes: 27 additions & 2 deletions src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ impl Content {
}

pub fn key_f3(&mut self) {
// TODO

let selected_elements = self.selected_elements();

match self.c_type {
ContentType::Pools => { },
ContentType::Datasets => { },
ContentType::Volumes => { },
ContentType::Snapshots => { Content::input_snapshot_send(selected_elements); },
};
}

pub fn key_f4(&mut self) {
Expand Down Expand Up @@ -337,7 +345,7 @@ impl Content {
fn input_snapshot_clone(selected_elements: Vec<String>) {

let selected_string = Content::seleted_string(&selected_elements);
let title = " Snapshot Clone ";
let title = " Clone Snapshot ";
let prompt = "Enter the name of the new Snapshot";

if let Ok(dataset_name) = dialog::input_dialog(title, prompt, "") {
Expand All @@ -359,4 +367,21 @@ impl Content {

dialog::refresh_screen();
}

fn input_snapshot_send(selected_elements: Vec<String>) {

let selected_string = Content::seleted_string(&selected_elements);
let title = " Send Snapshot ";
let prompt = "Enter the stream to send the snapshot (Use with caution!)";

if let Ok(snapshots) = dialog::two_input_dialog(title, prompt, selected_string.as_str(), "zfs recv pool/dataset") {

let snapshot_source = snapshots.0;
let snapshot_stream = snapshots.1;

command::zfs_send(snapshot_source, snapshot_stream);
}

dialog::refresh_screen();
}
}
2 changes: 1 addition & 1 deletion src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Screen {
let pools_menu = " 1 Help 2 _____ 3 _____ 4 _____ 5 _____ 6 _____ 7 Scrub 8 Destr 9 GetAl 10 Exit ".to_string();
let datasets_menu = " 1 Help 2 _____ 3 _____ 4 _____ 5 Snaps 6 Renam 7 Creat 8 Destr 9 GetAl 10 Exit ".to_string();
let volumes_menu = " 1 Help 2 _____ 3 _____ 4 _____ 5 Snaps 6 Renam 7 Creat 8 Destr 9 GetAl 10 Exit ".to_string();
let snapshots_menu = " 1 Help 2 Diff 3 _____ 4 _____ 5 Clone 6 Renam 7 RollB 8 Destr 9 GetAl 10 Exit ".to_string();
let snapshots_menu = " 1 Help 2 Diff 3 Send 4 _____ 5 Clone 6 Renam 7 RollB 8 Destr 9 GetAl 10 Exit ".to_string();

let mut selected_menu: String;

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod content;

const NAME: &str = "zc - ZFS Commander";
const COPYRIGHT: &str = "Copyright (c) 2020, Manoel de Souza <[email protected]>";
const VERSION: &str = "0.9.3";
const VERSION: &str = "0.9.4";
const RELEASE: &str = "30-Jul-2020";

const HELP: &str = r#"
Expand All @@ -25,7 +25,7 @@ const HELP: &str = r#"
|:-----:|:---------------:|:-------------:|:-------------:|:-------------:|
| F1 | Help | Help | Help | Help |
| F2 | - | - | zfs diff | - |
| F3 | - | - | - | - |
| F3 | - | - | zfs send | - |
| F4 | - | - | - | - |
| F5 | - | zfs snapshot | zfs clone | zfs snapshot |
| F6 | - | zfs rename | zfs rename | zfs rename |
Expand Down

0 comments on commit 5979f3e

Please sign in to comment.