use of ch.cyberduck.core.transfer.download.PathPriorityComparator in project cyberduck by iterate-ch.
the class CryptoBulkFeature method pre.
@Override
public R pre(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) throws BackgroundException {
final Map<TransferItem, TransferStatus> encrypted = new HashMap<>(files.size());
final ArrayList<Map.Entry<TransferItem, TransferStatus>> sorted = new ArrayList<>(files.entrySet());
// Sort with folder first in list
sorted.sort(new Comparator<Map.Entry<TransferItem, TransferStatus>>() {
@Override
public int compare(final Map.Entry<TransferItem, TransferStatus> o1, final Map.Entry<TransferItem, TransferStatus> o2) {
return new PathPriorityComparator().compare(o1.getKey().remote, o2.getKey().remote);
}
});
for (Map.Entry<TransferItem, TransferStatus> entry : sorted) {
final Path file = entry.getKey().remote;
final Local local = entry.getKey().local;
final TransferStatus status = entry.getValue();
if (null == status.getHeader()) {
// Write header to be reused in writer
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
}
if (null == status.getNonces()) {
status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(status.getLength())));
}
if (file.isDirectory()) {
if (!status.isExists()) {
switch(type) {
case upload:
// Preset directory ID for new folders to avert lookup with not found failure in directory ID provider
final String directoryId = random.random();
encrypted.put(new TransferItem(cryptomator.encrypt(session, file, directoryId, false), local), status);
break;
default:
encrypted.put(new TransferItem(cryptomator.encrypt(session, file), local), status);
break;
}
} else {
encrypted.put(new TransferItem(cryptomator.encrypt(session, file), local), status);
}
} else {
encrypted.put(new TransferItem(cryptomator.encrypt(session, file), local), status);
}
}
return delegate.pre(type, encrypted, callback);
}
Aggregations