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;
}
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());
}
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();
}
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());
}
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());
}
Aggregations