Skip to content

Commit 2aa8f9a

Browse files
committed
Automatically fix up invalid slashes around paths
1 parent 7196389 commit 2aa8f9a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ struct Table<'a> {
3030
}
3131
impl<'a> Table<'a> {
3232
fn new(path: &str, file: Option<&str>, filemode: &str, skip: Option<&'a str>) -> Table<'a> {
33+
let mut ownpath = String::from(path);
34+
if !ownpath.starts_with("/") { ownpath.insert(0, '/'); }
35+
if ownpath.ends_with("/") { ownpath.pop(); }
3336
Table {
34-
path: String::from(path),
37+
path: ownpath,
3538
file: match file {
3639
None => RefCell::new(Box::new(stdout())),
3740
Some(ref file) => RefCell::new(Box::new(
@@ -127,7 +130,7 @@ fn gml_to_ewkb(cell: &RefCell<String>, coll: &[Geometry], bbox: Option<&BBox>, m
127130
2 => 32, // Indicate EWKB where the srid follows this byte
128131
3 => 32 | 128, // Add bit to indicate the presence of Z values
129132
_ => {
130-
eprintln!("GML number of dimensions {} not supported", geom.dims);
133+
eprintln!("Warning: GML number of dimensions {} not supported", geom.dims);
131134
32
132135
}
133136
};
@@ -182,8 +185,10 @@ fn add_table<'a>(rowpath: &str, outfile: Option<&str>, filemode: &str, skip: Opt
182185
for col in colspec {
183186
let name = col["name"].as_str().unwrap_or_else(|| fatalerr!("Error: column has no 'name' entry in configuration file"));
184187
let colpath = col["path"].as_str().unwrap_or_else(|| fatalerr!("Error: column has no 'path' entry in configuration file"));
185-
let mut path = String::from(rowpath);
188+
let mut path = String::from(&table.path);
189+
if !colpath.starts_with("/") { path.push('/'); }
186190
path.push_str(colpath);
191+
if path.ends_with("/") { path.pop(); }
187192
let subtable: Option<Table> = match col["cols"].is_badvalue() {
188193
true => None,
189194
false => {

0 commit comments

Comments
 (0)