Return custom comparison service for checksum.

This commit is contained in:
David Kocher
2025-10-01 15:25:02 +02:00
parent a8c060e043
commit bad96fe118
3 changed files with 23 additions and 2 deletions
@@ -19,6 +19,9 @@ import ch.cyberduck.core.AbstractProtocol;
import ch.cyberduck.core.LocaleFactory;
import ch.cyberduck.core.Protocol;
import ch.cyberduck.core.Scheme;
import ch.cyberduck.core.synchronization.ChecksumComparisonService;
import ch.cyberduck.core.synchronization.ComparisonService;
import ch.cyberduck.core.synchronization.DefaultComparisonService;
import com.google.auto.service.AutoService;
@@ -85,4 +88,14 @@ public class DriveProtocol extends AbstractProtocol {
public VersioningMode getVersioningMode() {
return VersioningMode.storage;
}
@Override
@SuppressWarnings("unchecked")
public <T> T getFeature(final Class<T> type) {
if(type == ComparisonService.class) {
return (T) new DefaultComparisonService(new ChecksumComparisonService(), ComparisonService.disabled);
}
return super.getFeature(type);
}
}
@@ -58,14 +58,19 @@ public class DriveMoveFeatureTest extends AbstractDriveTest {
final DriveFileIdProvider fileid = new DriveFileIdProvider(session);
final Path test = new DriveTouchFeature(session, fileid).touch(new DriveWriteFeature(session, fileid), new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
final String id = test.attributes().getFileId();
final Path folder = new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
new DriveDirectoryFeature(session, fileid).mkdir(new DriveWriteFeature(session, fileid), folder, new TransferStatus());
final Path folder = new DriveDirectoryFeature(session, fileid).mkdir(new DriveWriteFeature(session, fileid),
new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
assertEquals(folder.attributes(), new DriveAttributesFinderFeature(session, fileid).find(folder));
final Path target = new DriveMoveFeature(session, fileid).move(test, new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());
assertEquals(id, target.attributes().getFileId());
assertEquals(test.attributes().getChecksum(), target.attributes().getChecksum());
assertNotEquals(test.attributes().getModificationDate(), target.attributes().getModificationDate());
final Find find = new DefaultFindFeature(session);
assertFalse(find.find(test));
assertTrue(find.find(target));
assertEquals(folder.attributes(), new DriveAttributesFinderFeature(session, fileid).find(folder));
final PathAttributes targetAttr = new DriveAttributesFinderFeature(session, fileid).find(target);
assertEquals(target.attributes(), targetAttr);
assertEquals(Comparison.equal, session.getHost().getProtocol().getFeature(ComparisonService.class).compare(Path.Type.file, test.attributes(), targetAttr));
new DriveDeleteFeature(session, fileid).delete(Arrays.asList(target, folder), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
@@ -55,6 +55,8 @@ public class DriveWriteFeatureTest extends AbstractDriveTest {
final DriveFileIdProvider idProvider = new DriveFileIdProvider(session);
final Path folder = new DriveDirectoryFeature(session, idProvider).mkdir(
new DriveWriteFeature(session, idProvider), new Path(DriveHomeFinderService.MYDRIVE_FOLDER, UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory)), new TransferStatus());
final PathAttributes folderAttributes = new DriveAttributesFinderFeature(session, idProvider).find(folder);
assertEquals(folderAttributes, folder.attributes());
final Path test = new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
String fileid;
{
@@ -83,6 +85,7 @@ public class DriveWriteFeatureTest extends AbstractDriveTest {
assertArrayEquals(content, buffer);
assertEquals("x-application/cyberduck", session.getClient().files().get(test.attributes().getFileId()).execute().getMimeType());
}
assertEquals(folderAttributes, new DriveAttributesFinderFeature(session, idProvider).find(folder));
{
// overwrite
final TransferStatus status = new TransferStatus();