Skip to content

Commit ff44136

Browse files
committed
Parse QuickXorHash.
1 parent 1d4e411 commit ff44136

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphAttributesFinderFeature.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,21 @@
3333
import org.nuxeo.onedrive.client.OneDriveAPIException;
3434
import org.nuxeo.onedrive.client.types.DriveItem;
3535
import org.nuxeo.onedrive.client.types.DriveItemVersion;
36+
import org.nuxeo.onedrive.client.types.File;
3637
import org.nuxeo.onedrive.client.types.FileSystemInfo;
38+
import org.nuxeo.onedrive.client.types.Hashes;
3739
import org.nuxeo.onedrive.client.types.Publication;
3840

3941
import java.io.IOException;
4042
import java.nio.charset.Charset;
4143
import java.util.Optional;
42-
import java.util.regex.Matcher;
43-
import java.util.regex.Pattern;
4444

4545

4646
public class GraphAttributesFinderFeature implements AttributesFinder, AttributesAdapter<DriveItem.Metadata> {
4747

4848
private final GraphSession session;
4949
private final GraphFileIdProvider fileid;
5050

51-
private static final Pattern ETAG_PATTERN = Pattern.compile("\"\\{([0-9A-Z-]+)\\},\\d+\"");
52-
5351
public GraphAttributesFinderFeature(final GraphSession session, final GraphFileIdProvider fileid) {
5452
this.session = session;
5553
this.fileid = fileid;
@@ -94,10 +92,11 @@ private DriveItem.Metadata toMetadata(final Path file, final DriveItem item) thr
9492
public PathAttributes toAttributes(final DriveItem.Metadata metadata) {
9593
final PathAttributes attributes = new PathAttributes();
9694
attributes.setETag(metadata.getETag());
97-
if(null != metadata.getETag()) {
98-
final Matcher matcher = ETAG_PATTERN.matcher(metadata.getETag());
99-
if(matcher.matches()) {
100-
attributes.setChecksum(Checksum.parse(matcher.group(1)));
95+
final File file = metadata.getFile();
96+
if(file != null) {
97+
final Hashes hashes = file.getHashes();
98+
if(hashes != null) {
99+
attributes.setChecksum(Checksum.parse(hashes.getQuickXorHash()));
101100
}
102101
}
103102
Optional<DescriptiveUrl> webUrl = getWebUrl(metadata);

onedrive/src/test/java/ch/cyberduck/core/onedrive/GraphAttributesFinderFeatureTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import ch.cyberduck.core.exception.NotfoundException;
2323
import ch.cyberduck.core.features.Delete;
2424
import ch.cyberduck.core.features.Home;
25-
import ch.cyberduck.core.io.HashAlgorithm;
25+
import ch.cyberduck.core.io.Checksum;
2626
import ch.cyberduck.core.onedrive.features.GraphAttributesFinderFeature;
2727
import ch.cyberduck.core.onedrive.features.GraphDeleteFeature;
2828
import ch.cyberduck.core.onedrive.features.GraphDirectoryFeature;
@@ -64,8 +64,7 @@ public void testFindFile() throws Exception {
6464
assertNotEquals(-1L, attributes.getCreationDate());
6565
assertNotEquals(-1L, attributes.getModificationDate());
6666
assertNotNull(attributes.getETag());
67-
assertNotNull(attributes.getChecksum());
68-
assertEquals(HashAlgorithm.uuid, attributes.getChecksum().algorithm);
67+
assertNotEquals(Checksum.NONE, attributes.getChecksum());
6968
assertNull(attributes.getVersionId());
7069
assertNotNull(attributes.getLink());
7170
assertNotNull(attributes.getFileId());
@@ -83,7 +82,7 @@ public void testFindDirectory() throws Exception {
8382
assertNotEquals(-1L, attributes.getModificationDate());
8483
assertNotNull(attributes.getETag());
8584
assertNotNull(attributes.getChecksum());
86-
assertEquals(HashAlgorithm.uuid, attributes.getChecksum().algorithm);
85+
assertEquals(Checksum.NONE, attributes.getChecksum().algorithm);
8786
assertNull(attributes.getVersionId());
8887
assertNotNull(attributes.getLink());
8988
assertNotNull(attributes.getFileId());

onedrive/src/test/java/ch/cyberduck/core/onedrive/GraphMoveFeatureTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public void testMove() throws BackgroundException {
104104
Path touchedFile = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
105105
touch.touch(touchedFile, new TransferStatus().setMime("x-application/cyberduck"));
106106
final PathAttributes attributes = attributesFinder.find(touchedFile);
107-
107+
assertEquals("AAAAAAAAAAAAAAAAAAAAAAAAAAA=", attributes.getChecksum().base64);
108+
assertEquals("0000000000000000000000000000000000000000", attributes.getChecksum().hex);
108109
Path rename = new Path(targetDirectory, touchedFile.getName(), EnumSet.of(Path.Type.file));
109110
assertTrue(move.isSupported(touchedFile, Optional.of(rename)));
110111
final Path target = move.move(touchedFile, rename, new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());

onedrive/src/test/java/ch/cyberduck/core/onedrive/OneDriveWriteFeatureTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,33 @@ public void testWrite() throws Exception {
6262
final PathAttributes folderAttributes = new GraphAttributesFinderFeature(session, fileid).find(folder);
6363
final String folderEtag = folderAttributes.getETag();
6464
final long folderTimestamp = folderAttributes.getModificationDate();
65-
final byte[] content = RandomUtils.nextBytes(5 * 1024 * 1024);
65+
final byte[] sourceContent = RandomUtils.nextBytes(5 * 1024 * 1024);
6666
final TransferStatus status = new TransferStatus();
67-
status.setLength(content.length);
67+
status.setLength(sourceContent.length);
6868
final Path file = new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
6969
final String id = new GraphTouchFeature(session, fileid).touch(file, new TransferStatus()).attributes().getFileId();
7070
final StatusOutputStream<DriveItem.Metadata> out = feature.write(file, status, new DisabledConnectionCallback());
71-
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
71+
new StreamCopier(status, status).transfer(new ByteArrayInputStream(sourceContent), out);
7272
assertNotNull(out.getStatus());
7373
assertTrue(status.isComplete());
7474
assertNotSame(PathAttributes.EMPTY, status.getResponse());
7575
assertEquals(Protocol.DirectoryTimestamp.explicit, session.getHost().getProtocol().getDirectoryTimestamp());
7676
assertEquals(folderEtag, new GraphAttributesFinderFeature(session, fileid).find(folder).getETag());
7777
assertEquals(folderTimestamp, new GraphAttributesFinderFeature(session, fileid).find(folder).getModificationDate());
7878
assertTrue(new DefaultFindFeature(session).find(file));
79-
final byte[] compare = new byte[content.length];
80-
final InputStream stream = new GraphReadFeature(session, fileid).read(file, new TransferStatus().setLength(content.length), new DisabledConnectionCallback());
79+
final byte[] compare = new byte[sourceContent.length];
80+
final InputStream stream = new GraphReadFeature(session, fileid).read(file, new TransferStatus().setLength(sourceContent.length), new DisabledConnectionCallback());
8181
IOUtils.readFully(stream, compare);
8282
stream.close();
83-
assertArrayEquals(content, compare);
83+
assertArrayEquals(sourceContent, compare);
8484
final Path copy = new Path(file);
8585
copy.attributes().setCustom(Collections.emptyMap());
8686
assertEquals(id, fileid.getFileId(copy));
8787
// Overwrite
8888
final StatusOutputStream<DriveItem.Metadata> overwrite = feature.write(file, status.setExists(true), new DisabledConnectionCallback());
8989
assertNotNull(overwrite);
90-
assertEquals(content.length, IOUtils.copyLarge(new ByteArrayInputStream(content), overwrite));
90+
final byte[] overwriteContent = RandomUtils.nextBytes(5 * 1024 * 1024);
91+
assertEquals(overwriteContent.length, IOUtils.copyLarge(new ByteArrayInputStream(overwriteContent), overwrite));
9192
overwrite.close();
9293
final PathAttributes overwriteAttr = new GraphAttributesFinderFeature(session, fileid).toAttributes(overwrite.getStatus());
9394
assertEquals(overwriteAttr, new GraphAttributesFinderFeature(session, fileid).find(file));

0 commit comments

Comments
 (0)