Skip to content

Commit 0df592b

Browse files
authored
fix: simple translate (#757)
1 parent 7fc2817 commit 0df592b

File tree

6 files changed

+23
-5
lines changed

6 files changed

+23
-5
lines changed

crates/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ url.workspace = true
4848
[dev-dependencies]
4949
assert_cmd.workspace = true
5050
rstest.workspace = true
51+
tempfile.workspace = true
5152

5253
[lib]
5354
crate-type = ["lib", "cdylib"]

crates/cli/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,17 @@ mod tests {
805805
.success();
806806
}
807807

808+
#[rstest]
809+
fn translate_to_file(mut command: Command) {
810+
let temp_dir = tempfile::env::temp_dir();
811+
command
812+
.arg("translate")
813+
.arg("examples/simple-item.json")
814+
.arg(temp_dir.join("simple-item.json"))
815+
.assert()
816+
.success();
817+
}
818+
808819
#[test]
809820
fn input_format() {
810821
let rustac = Rustac::parse_from(["rustac", "translate"]);

crates/core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2323
- Ensure geoparquet->json provides valid datetime strings (UTC) ([#711](https://github.com/stac-utils/rustac/pull/711)])
2424
- Some `Href` method names ([#747](https://github.com/stac-utils/rustac/pull/747))
2525
- Use `Href` for `Asset.href` 🙈 ([#752](https://github.com/stac-utils/rustac/pull/752))
26+
- `href::make_absolute` is now public ([#757](https://github.com/stac-utils/rustac/pull/757))
2627

2728
### Fixed
2829

crates/core/src/href.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Utilities and structures for working with hrefs.
2+
13
use crate::{Error, Result};
24
use serde::{Deserialize, Serialize};
35
use std::{
@@ -238,7 +240,8 @@ impl AsRef<Href> for Href {
238240
}
239241
}
240242

241-
fn make_absolute(href: &str, base: &str) -> String {
243+
/// Makes an href absolute relative to a
244+
pub fn make_absolute(href: &str, base: &str) -> String {
242245
if href.starts_with('/') {
243246
href.to_string()
244247
} else {

crates/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub mod geo;
116116
pub mod geoarrow;
117117
#[cfg(feature = "geoparquet")]
118118
pub mod geoparquet;
119-
mod href;
119+
pub mod href;
120120
pub mod item;
121121
mod item_asset;
122122
mod item_collection;

crates/io/src/store.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ where
2525
let s = if s.starts_with("/") {
2626
format!("file://{s}")
2727
} else {
28-
let path_buf = std::fs::canonicalize(s)?;
29-
format!("file://{}", path_buf.display())
28+
let current_dir = std::env::current_dir()?;
29+
let s =
30+
stac::href::make_absolute(&s, &format!("{}/", current_dir.to_string_lossy()));
31+
format!("file://{}", s)
3032
};
3133
Url::parse(&s)?
3234
}
3335
};
3436
let parse = || -> Result<(Box<dyn ObjectStore>, Path)> {
35-
tracing::debug!("parsing url={url}");
3637
// It's technically inefficient to parse it twice, but we're doing this to
3738
// then do IO so who cares.
3839
let (scheme, path) = ObjectStoreScheme::parse(&url).map_err(object_store::Error::from)?;
@@ -68,6 +69,7 @@ where
6869
Ok(pair)
6970
};
7071
let (store, path) = parse()?;
72+
tracing::debug!("{url} parsed into path {path}");
7173
url.set_path("");
7274
Ok((StacStore::new(Arc::new(store), url), path))
7375
}

0 commit comments

Comments
 (0)