Skip to content

Commit 634cf87

Browse files
GerdPGerdP
authored andcommitted
fix #23738: Mass upload: JOSM tries to upload changes even though changeset is already closed
- while filling the changeset check if the maximum size is reached so that JOSM doesn't attempt to upload more than the maximum allowed objects - throw ChangesetClosedException to handle the automatic close of the changeset on server side git-svn-id: https://josm.openstreetmap.de/svn/trunk@19126 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent b7ca041 commit 634cf87

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ protected void realRun() {
260260
try {
261261
getProgressMonitor().subTask(
262262
trn("Uploading {0} object...", "Uploading {0} objects...", toUpload.getSize(), toUpload.getSize()));
263+
getProgressMonitor().setTicks(0); // needed in 2nd and further loop executions
263264
synchronized (this) {
264265
writer = new OsmServerWriter();
265266
}

src/org/openstreetmap/josm/io/OsmServerWriter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.openstreetmap.josm.tools.I18n.tr;
66
import static org.openstreetmap.josm.tools.I18n.trn;
77

8+
import java.time.Instant;
89
import java.util.ArrayList;
910
import java.util.Collection;
1011
import java.util.Iterator;
@@ -18,6 +19,7 @@
1819
import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
1920
import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
2021
import org.openstreetmap.josm.gui.progress.ProgressMonitor;
22+
import org.openstreetmap.josm.io.ChangesetClosedException.Source;
2123
import org.openstreetmap.josm.tools.CheckParameterUtil;
2224

2325
/**
@@ -155,15 +157,15 @@ protected void uploadChangesInChunks(Collection<? extends OsmPrimitive> primitiv
155157
progressMonitor.beginTask(tr("Starting to upload in chunks..."));
156158
List<OsmPrimitive> chunk = new ArrayList<>(chunkSize);
157159
Iterator<? extends OsmPrimitive> it = primitives.iterator();
160+
int maxChunkSize = api.getCapabilities().getMaxChangesetSize();
158161
int numChunks = (int) Math.ceil((double) primitives.size() / (double) chunkSize);
159162
int i = 0;
160163
while (it.hasNext()) {
161164
i++;
162165
if (canceled) return;
163166
int j = 0;
164167
chunk.clear();
165-
while (it.hasNext() && j < chunkSize) {
166-
if (canceled) return;
168+
while (it.hasNext() && j < chunkSize && processed.size() + j < maxChunkSize) {
167169
j++;
168170
chunk.add(it.next());
169171
}
@@ -172,6 +174,10 @@ protected void uploadChangesInChunks(Collection<? extends OsmPrimitive> primitiv
172174
"({0}/{1}) Uploading {2} objects...",
173175
chunk.size(), i, numChunks, chunk.size()));
174176
processed.addAll(api.uploadDiff(chunk, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)));
177+
// see #23738: server will close CS if maximum changeset size was reached
178+
if (processed.size() >= maxChunkSize) {
179+
throw new ChangesetClosedException(api.getChangeset().getId(), Instant.now(), Source.UPLOAD_DATA);
180+
}
175181
}
176182
} finally {
177183
progressMonitor.finishTask();

0 commit comments

Comments
 (0)