From fa6472e2a19146920951e38f3d39c52ce66c7b32 Mon Sep 17 00:00:00 2001 From: Alek Westover Date: Tue, 13 Jun 2023 15:24:54 -0400 Subject: [PATCH] looking a lot better --- alek_ext/alek1.out | 5 ----- alek_ext/alek2.out | 7 ------- alek_ext/src/main.rs | 36 +++++++++++++++--------------------- 3 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 alek_ext/alek1.out delete mode 100644 alek_ext/alek2.out diff --git a/alek_ext/alek1.out b/alek_ext/alek1.out deleted file mode 100644 index fd6f98abc5..0000000000 --- a/alek_ext/alek1.out +++ /dev/null @@ -1,5 +0,0 @@ -this -Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. - -lol - diff --git a/alek_ext/alek2.out b/alek_ext/alek2.out deleted file mode 100644 index 6447eb8ef9..0000000000 --- a/alek_ext/alek2.out +++ /dev/null @@ -1,7 +0,0 @@ -this -ax mod p < p/2 - -its gonna be big! -coming soon at 4pm -lol - diff --git a/alek_ext/src/main.rs b/alek_ext/src/main.rs index 7b51745449..6af088487c 100644 --- a/alek_ext/src/main.rs +++ b/alek_ext/src/main.rs @@ -1,9 +1,7 @@ /* **WIP** * This is a MWE of using our RemoteStorage API to call the aws stuff and download multiple files - * TODO: - * 2. s3_bucket needs a lot of work; for example to make sure the pagination thing goes fine. - * 3. figure out how to write directly from the buffer to a local file; and just generally clean up main.rs + * TODO: s3_bucket some work; for example to make sure the pagination thing goes fine. */ use remote_storage::*; @@ -22,36 +20,32 @@ async fn main() -> anyhow::Result<()> { tracing::subscriber::set_global_default(subscriber)?; let cfg_file_path = Path::new("./../.neon/pageserver.toml"); - let cfg_file_contents = std::fs::read_to_string(cfg_file_path).unwrap(); + let cfg_file_contents = std::fs::read_to_string(cfg_file_path) + .with_context(|| format!( "Failed to read pageserver config at '{}'", cfg_file_path.display()))?; let toml = cfg_file_contents .parse::() - .context("Error parsing toml")?; + .with_context(|| format!( "Failed to parse '{}' as pageserver config", cfg_file_path.display()))?; let remote_storage_data = toml.get("remote_storage") - .expect("field should be present"); - let remote_storage_config = RemoteStorageConfig::from_toml(remote_storage_data) - .expect("error parsing toml") - .expect("error parsing toml"); + .context("field should be present")?; + let remote_storage_config = RemoteStorageConfig::from_toml(remote_storage_data)? + .context("error configuring remote storage")?; info!("{:?}", remote_storage_config); let remote_storage = GenericRemoteStorage::from_config(&remote_storage_config)?; let folder = RemotePath::new(Path::new("public_extensions"))?; let from_paths = remote_storage.list_files(Some(&folder)).await?; - let mut i = 0; for remote_from_path in from_paths { - i += 1; - println!("number {i}{:?}", remote_from_path.object_name()); + // TODO: is it giving the right name? + // TODO: where should we actually save the files to? if remote_from_path.extension() == Some("control") { - let mut data = remote_storage.download(&remote_from_path).await?; - // write `data` to a file locally - // TODO: I think that the way I'm doing this is not optimal; - // It should be possible to write the data directly to a file - // rather than first writing it to a vector... + let file_name = remote_from_path.object_name().expect("it must exist"); + println!("{:?}",file_name); + let mut download = remote_storage.download(&remote_from_path).await?; let mut write_data_buffer = Vec::new(); - data.download_stream.read_to_end(&mut write_data_buffer).await?; - let f = File::create(format!("alek{i}.out")).expect("problem creating file"); - let mut f = BufWriter::new(f); - f.write_all(&mut write_data_buffer).expect("error writing data"); + download.download_stream.read_to_end(&mut write_data_buffer).await?; + let mut output_file = BufWriter::new(File::create(file_name)?); + output_file.write_all(&mut write_data_buffer)?; } }