-
Notifications
You must be signed in to change notification settings - Fork 2
Fileio Support [CPP-183] #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
7370036
clean up connection logic
notoriaga 43ae614
fileio
notoriaga 5bbe897
Merge branch 'main' into steve/fileio
notoriaga 5a02a35
pull in broadcaster
notoriaga 1f83c44
cleanup
notoriaga a1a7caf
fix tests
notoriaga ec00a5b
remove io
notoriaga b695f4c
fmt
notoriaga a4a5fc0
lints
notoriaga 1d7a66d
remove rand
notoriaga 42e6bda
rebuild
notoriaga 42f83d1
fix broadcaster
notoriaga 394d57e
lints
notoriaga 01492f7
lintz
notoriaga ed6249b
return result
notoriaga c57e0fa
Add iter methods to receiver
notoriaga da60bf0
have sender accept values or refs
notoriaga 4059e4a
Add rand
notoriaga ebc7298
use slotmap for broadcast
notoriaga 0d27a91
add connection struct
notoriaga b6e84dc
add fileio
notoriaga 2e13480
add jank cli
notoriaga eb95dfe
maybe fix benchmarks
notoriaga 4d02116
add util bin
notoriaga d4a3b20
bench = false
notoriaga e18e124
use connection struct more
notoriaga b48d00a
generic read/write
notoriaga 6bf7bdd
track offset/sequence across writes
notoriaga 7d97f41
cleanup
notoriaga 3239268
lint
notoriaga 234f456
more tests
notoriaga e3a33c8
another test
notoriaga 8dfa5ec
comments
notoriaga 234174a
add sleep
notoriaga 3f41d68
Merge branch 'main' into steve/fileio-next
notoriaga 613e0ea
fix close when done
notoriaga d609102
remove comment
notoriaga 99ef0b6
Move sender id setting/constant to MsgSender
notoriaga 74feb40
Merge branch 'main' into steve/fileio-next
notoriaga d908227
build
notoriaga a562726
Merge remote-tracking branch 'origin/main' into steve/fileio-next
656169e
s/write/overwrite
notoriaga 7d50748
Merge branch 'steve/fileio-next' of github.com:swift-nav/console_pp i…
notoriaga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
use std::{ | ||
fs, | ||
io::{self, Write}, | ||
}; | ||
|
||
use clap::Clap; | ||
use crossbeam::{channel, scope}; | ||
use sbp::sbp_tools::SBPTools; | ||
|
||
use console_backend::{ | ||
broadcaster::Broadcaster, | ||
cli_options::Input, | ||
fileio::Fileio, | ||
types::{MsgSender, Result}, | ||
}; | ||
|
||
#[derive(Clap, Debug)] | ||
#[clap(about = "Fileio operations.")] | ||
pub enum Opts { | ||
/// Write a file from local source to remote destination dest. | ||
Write { | ||
source: String, | ||
dest: String, | ||
#[clap(subcommand)] | ||
input: Input, | ||
}, | ||
|
||
/// Read a file from remote source to local dest. If no dest is provided, file is read to stdout. | ||
Read { | ||
source: String, | ||
dest: Option<String>, | ||
#[clap(subcommand)] | ||
input: Input, | ||
}, | ||
|
||
/// List a directory. | ||
List { | ||
path: String, | ||
#[clap(subcommand)] | ||
input: Input, | ||
}, | ||
|
||
/// Delete a file. | ||
Delete { | ||
path: String, | ||
#[clap(subcommand)] | ||
input: Input, | ||
}, | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let bc = Broadcaster::new(); | ||
|
||
let (done_tx, done_rx) = channel::bounded(0); | ||
|
||
let bc_source = bc.clone(); | ||
let run = move |rdr| { | ||
let messages = sbp::iter_messages(rdr).log_errors(log::Level::Debug); | ||
for msg in messages { | ||
bc_source.send(&msg); | ||
if done_rx.try_recv().is_ok() { | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
match Opts::parse() { | ||
Opts::Write { | ||
source, | ||
dest, | ||
input, | ||
} => { | ||
let (rdr, wtr) = input.into_conn()?.into_io(); | ||
let sender = MsgSender::new(wtr); | ||
scope(|s| { | ||
s.spawn(|_| run(rdr)); | ||
let mut fileio = Fileio::new(bc, sender); | ||
let data = fs::File::open(source)?; | ||
fileio.overwrite(dest, data)?; | ||
eprintln!("file written successfully."); | ||
done_tx.send(true).unwrap(); | ||
Result::Ok(()) | ||
}) | ||
.unwrap() | ||
} | ||
Opts::Read { | ||
source, | ||
dest, | ||
input, | ||
} => { | ||
let (rdr, wtr) = input.into_conn()?.into_io(); | ||
let sender = MsgSender::new(wtr); | ||
scope(|s| { | ||
s.spawn(|_| run(rdr)); | ||
let mut fileio = Fileio::new(bc, sender); | ||
let dest: Box<dyn Write> = match dest { | ||
Some(path) => Box::new(fs::File::create(path)?), | ||
None => Box::new(io::stdout()), | ||
}; | ||
fileio.read(source, dest)?; | ||
done_tx.send(true).unwrap(); | ||
Result::Ok(()) | ||
}) | ||
.unwrap() | ||
} | ||
Opts::List { path, input } => { | ||
let (rdr, wtr) = input.into_conn()?.into_io(); | ||
let sender = MsgSender::new(wtr); | ||
scope(|s| { | ||
s.spawn(|_| run(rdr)); | ||
let mut fileio = Fileio::new(bc, sender); | ||
let files = fileio.readdir(path)?; | ||
eprintln!("{:#?}", files); | ||
done_tx.send(true).unwrap(); | ||
Result::Ok(()) | ||
}) | ||
.unwrap() | ||
} | ||
Opts::Delete { path, input } => { | ||
let (rdr, wtr) = input.into_conn()?.into_io(); | ||
let sender = MsgSender::new(wtr); | ||
scope(|s| { | ||
s.spawn(|_| run(rdr)); | ||
let fileio = Fileio::new(bc, sender); | ||
fileio.remove(path)?; | ||
eprintln!("file deleted."); | ||
done_tx.send(true).unwrap(); | ||
Result::Ok(()) | ||
}) | ||
.unwrap() | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this optional because I was getting weird errors trying to run the new helper with
cargo run
. These backend utils shouldn't need to do all the python stuff anyways. So now to run the util you can do