fn main()

in src/rust/engine/fs/brfs/src/main.rs [621:718]


fn main() {
  let default_store_path = dirs::home_dir()
    .expect("Couldn't find homedir")
    .join(".cache")
    .join("pants")
    .join("lmdb_store");

  let args = clap::App::new("brfs")
    .arg(
      clap::Arg::with_name("local-store-path")
        .takes_value(true)
        .long("local-store-path")
        .default_value_os(default_store_path.as_ref())
        .required(false),
    ).arg(
      clap::Arg::with_name("server-address")
        .takes_value(true)
        .long("server-address")
        .required(false),
    ).arg(
      clap::Arg::with_name("remote-instance-name")
        .takes_value(true)
        .long("remote-instance-name")
        .required(false),
    ).arg(
      clap::Arg::with_name("root-ca-cert-file")
          .help("Path to file containing root certificate authority certificates. If not set, TLS will not be used when connecting to the remote.")
          .takes_value(true)
          .long("root-ca-cert-file")
          .required(false)
    ).arg(clap::Arg::with_name("oauth-bearer-token-file")
        .help("Path to file containing oauth bearer token. If not set, no authorization will be provided to remote servers.")
        .takes_value(true)
        .long("oauth-bearer-token-file")
        .required(false)
  ).arg(
      clap::Arg::with_name("mount-path")
        .required(true)
        .takes_value(true),
    ).get_matches();

  let mount_path = args.value_of("mount-path").unwrap();
  let store_path = args.value_of("local-store-path").unwrap();

  // Unmount whatever happens to be mounted there already.
  // This is handy for development, but should probably be removed :)
  let unmount_return = unmount(mount_path);
  if unmount_return != 0 {
    match errno::errno() {
      errno::Errno(22) => {
        debug!("unmount failed, continuing because error code suggests directory was not mounted")
      }
      v => panic!("Error unmounting: {:?}", v),
    }
  }

  let root_ca_certs = if let Some(path) = args.value_of("root-ca-cert-file") {
    Some(std::fs::read(path).expect("Error reading root CA certs file"))
  } else {
    None
  };

  let oauth_bearer_token = if let Some(path) = args.value_of("oauth-bearer-token-file") {
    Some(std::fs::read_to_string(path).expect("Error reading oauth bearer token file"))
  } else {
    None
  };

  let store = match args.value_of("server-address") {
    Some(address) => fs::Store::with_remote(
      &store_path,
      &[address.to_owned()],
      args.value_of("remote-instance-name").map(str::to_owned),
      &root_ca_certs,
      oauth_bearer_token,
      1,
      4 * 1024 * 1024,
      std::time::Duration::from_secs(5 * 60),
      // TODO: Take a command line arg.
      serverset::BackoffConfig::new(
        std::time::Duration::from_secs(1),
        1.2,
        std::time::Duration::from_secs(20),
      )
      .expect("Error making BackoffConfig"),
      1,
      futures_timer::TimerHandle::default(),
    ),
    None => fs::Store::local_only(&store_path),
  }
  .expect("Error making store");

  let runtime = tokio::runtime::Runtime::new().expect("Making runtime");
  let _fs = mount(mount_path, store, runtime).expect("Error mounting");
  loop {
    std::thread::sleep(std::time::Duration::from_secs(1));
  }
}