Changeset 19126 in josm


Ignore:
Timestamp:
2024-06-24T09:27:46+02:00 (5 months ago)
Author:
GerdP
Message:

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
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java

    r19050 r19126  
    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();
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r19050 r19126  
    66import static org.openstreetmap.josm.tools.I18n.trn;
    77
     8import java.time.Instant;
    89import java.util.ArrayList;
    910import java.util.Collection;
     
    1920import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2021import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     22import org.openstreetmap.josm.io.ChangesetClosedException.Source;
    2123import org.openstreetmap.josm.tools.CheckParameterUtil;
    2224
     
    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;
     
    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());
     
    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 {
Note: See TracChangeset for help on using the changeset viewer.