Skip to content

Commit 2c100d6

Browse files
committed
Bugfix: Check we are not dealing with an .osc file in create mode
1 parent b302bc0 commit 2c100d6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/parse-osmium.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ void parse_osmium_t::stream_file(std::string const &filename,
113113
std::string const &osmium_format = (fmt == "auto" ? "" : fmt);
114114
osmium::io::File infile{filename, osmium_format};
115115

116+
if (!m_append && infile.has_multiple_object_versions()) {
117+
throw std::runtime_error{
118+
"Reading an OSM change file only works in append mode."};
119+
}
120+
116121
if (infile.format() == osmium::io::file_format::unknown) {
117122
throw std::runtime_error{
118123
fmt == "auto"
@@ -137,6 +142,10 @@ void parse_osmium_t::node(osmium::Node const &node)
137142
}
138143

139144
if (node.deleted()) {
145+
if (!m_append) {
146+
throw std::runtime_error{"Input file contains deleted objects but "
147+
"you are not in append mode."};
148+
}
140149
m_data->node_delete(node.id());
141150
} else {
142151
// if the node is not valid, then node.location.lat/lon() can throw.
@@ -172,6 +181,10 @@ void parse_osmium_t::way(osmium::Way &way)
172181
}
173182

174183
if (way.deleted()) {
184+
if (!m_append) {
185+
throw std::runtime_error{"Input file contains deleted objects but "
186+
"you are not in append mode."};
187+
}
175188
m_data->way_delete(way.id());
176189
} else {
177190
if (m_append) {
@@ -191,6 +204,10 @@ void parse_osmium_t::relation(osmium::Relation const &rel)
191204
}
192205

193206
if (rel.deleted()) {
207+
if (!m_append) {
208+
throw std::runtime_error{"Input file contains deleted objects but "
209+
"you are not in append mode."};
210+
}
194211
m_data->relation_delete(rel.id());
195212
} else {
196213
if (rel.members().size() > 32767) {

0 commit comments

Comments
 (0)