@Override
    public void setMetadata(final Path file, final TransferStatus status) throws BackgroundException {
        try {
            if(containerService.isContainer(file)) {
                for(Map.Entry<String, String> entry : file.attributes().getMetadata().entrySet()) {
                    // Choose metadata values to remove
                    if(!status.getMetadata().containsKey(entry.getKey())) {
                        log.debug(String.format("Remove metadata with key %s", entry.getKey()));
                        status.getMetadata().put(entry.getKey(), StringUtils.EMPTY);
                    }
                }
                if(log.isDebugEnabled()) {
                    log.debug(String.format("Write metadata %s for file %s", status, file));
                }
                session.getClient().updateContainerMetadata(regionService.lookup(file),
                    containerService.getContainer(file).getName(), status.getMetadata());
            }
            else {
                if(log.isDebugEnabled()) {
                    log.debug(String.format("Write metadata %s for file %s", status, file));
                }
                session.getClient().updateObjectMetadata(regionService.lookup(file),
                    containerService.getContainer(file).getName(), containerService.getKey(file), status.getMetadata());
            }
        }
        catch(GenericException e) {
            throw new SwiftExceptionMappingService().map("Failure to write attributes of {0}", e, file);
        }
        catch(IOException e) {
            throw new DefaultIOExceptionMappingService().map("Failure to write attributes of {0}", e, file);
        }
    }
@Test
    public void testSetMetadata() throws Exception {
        final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
        container.attributes().setRegion("IAD");
        final Path test = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        new SwiftTouchFeature(session, new SwiftRegionService(session)).touch(test, new TransferStatus().withMime("text/plain"));
        final String v = UUID.randomUUID().toString();
        new SwiftMetadataFeature(session).setMetadata(test, Collections.<String, String>singletonMap("Test", v));
        final Map<String, String> metadata = new SwiftMetadataFeature(session).getMetadata(test);
        assertFalse(metadata.isEmpty());
        assertTrue(metadata.containsKey("X-Object-Meta-Test"));
        assertEquals(v, metadata.get("X-Object-Meta-Test"));
        assertEquals("text/plain", metadata.get("Content-Type"));
        new SwiftDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }