From 19064f2cd09368b222272a6401bb60bdaf23e93a Mon Sep 17 00:00:00 2001 From: David Kocher Date: Wed, 25 Dec 2024 18:08:09 +0100 Subject: [PATCH] Fix #16715. --- .../java/ch/cyberduck/core/onedrive/GraphSession.java | 4 ++-- .../java/ch/cyberduck/core/onedrive/OneDriveSession.java | 5 +++++ .../core/onedrive/features/GraphQuotaFeature.java | 8 +++++--- .../ch/cyberduck/core/onedrive/GraphQuotaFeatureTest.java | 7 ++++--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/onedrive/src/main/java/ch/cyberduck/core/onedrive/GraphSession.java b/onedrive/src/main/java/ch/cyberduck/core/onedrive/GraphSession.java index a11ffa597b3..0ebf34ea59c 100644 --- a/onedrive/src/main/java/ch/cyberduck/core/onedrive/GraphSession.java +++ b/onedrive/src/main/java/ch/cyberduck/core/onedrive/GraphSession.java @@ -34,9 +34,9 @@ import ch.cyberduck.core.oauth.OAuth2RequestInterceptor; import ch.cyberduck.core.onedrive.features.*; import ch.cyberduck.core.preferences.HostPreferences; -import ch.cyberduck.core.proxy.ProxyFactory; import ch.cyberduck.core.proxy.ProxyFinder; import ch.cyberduck.core.shared.BufferWriteFeature; +import ch.cyberduck.core.shared.DefaultHomeFinderService; import ch.cyberduck.core.ssl.X509KeyManager; import ch.cyberduck.core.ssl.X509TrustManager; import ch.cyberduck.core.threading.CancelCallback; @@ -264,7 +264,7 @@ public T _getFeature(final Class type) { } } if(type == Quota.class) { - return (T) new GraphQuotaFeature(this, fileid); + return (T) new GraphQuotaFeature(this, fileid, new DefaultHomeFinderService(this)); } if(type == UrlProvider.class) { return (T) new GraphUrlProvider(); diff --git a/onedrive/src/main/java/ch/cyberduck/core/onedrive/OneDriveSession.java b/onedrive/src/main/java/ch/cyberduck/core/onedrive/OneDriveSession.java index 6aa10978caf..e45e30769cd 100644 --- a/onedrive/src/main/java/ch/cyberduck/core/onedrive/OneDriveSession.java +++ b/onedrive/src/main/java/ch/cyberduck/core/onedrive/OneDriveSession.java @@ -23,7 +23,9 @@ import ch.cyberduck.core.exception.NotfoundException; import ch.cyberduck.core.features.Home; import ch.cyberduck.core.features.Lock; +import ch.cyberduck.core.features.Quota; import ch.cyberduck.core.onedrive.features.GraphLockFeature; +import ch.cyberduck.core.onedrive.features.GraphQuotaFeature; import ch.cyberduck.core.shared.DefaultPathHomeFeature; import ch.cyberduck.core.shared.DelegatingHomeFeature; import ch.cyberduck.core.shared.WorkdirHomeFeature; @@ -190,6 +192,9 @@ public T _getFeature(final Class type) { if(type == Home.class) { return (T) new DelegatingHomeFeature(new WorkdirHomeFeature(host), new DefaultPathHomeFeature(host), new OneDriveHomeFinderService()); } + if(type == Quota.class) { + return (T) new GraphQuotaFeature(this, fileid, new OneDriveHomeFinderService()); + } if(type == ListService.class) { return (T) new OneDriveListService(this, fileid); } diff --git a/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphQuotaFeature.java b/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphQuotaFeature.java index f7f39f9f303..e029f2d29e6 100644 --- a/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphQuotaFeature.java +++ b/onedrive/src/main/java/ch/cyberduck/core/onedrive/features/GraphQuotaFeature.java @@ -18,10 +18,10 @@ import ch.cyberduck.core.DefaultIOExceptionMappingService; import ch.cyberduck.core.Path; import ch.cyberduck.core.exception.BackgroundException; +import ch.cyberduck.core.features.Home; import ch.cyberduck.core.features.Quota; import ch.cyberduck.core.onedrive.GraphExceptionMappingService; import ch.cyberduck.core.onedrive.GraphSession; -import ch.cyberduck.core.shared.DefaultHomeFinderService; import org.nuxeo.onedrive.client.ODataQuery; import org.nuxeo.onedrive.client.OneDriveAPIException; @@ -34,15 +34,17 @@ public class GraphQuotaFeature implements Quota { private final GraphSession session; private final GraphFileIdProvider fileid; + private final Home finder; - public GraphQuotaFeature(final GraphSession session, final GraphFileIdProvider fileid) { + public GraphQuotaFeature(final GraphSession session, final GraphFileIdProvider fileid, final Home finder) { this.session = session; this.fileid = fileid; + this.finder = finder; } @Override public Space get() throws BackgroundException { - final Path home = new DefaultHomeFinderService(session).find(); + final Path home = finder.find(); if(!session.isAccessible(home)) { // not accessible (important for Sharepoint) return unknown; diff --git a/onedrive/src/test/java/ch/cyberduck/core/onedrive/GraphQuotaFeatureTest.java b/onedrive/src/test/java/ch/cyberduck/core/onedrive/GraphQuotaFeatureTest.java index bd71c989c38..7907a6110b6 100644 --- a/onedrive/src/test/java/ch/cyberduck/core/onedrive/GraphQuotaFeatureTest.java +++ b/onedrive/src/test/java/ch/cyberduck/core/onedrive/GraphQuotaFeatureTest.java @@ -24,16 +24,17 @@ import org.junit.Test; import org.junit.experimental.categories.Category; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; @Category(IntegrationTest.class) public class GraphQuotaFeatureTest extends AbstractOneDriveTest { @Test public void testQuotaSimple() throws BackgroundException { - final Home home = new OneDriveHomeFinderService(); - final Quota quota = new GraphQuotaFeature(session, fileid); + assertEquals(Quota.unknown, new GraphQuotaFeature(session, fileid, () -> Home.ROOT).get()); + final Quota quota = new GraphQuotaFeature(session, fileid, new OneDriveHomeFinderService()); Quota.Space space = quota.get(); + assertNotEquals(Quota.unknown, space); assertTrue(space.available > 0); assertTrue(space.used >= 0); }