diff --git a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveAttributesFinderFeature.java b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveAttributesFinderFeature.java index ae8c85dc1c7..661550709ba 100644 --- a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveAttributesFinderFeature.java +++ b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveAttributesFinderFeature.java @@ -77,6 +77,9 @@ public PathAttributes find(final Path file, final ListProgressListener listener) if(new SimplePathPredicate(DriveHomeFinderService.SHARED_DRIVES_NAME).test(file.getParent())) { list = new DriveTeamDrivesListService(session, fileid).list(file.getParent(), listener); } + else if(new SimplePathPredicate(DriveHomeFinderService.TRASH_FOLDER).test(file.getParent())) { + list = new DriveTrashedListService(session, fileid).list(file.getParent(), listener); + } else { list = new FileidDriveListService(session, fileid, query).list(file.getParent(), listener); } diff --git a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveHomeFinderService.java b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveHomeFinderService.java index f02cd90b688..c9fa2286d3a 100644 --- a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveHomeFinderService.java +++ b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveHomeFinderService.java @@ -40,6 +40,10 @@ public class DriveHomeFinderService extends AbstractHomeFeature { = new Path(PathNormalizer.normalize(LocaleFactory.localizedString("Shared Drives", "Google Drive")), EnumSet.of(Path.Type.directory, Path.Type.placeholder, Path.Type.volume)); + public static final Path TRASH_FOLDER + = new Path(PathNormalizer.normalize(LocaleFactory.localizedString("Trash", "Google Drive")), + EnumSet.of(Path.Type.directory, Path.Type.placeholder, Path.Type.volume)); + @Override public Path find() throws BackgroundException { return MYDRIVE_FOLDER; diff --git a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveListService.java b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveListService.java index 739b03950bc..1d994fbbaf9 100644 --- a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveListService.java +++ b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveListService.java @@ -39,6 +39,7 @@ public AttributedList list(final Path directory, final ListProgressListene list.add(DriveHomeFinderService.MYDRIVE_FOLDER); list.add(DriveHomeFinderService.SHARED_FOLDER_NAME); list.add(DriveHomeFinderService.SHARED_DRIVES_NAME); + list.add(DriveHomeFinderService.TRASH_FOLDER); listener.chunk(directory, list); return list; } @@ -49,6 +50,9 @@ public AttributedList list(final Path directory, final ListProgressListene if(new SimplePathPredicate(DriveHomeFinderService.SHARED_DRIVES_NAME).test(directory)) { return new DriveTeamDrivesListService(session, fileid).list(directory, listener); } + if(new SimplePathPredicate(DriveHomeFinderService.TRASH_FOLDER).test(directory)) { + return new DriveTrashedListService(session, fileid).list(directory, listener); + } return new DriveDefaultListService(session, fileid).list(directory, listener); } } diff --git a/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveTrashedListService.java b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveTrashedListService.java new file mode 100644 index 00000000000..a6247b629c0 --- /dev/null +++ b/googledrive/src/main/java/ch/cyberduck/core/googledrive/DriveTrashedListService.java @@ -0,0 +1,32 @@ +package ch.cyberduck.core.googledrive; + +/* + * Copyright (c) 2002-2023 iterate GmbH. All rights reserved. + * https://cyberduck.io/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +import ch.cyberduck.core.ListProgressListener; +import ch.cyberduck.core.Path; +import ch.cyberduck.core.exception.BackgroundException; + +public class DriveTrashedListService extends AbstractDriveListService { + + public DriveTrashedListService(final DriveSession session, final DriveFileIdProvider fileid) { + super(session, fileid); + } + + @Override + protected String query(final Path directory, final ListProgressListener listener) throws BackgroundException { + return "trashed = true"; + } +} diff --git a/googledrive/src/test/java/ch/cyberduck/core/googledrive/DriveTrashedListServiceTest.java b/googledrive/src/test/java/ch/cyberduck/core/googledrive/DriveTrashedListServiceTest.java new file mode 100644 index 00000000000..2ed37e9b33d --- /dev/null +++ b/googledrive/src/test/java/ch/cyberduck/core/googledrive/DriveTrashedListServiceTest.java @@ -0,0 +1,53 @@ +package ch.cyberduck.core.googledrive; + +/* + * Copyright (c) 2002-2023 iterate GmbH. All rights reserved. + * https://cyberduck.io/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +import ch.cyberduck.core.AlphanumericRandomStringService; +import ch.cyberduck.core.AttributedList; +import ch.cyberduck.core.DisabledListProgressListener; +import ch.cyberduck.core.DisabledLoginCallback; +import ch.cyberduck.core.Path; +import ch.cyberduck.core.features.Delete; +import ch.cyberduck.core.transfer.TransferStatus; +import ch.cyberduck.test.IntegrationTest; + +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.Collections; +import java.util.EnumSet; + +import static org.junit.Assert.*; + +@Category(IntegrationTest.class) +public class DriveTrashedListServiceTest extends AbstractDriveTest { + + @Test + public void testList() throws Exception { + final DriveFileIdProvider fileid = new DriveFileIdProvider(session); + final Path home = DriveHomeFinderService.MYDRIVE_FOLDER; + final Path test = new DriveTouchFeature(session, fileid).touch(new Path(home, + new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus()); + new DriveTrashFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); + final AttributedList list = new DriveTrashedListService(session, fileid).list(DriveHomeFinderService.TRASH_FOLDER, new DisabledListProgressListener()); + assertFalse(list.isEmpty()); + for(Path f : list) { + assertTrue(f.attributes().isHidden()); + assertEquals(f.attributes(), new DriveAttributesFinderFeature(session, fileid).find(f)); + } + new DriveDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); + } +} \ No newline at end of file