Source:
<code>public void replace(View<E> update) { DatasetDescriptor updateDescriptor = update.getDataset().getDescriptor(); Compatibility.checkCompatible(updateDescriptor, descriptor); if (descriptor.isPartitioned()) { for (PartitionView<E> src : update.getCoveringPartitions()) { if (src instanceof FileSystemPartitionView) { FileSystemPartitionView<E> dest = getPartitionView( ((FileSystemPartitionView<E>) src).getRelativeLocation()); List<Path> removals = Lists.newArrayList(); Iterable<PartitionView<E>> existingPartitions = dest .toConstraintsView() .getCoveringPartitions(); for (PartitionView<E> partition : existingPartitions) { FileSystemPartitionView<E> toRemove = (FileSystemPartitionView<E>) partition; Path path = new Path(toRemove.getLocation()); removals.add(path); if (partitionListener != null && descriptor.isPartitioned()) { partitionListener.partitionDeleted( namespace, name, toRemove.getRelativeLocation().toString()); } } FileSystemUtil.replace(fileSystem, directory, new Path(dest.getLocation()), new Path(src.getLocation()), removals); if (partitionListener != null && descriptor.isPartitioned()) { partitionListener.partitionAdded( namespace, name, dest.getRelativeLocation().toString()); } } else { throw new IllegalArgumentException( "Incompatible PartitionView: " + src.getClass().getName()); } } } else { deleteAll(); <START> merge((FileSystemDataset<E>) update.getDataset()); <END> } }</code><technical_language>making this safer moving existing files a hidden temporary directory deleting merge succeeds</technical_language>

Target:
public void replace(View<E> update) { DatasetDescriptor updateDescriptor = update.getDataset().getDescriptor(); Compatibility.checkCompatible(updateDescriptor, descriptor); if (descriptor.isPartitioned()) { for (PartitionView<E> src : update.getCoveringPartitions()) { if (src instanceof FileSystemPartitionView) { FileSystemPartitionView<E> dest = getPartitionView( ((FileSystemPartitionView<E>) src).getRelativeLocation()); List<Path> removals = Lists.newArrayList(); Iterable<PartitionView<E>> existingPartitions = dest .toConstraintsView() .getCoveringPartitions(); for (PartitionView<E> partition : existingPartitions) { FileSystemPartitionView<E> toRemove = (FileSystemPartitionView<E>) partition; Path path = new Path(toRemove.getLocation()); removals.add(path); if (partitionListener != null && descriptor.isPartitioned()) { partitionListener.partitionDeleted( namespace, name, toRemove.getRelativeLocation().toString()); } } FileSystemUtil.replace(fileSystem, directory, new Path(dest.getLocation()), new Path(src.getLocation()), removals); if (partitionListener != null && descriptor.isPartitioned()) { partitionListener.partitionAdded( namespace, name, dest.getRelativeLocation().toString()); } } else { throw new IllegalArgumentException( "Incompatible PartitionView: " + src.getClass().getName()); } } } else { PartitionView<E> srcPartition = Iterables.getOnlyElement( update.getCoveringPartitions()); List<Pair<Path, Path>> staged = FileSystemUtil.stageMove(fileSystem, new Path(srcPartition.getLocation()), new Path(unbounded.getLocation()), "replace" ); deleteAll(); FileSystemUtil.finishMove(fileSystem, staged); } }