blob: 4ba6a2dc586cee0f56081bfdf55d4118a9c4c2e6 [file] [log] [blame]
// Copyright 2023 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use {
anyhow::{anyhow, Context, Error},
fidl_fuchsia_io as fio,
fuchsia_component::server::ServiceFs,
futures::StreamExt,
};
const DATA_FOR_TEST_DIR_NAME: &str = "data_for_test";
const DATA_FOR_TESTS_PATH: &str = "/data/data_for_test";
#[fuchsia::main]
async fn main() -> Result<(), Error> {
if !std::path::Path::new("/data").exists() {
return Err(anyhow!("Expected /data to be available"));
}
let mut fs = ServiceFs::new();
// Delete data from previous run if leftover due to deletion failure.
if std::path::Path::new(DATA_FOR_TESTS_PATH).exists() {
std::fs::remove_dir_all(DATA_FOR_TESTS_PATH).context("Removing data for test directory")?;
}
// back /data provided to test using fx_fs
std::fs::create_dir(DATA_FOR_TESTS_PATH).context("Create data for test directory")?;
let data_directory = fuchsia_fs::directory::open_in_namespace(
DATA_FOR_TESTS_PATH,
fio::OpenFlags::RIGHT_READABLE | fio::OpenFlags::RIGHT_WRITABLE,
)?;
fs.add_remote(DATA_FOR_TEST_DIR_NAME, data_directory);
fs.take_and_serve_directory_handle()?;
fs.collect::<()>().await;
Ok(())
}