Cyberduck Mountain Duck CLI

Ticket #7682: upload_cleanup.patch

File upload_cleanup.patch, 4.7 KB (added by joel-wright, on Dec 15, 2013 at 11:55:31 PM)

Upload Cleanup Patch

  • source/ch/cyberduck/core/Preferences.java

     
    615615        defaults.put("openstack.container.size.preload", String.valueOf(true));
    616616
    617617        defaults.put("openstack.upload.md5", String.valueOf(true));
     618        defaults.put("openstack.upload.cleanup", String.valueOf(true));
    618619
    619620        defaults.put("openstack.upload.largeobject", String.valueOf(true));
    620621        defaults.put("openstack.upload.largeobject.concurrency", String.valueOf(5));
  • source/ch/cyberduck/core/openstack/SwiftLargeObjectUploadFeature.java

     
    2020
    2121import ch.cyberduck.core.DefaultIOExceptionMappingService;
    2222import ch.cyberduck.core.DisabledListProgressListener;
     23import ch.cyberduck.core.DisabledLoginController;
    2324import ch.cyberduck.core.Local;
    2425import ch.cyberduck.core.Path;
    2526import ch.cyberduck.core.PathContainerService;
     
    162163        // Create and upload the large object manifest. It is best to upload all the segments first and
    163164        // then create or update the manifest.
    164165        try {
     166            // Cleanup if necessary
     167            final List<Path> segmentsToDelete = new ArrayList<Path>();
     168            boolean deleteOrphanedSegments = Preferences.instance().getBoolean("openstack.upload.cleanup");
     169            if (deleteOrphanedSegments) {
     170                segmentsToDelete.addAll(segmentService.list(file));
     171            }
    165172            // Static Large Object.
    166173            final String manifest = segmentService.manifest(containerService.getContainer(file).getName(), completed);
    167174            if(log.isDebugEnabled()) {
     
    174181                    status.getMime(),
    175182                    containerService.getKey(file), manifest, Collections.<String, String>emptyMap());
    176183            stored.setMd5sum(checksum);
     184
     185            if (deleteOrphanedSegments) {
     186                segmentsToDelete.removeAll(segmentService.list(file));
     187                if (!segmentsToDelete.isEmpty()) {
     188                    // Clean up any old segments
     189                    new SwiftMultipleDeleteFeature(session).delete(segmentsToDelete, new DisabledLoginController());
     190                }
     191            }
     192
    177193            return stored;
    178194        }
    179195        catch(GenericException e) {
  • source/ch/cyberduck/core/openstack/SwiftWriteFeature.java

     
    2121import ch.cyberduck.core.Cache;
    2222import ch.cyberduck.core.DefaultIOExceptionMappingService;
    2323import ch.cyberduck.core.DisabledListProgressListener;
     24import ch.cyberduck.core.DisabledLoginController;
    2425import ch.cyberduck.core.Path;
    2526import ch.cyberduck.core.PathContainerService;
    2627import ch.cyberduck.core.Preferences;
     
    3940import java.io.IOException;
    4041import java.util.HashMap;
    4142import java.util.List;
     43import java.util.ArrayList;
    4244
    4345import ch.iterate.openstack.swift.exception.GenericException;
    4446import ch.iterate.openstack.swift.model.StorageObject;
     
    110112            @Override
    111113            public StorageObject call(final AbstractHttpEntity entity) throws BackgroundException {
    112114                try {
     115                    final List<Path> segments = new ArrayList<Path>();
     116                    if (Preferences.instance().getBoolean("openstack.upload.cleanup")) {
     117                        segments.addAll(segmentService.list(file));
     118                    }
    113119                    final String checksum = session.getClient().storeObject(new SwiftRegionService(session).lookup(containerService.getContainer(file)),
    114120                            containerService.getContainer(file).getName(), containerService.getKey(file),
    115121                            entity, metadata, null);
    116122                    final StorageObject stored = new StorageObject(containerService.getKey(file));
    117123                    stored.setMd5sum(checksum);
    118124                    stored.setSize(status.getLength());
     125                    if (!segments.isEmpty()) {
     126                        // Clean up any old segments
     127                        new SwiftMultipleDeleteFeature(session).delete(segments, new DisabledLoginController());
     128                    }
    119129                    return stored;
    120130                }
    121131                catch(GenericException e) {
swiss made software