Skip to content

Commit 59cf9f0

Browse files
committedMar 21, 2025··
Fix #16976.
1 parent 21287bd commit 59cf9f0

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed
 

‎googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveAttributesFinderFeature.java

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ public PathAttributes toAttributes(final File f) {
128128
.getBytes(Charset.defaultCharset()).length);
129129
}
130130
}
131+
if(null != f.getProperties()) {
132+
attributes.setMetadata(f.getProperties());
133+
}
131134
return attributes;
132135
}
133136
}

‎googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveMetadataFeature.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323

2424
import java.io.IOException;
2525
import java.util.Collections;
26+
import java.util.HashMap;
2627
import java.util.Map;
2728

2829
import com.google.api.services.drive.model.File;
2930

31+
import static com.google.api.client.util.Data.NULL_STRING;
32+
3033
public class DriveMetadataFeature implements Metadata {
3134

3235
private final DriveSession session;
@@ -63,10 +66,18 @@ public void setMetadata(final Path file, final TransferStatus status) throws Bac
6366
try {
6467
final String fileid = this.fileid.getFileId(file);
6568
final File body = new File();
66-
body.setProperties(status.getMetadata());
67-
final File properties = session.getClient().files().update(fileid, body).setFields("properties").
68-
setSupportsAllDrives(HostPreferencesFactory.get(session.getHost()).getBoolean("googledrive.teamdrive.enable")).execute();
69-
status.setResponse(new DriveAttributesFinderFeature(session, this.fileid).toAttributes(properties));
69+
final Map<String, String> properties = new HashMap<>(status.getMetadata());
70+
for(String key : file.attributes().getMetadata().keySet()) {
71+
if(!properties.containsKey(key)) {
72+
// Entries with null values are cleared in update and copy requests
73+
properties.put(key, NULL_STRING);
74+
}
75+
}
76+
body.setProperties(properties);
77+
status.setResponse(new DriveAttributesFinderFeature(session, this.fileid).toAttributes(
78+
session.getClient().files().update(fileid, body).setFields("properties").
79+
setSupportsAllDrives(HostPreferencesFactory.get(session.getHost()).getBoolean("googledrive.teamdrive.enable")).execute()
80+
));
7081
}
7182
catch(IOException e) {
7283
throw new DriveExceptionMappingService(fileid).map("Failure to write attributes of {0}", e, file);

‎googledrive/src/test/java/ch/cyberduck/core/googledrive/DriveMetadataFeatureTest.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.util.Collections;
3131
import java.util.EnumSet;
32+
import java.util.Map;
3233
import java.util.UUID;
3334

3435
import static ch.cyberduck.core.googledrive.DriveHomeFinderService.MYDRIVE_FOLDER;
@@ -39,14 +40,20 @@ public class DriveMetadataFeatureTest extends AbstractDriveTest {
3940

4041
@Test
4142
public void setMetadata() throws Exception {
42-
final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
43-
final Path test = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
43+
final Path test = new Path(DriveHomeFinderService.MYDRIVE_FOLDER, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
4444
final DriveFileIdProvider fileid = new DriveFileIdProvider(session);
45-
new DriveTouchFeature(session, fileid).touch(test, new TransferStatus());
46-
assertEquals(Collections.emptyMap(), new DriveMetadataFeature(session, fileid).getMetadata(test));
47-
new DriveMetadataFeature(session, fileid).setMetadata(test, Collections.singletonMap("test", "t"));
48-
assertEquals(Collections.singletonMap("test", "t"), new DriveMetadataFeature(session, fileid).getMetadata(test));
49-
new DriveDeleteFeature(session, fileid).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
45+
final TransferStatus status = new TransferStatus();
46+
new DriveTouchFeature(session, fileid).touch(test, status);
47+
final DriveMetadataFeature feature = new DriveMetadataFeature(session, fileid);
48+
assertEquals(Collections.emptyMap(), feature.getMetadata(test));
49+
feature.setMetadata(test, Collections.singletonMap("test", "t"));
50+
final Map<String, String> metadata = feature.getMetadata(test);
51+
assertEquals(Collections.singletonMap("test", "t"), metadata);
52+
test.attributes().setMetadata(metadata);
53+
feature.setMetadata(test, status.setMetadata(Collections.emptyMap()));
54+
assertFalse(status.getResponse().getMetadata().containsKey("test"));
55+
assertFalse(feature.getMetadata(test).containsKey("test"));
56+
new DriveDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
5057
}
5158

5259
@Test

0 commit comments

Comments
 (0)
Please sign in to comment.