1#[path = "support/concurrent.rs"]
2mod concurrent;
3#[path = "../src/flush.rs"]
4mod flush;
5#[path = "support/typing.rs"]
6mod typing;
7
8use std::{env, fs, io::Write};
9
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let args: Vec<_> = env::args().skip(1).collect();
12 if args.len() == 2 && args[0] == "init" {
13 let bytes =
14 onestore::create_section("synthetic.one", "Concurrent edits:", "Concurrency test")?;
15 let mut file = fs::OpenOptions::new()
16 .write(true)
17 .create_new(true)
18 .open(&args[1])?;
19 file.write_all(&bytes)?;
20 flush::flush(&file)?;
21 return Ok(());
22 }
23 concurrent::run(
24 &args,
25 |path| onestore::read_file(path),
26 |path, source, space, object, range, replacement| {
27 let edit = typing::text(space, object, range, replacement);
28 match typing::sealed(source, "Concurrent client", &edit) {
29 Ok(Some(transaction)) => transaction.commit_file(path),
30 Ok(None) => Ok(()),
31 Err(error) => Err(onestore::CommitError {
32 state: onestore::CommitState::NotCommitted,
33 error: std::io::Error::new(std::io::ErrorKind::InvalidData, error),
34 }),
35 }
36 },
37 )
38}