Search in sources :

Example 1 with CachingAttributesFinderFeature

use of ch.cyberduck.core.CachingAttributesFinderFeature in project cyberduck by iterate-ch.

the class AttributesWorker method run.

@Override
public PathAttributes run(final Session<?> session) throws BackgroundException {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Read latest attributes for file %s", file));
    }
    final AttributesFinder find = new CachingAttributesFinderFeature(cache, session.getFeature(AttributesFinder.class));
    final PathAttributes attr = find.find(file);
    if (log.isDebugEnabled()) {
        log.debug(String.format("Return %s for file %s", attr, file));
    }
    return attr;
}
Also used : CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) PathAttributes(ch.cyberduck.core.PathAttributes)

Example 2 with CachingAttributesFinderFeature

use of ch.cyberduck.core.CachingAttributesFinderFeature in project cyberduck by iterate-ch.

the class CachingAttributesFinderFeatureTest method testAttributes.

@Test
public void testAttributes() throws Exception {
    final PathCache cache = new PathCache(1);
    final AttributesFinder f = new CachingAttributesFinderFeature(cache, new DefaultAttributesFinderFeature(session));
    final String name = new AlphanumericRandomStringService().random();
    final Path file = new DAVTouchFeature(session).touch(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    final Attributes lookup = f.find(file);
    assertEquals(0L, lookup.getSize());
    // Test cache
    assertSame(lookup, new CachingAttributesFinderFeature(cache, new AttributesFinder() {

        @Override
        public PathAttributes find(final Path file, final ListProgressListener listener) {
            fail("Expected cache hit");
            return PathAttributes.EMPTY;
        }
    }).find(file));
    assertEquals(0L, f.find(file).getSize());
    assertTrue(cache.containsKey(file.getParent()));
    // Test wrong type
    try {
        f.find(new Path(new DefaultHomeFinderService(session).find(), name, EnumSet.of(Path.Type.directory)));
        fail();
    } catch (NotfoundException e) {
    // Expected
    }
    new DAVDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : PathCache(ch.cyberduck.core.PathCache) Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) NotfoundException(ch.cyberduck.core.exception.NotfoundException) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) PathAttributes(ch.cyberduck.core.PathAttributes) Attributes(ch.cyberduck.core.Attributes) PathAttributes(ch.cyberduck.core.PathAttributes) DAVDeleteFeature(ch.cyberduck.core.dav.DAVDeleteFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) ListProgressListener(ch.cyberduck.core.ListProgressListener) DAVTouchFeature(ch.cyberduck.core.dav.DAVTouchFeature) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDAVTest(ch.cyberduck.core.dav.AbstractDAVTest)

Example 3 with CachingAttributesFinderFeature

use of ch.cyberduck.core.CachingAttributesFinderFeature in project cyberduck by iterate-ch.

the class DriveAttributesFinderFeatureTest method testFindDefaultAttributesFinderWithCacheCryptomator.

@Test
public void testFindDefaultAttributesFinderWithCacheCryptomator() throws Exception {
    final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final CryptoVault cryptomator = new CryptoVault(vault);
    cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final DriveFileIdProvider idProvider = new DriveFileIdProvider(session);
    final Path test = new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new DriveWriteFeature(session, idProvider)), new DriveWriteFeature(session, idProvider), cryptomator).touch(new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    final Path found = new CryptoListService(session, new DriveListService(session, idProvider), cryptomator).list(test.getParent(), new DisabledListProgressListener()).find(new SimplePathPredicate(test));
    assertEquals(0L, found.attributes().getSize());
    final Cache<Path> cache = new PathCache(1);
    final AttributedList<Path> list = new AttributedList<>();
    list.add(found);
    cache.put(vault, list);
    final PathAttributes attributes = new CachingAttributesFinderFeature(cache, new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator)).find(test);
    assertNotNull(attributes);
    assertEquals(0L, attributes.getSize());
    assertEquals(0L, cache.get(vault).get(0).attributes().getSize());
    cryptomator.getFeature(session, Delete.class, new DriveDeleteFeature(session, idProvider)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
Also used : Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) DriveListService(ch.cyberduck.core.googledrive.DriveListService) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Path(ch.cyberduck.core.Path) PathCache(ch.cyberduck.core.PathCache) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) PathAttributes(ch.cyberduck.core.PathAttributes) DriveWriteFeature(ch.cyberduck.core.googledrive.DriveWriteFeature) DriveDeleteFeature(ch.cyberduck.core.googledrive.DriveDeleteFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) DefaultTouchFeature(ch.cyberduck.core.shared.DefaultTouchFeature) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) AttributedList(ch.cyberduck.core.AttributedList) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DriveFileIdProvider(ch.cyberduck.core.googledrive.DriveFileIdProvider) AbstractDriveTest(ch.cyberduck.core.googledrive.AbstractDriveTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with CachingAttributesFinderFeature

use of ch.cyberduck.core.CachingAttributesFinderFeature in project cyberduck by iterate-ch.

the class SFTPWriteFeatureTest method testWriteWithCache.

@Test
public void testWriteWithCache() throws Exception {
    final TransferStatus status = new TransferStatus();
    final int length = 1048576;
    final byte[] content = RandomUtils.nextBytes(length);
    status.setLength(content.length);
    final Path home = new SFTPHomeDirectoryService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault);
    cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final CryptoWriteFeature<Void> writer = new CryptoWriteFeature<>(session, new SFTPWriteFeature(session), cryptomator);
    final FileHeader header = cryptomator.getFileHeaderCryptor().create();
    status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
    status.setNonces(new RandomNonceGenerator());
    status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
    final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    out.close();
    assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(test));
    final Path found = new CryptoListService(session, new SFTPListService(session), cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test);
    final Cache<Path> cache = new PathCache(1);
    final AttributedList<Path> list = new AttributedList<>();
    list.add(found);
    cache.put(vault, list);
    assertEquals(content.length, cache.get(vault).get(0).attributes().getSize());
    assertEquals(content.length, found.attributes().getSize());
    {
        final PathAttributes attributes = new CryptoAttributesFeature(session, new SFTPAttributesFinderFeature(session), cryptomator).find(test);
        assertEquals(content.length, attributes.getSize());
        assertEquals(content.length, writer.append(test, status.withRemote(attributes)).size, 0L);
    }
    {
        final PathAttributes attributes = new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(test);
        assertEquals(content.length, attributes.getSize());
        assertEquals(content.length, writer.append(test, status.withRemote(attributes)).size, 0L);
    }
    {
        final PathAttributes attributes = new CachingAttributesFinderFeature(cache, new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator)).find(test);
        assertEquals(content.length, attributes.getSize());
        assertEquals(content.length, writer.append(test, status.withRemote(attributes)).size, 0L);
    }
    assertEquals(content.length, cache.get(vault).get(0).attributes().getSize());
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final InputStream in = new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
    new StreamCopier(status, status).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    cryptomator.getFeature(session, Delete.class, new SFTPDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : SFTPAttributesFinderFeature(ch.cyberduck.core.sftp.SFTPAttributesFinderFeature) Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) CryptoWriteFeature(ch.cyberduck.core.cryptomator.features.CryptoWriteFeature) SFTPFindFeature(ch.cyberduck.core.sftp.SFTPFindFeature) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SFTPWriteFeature(ch.cyberduck.core.sftp.SFTPWriteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) FileHeader(org.cryptomator.cryptolib.api.FileHeader) Path(ch.cyberduck.core.Path) PathCache(ch.cyberduck.core.PathCache) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SFTPDeleteFeature(ch.cyberduck.core.sftp.SFTPDeleteFeature) RandomNonceGenerator(ch.cyberduck.core.cryptomator.random.RandomNonceGenerator) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) SFTPReadFeature(ch.cyberduck.core.sftp.SFTPReadFeature) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) AttributedList(ch.cyberduck.core.AttributedList) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SFTPListService(ch.cyberduck.core.sftp.SFTPListService) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) SFTPHomeDirectoryService(ch.cyberduck.core.sftp.SFTPHomeDirectoryService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractSFTPTest(ch.cyberduck.core.sftp.AbstractSFTPTest)

Example 5 with CachingAttributesFinderFeature

use of ch.cyberduck.core.CachingAttributesFinderFeature in project cyberduck by iterate-ch.

the class SFTPAttributesFinderFeatureTest method testFindDefaultAttributesFinderWithCacheCryptomator.

@Test
public void testFindDefaultAttributesFinderWithCacheCryptomator() throws Exception {
    final Path home = new SFTPHomeDirectoryService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final CryptoVault cryptomator = new CryptoVault(vault);
    cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final Path test = new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new SFTPWriteFeature(session)), new SFTPWriteFeature(session), cryptomator).touch(new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    final Path found = new CryptoListService(session, new SFTPListService(session), cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test);
    assertEquals(0L, found.attributes().getSize());
    final Cache<Path> cache = new PathCache(1);
    final AttributedList<Path> list = new AttributedList<>();
    list.add(found);
    cache.put(vault, list);
    final PathAttributes attributes = new CachingAttributesFinderFeature(cache, new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator)).find(test);
    assertNotNull(attributes);
    assertEquals(0L, attributes.getSize());
    assertEquals(0L, cache.get(vault).get(0).attributes().getSize());
    cryptomator.getFeature(session, Delete.class, new SFTPDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) SFTPWriteFeature(ch.cyberduck.core.sftp.SFTPWriteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Path(ch.cyberduck.core.Path) PathCache(ch.cyberduck.core.PathCache) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) PathAttributes(ch.cyberduck.core.PathAttributes) SFTPDeleteFeature(ch.cyberduck.core.sftp.SFTPDeleteFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) DefaultTouchFeature(ch.cyberduck.core.shared.DefaultTouchFeature) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) AttributedList(ch.cyberduck.core.AttributedList) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SFTPListService(ch.cyberduck.core.sftp.SFTPListService) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) SFTPHomeDirectoryService(ch.cyberduck.core.sftp.SFTPHomeDirectoryService) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractSFTPTest(ch.cyberduck.core.sftp.AbstractSFTPTest)

Aggregations

CachingAttributesFinderFeature (ch.cyberduck.core.CachingAttributesFinderFeature)10 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)8 Path (ch.cyberduck.core.Path)8 PathCache (ch.cyberduck.core.PathCache)8 IntegrationTest (ch.cyberduck.test.IntegrationTest)8 Test (org.junit.Test)8 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)7 PathAttributes (ch.cyberduck.core.PathAttributes)7 Delete (ch.cyberduck.core.features.Delete)7 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)7 AttributesFinder (ch.cyberduck.core.features.AttributesFinder)5 DefaultAttributesFinderFeature (ch.cyberduck.core.shared.DefaultAttributesFinderFeature)5 AttributedList (ch.cyberduck.core.AttributedList)4 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)4 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)4 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)4 ListProgressListener (ch.cyberduck.core.ListProgressListener)4 CryptoAttributesFeature (ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature)4 CryptoListService (ch.cyberduck.core.cryptomator.features.CryptoListService)4 DefaultVaultRegistry (ch.cyberduck.core.vault.DefaultVaultRegistry)3