Search in sources :

Example 1 with PathCache

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

the class SearchWorkerTest method testRun.

@Test
public void testRun() throws Exception {
    final PathCache cache = new PathCache(Integer.MAX_VALUE);
    final AttributedList<Path> root = new AttributedList<>();
    root.add(new Path("/t1.png", EnumSet.of(Path.Type.file)));
    root.add(new Path("/t1.gif", EnumSet.of(Path.Type.file)));
    final Path folder = new Path("/folder", EnumSet.of(Path.Type.directory));
    root.add(folder);
    root.add(new Path("/folder2", EnumSet.of(Path.Type.directory)));
    cache.put(new Path("/", EnumSet.of(Path.Type.directory)), root);
    final AttributedList<Path> folderContents = new AttributedList<>();
    folderContents.add(new Path(folder, "/t2.png", EnumSet.of(Path.Type.file)));
    folderContents.add(new Path(folder, "/t2.gif", EnumSet.of(Path.Type.file)));
    final Path subfolder = new Path(folder, "/subfolder", EnumSet.of(Path.Type.directory));
    folderContents.add(subfolder);
    cache.put(folder, folderContents);
    final AttributedList<Path> subfolderContents = new AttributedList<>();
    subfolderContents.add(new Path(subfolder, "t2.png", EnumSet.of(Path.Type.file)));
    subfolderContents.add(new Path(subfolder, "t2.gif", EnumSet.of(Path.Type.file)));
    cache.put(subfolder, subfolderContents);
    final SearchWorker search = new SearchWorker(new Path("/", EnumSet.of(Path.Type.directory)), new SearchFilter(".png"), cache, new DisabledListProgressListener());
    final AttributedList<Path> found = search.run(new NullSession(new Host(new TestProtocol())));
    assertTrue(found.contains(new Path("/t1.png", EnumSet.of(Path.Type.file))));
    assertFalse(found.contains(new Path("/t1.gif", EnumSet.of(Path.Type.file))));
    assertFalse(found.contains(new Path("/t2.png", EnumSet.of(Path.Type.file))));
    assertFalse(found.contains(new Path("/t2.gif", EnumSet.of(Path.Type.file))));
    assertTrue(found.contains(folder));
    assertTrue(found.contains(new Path(folder, "/t2.png", EnumSet.of(Path.Type.file))));
    assertTrue(found.contains(subfolder));
    assertTrue(found.contains(new Path(subfolder, "/t2.png", EnumSet.of(Path.Type.file))));
    assertFalse(found.contains(new Path(new Path("/folder2", EnumSet.of(Path.Type.directory)), "/t2.gif", EnumSet.of(Path.Type.file))));
    assertFalse(found.contains(new Path("/folder2", EnumSet.of(Path.Type.directory))));
}
Also used : PathCache(ch.cyberduck.core.PathCache) Path(ch.cyberduck.core.Path) TestProtocol(ch.cyberduck.core.TestProtocol) AttributedList(ch.cyberduck.core.AttributedList) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) NullSession(ch.cyberduck.core.NullSession) SearchFilter(ch.cyberduck.ui.browser.SearchFilter) Host(ch.cyberduck.core.Host) Test(org.junit.Test)

Example 2 with PathCache

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

the class CachingFindFeatureTest method testFindDefault.

@Test
public void testFindDefault() throws Exception {
    final PathCache cache = new PathCache(1);
    final Path bucket = new Path("versioning-test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final String name = new AlphanumericRandomStringService().random();
    final CachingFindFeature f = new CachingFindFeature(cache, new DefaultFindFeature(session));
    assertFalse(f.find(new Path(bucket, name, EnumSet.of(Path.Type.file))));
    final Path test = new S3TouchFeature(session).touch(new Path(bucket, name, EnumSet.of(Path.Type.file)), new TransferStatus());
    assertFalse(f.find(test));
    cache.clear();
    assertTrue(f.find(test));
    // Find without version id set in attributes
    assertTrue(f.find(new Path(test).withAttributes(PathAttributes.EMPTY)));
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : PathCache(ch.cyberduck.core.PathCache) Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) S3TouchFeature(ch.cyberduck.core.s3.S3TouchFeature) S3DefaultDeleteFeature(ch.cyberduck.core.s3.S3DefaultDeleteFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) CachingFindFeature(ch.cyberduck.core.CachingFindFeature) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 3 with PathCache

use of ch.cyberduck.core.PathCache 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 4 with PathCache

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

the class SyncTransferTest method testFilterMirror.

@Test
public void testFilterMirror() throws Exception {
    final Path p = new Path("t", EnumSet.of(Path.Type.directory));
    final Path a = new Path(p, "a", EnumSet.of(Path.Type.file));
    final Path b = new Path(p, "b", EnumSet.of(Path.Type.file));
    final PathCache cache = new PathCache(1);
    cache.put(p, new AttributedList<>(Arrays.asList(a, b)));
    SyncTransfer t = new SyncTransfer(new Host(new TestProtocol()), new TransferItem(p, new NullLocal(System.getProperty("java.io.tmpdir"), "t")));
    t.withCache(cache);
    final NullSession session = new NullTransferSession(new Host(new TestProtocol()));
    final TransferPathFilter filter = t.filter(session, null, TransferAction.mirror, new DisabledProgressListener());
    assertTrue(filter.accept(a, new NullLocal(System.getProperty("java.io.tmpdir"), "a") {

        @Override
        public boolean exists() {
            return true;
        }

        @Override
        public LocalAttributes attributes() {
            return new LocalAttributes(this.getAbsolute()) {

                @Override
                public long getSize() {
                    return 1L;
                }
            };
        }
    }, new TransferStatus().exists(true)));
    assertTrue(filter.accept(b, new NullLocal(System.getProperty("java.io.tmpdir"), "b") {

        @Override
        public boolean exists() {
            return true;
        }

        @Override
        public LocalAttributes attributes() {
            return new LocalAttributes(this.getAbsolute()) {

                @Override
                public long getSize() {
                    return 0L;
                }
            };
        }
    }, new TransferStatus().exists(true)));
    assertEquals(Comparison.local, t.compare(new TransferItem(a, new NullLocal(System.getProperty("java.io.tmpdir"), "a"))));
    assertEquals(Comparison.remote, t.compare(new TransferItem(b, new NullLocal(System.getProperty("java.io.tmpdir"), "b"))));
}
Also used : Path(ch.cyberduck.core.Path) PathCache(ch.cyberduck.core.PathCache) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) TestProtocol(ch.cyberduck.core.TestProtocol) LocalAttributes(ch.cyberduck.core.LocalAttributes) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) NullTransferSession(ch.cyberduck.core.NullTransferSession) NullLocal(ch.cyberduck.core.NullLocal) Test(org.junit.Test)

Example 5 with PathCache

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

the class DriveWriteFeatureTest 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 = DriveHomeFinderService.MYDRIVE_FOLDER;
    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 DriveFileIdProvider fileid = new DriveFileIdProvider(session);
    final CryptoWriteFeature<File> writer = new CryptoWriteFeature<>(session, new DriveWriteFeature(session, fileid), 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 DriveFindFeature(session, fileid), cryptomator).find(test));
    final Path found = new CryptoListService(session, new DriveListService(session, fileid), cryptomator).list(test.getParent(), new DisabledListProgressListener()).find(new SimplePathPredicate(test));
    final String fileId = found.attributes().getFileId();
    assertNotNull(fileId);
    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());
    assertEquals(content.length, writer.append(test, status.withRemote(found.attributes())).size, 0L);
    {
        final PathAttributes attributes = new CryptoAttributesFeature(session, new DriveAttributesFinderFeature(session, fileid), cryptomator).find(test);
        assertEquals(content.length, attributes.getSize());
        assertEquals(fileId, found.attributes().getFileId());
    }
    {
        final PathAttributes attributes = new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(test);
        assertEquals(content.length, attributes.getSize());
        assertEquals(fileId, found.attributes().getFileId());
    }
    {
        final PathAttributes attributes = new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(test);
        assertEquals(content.length, attributes.getSize());
        assertEquals(fileId, found.attributes().getFileId());
    }
    assertEquals(content.length, cache.get(vault).get(0).attributes().getSize());
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final InputStream in = new CryptoReadFeature(session, new DriveReadFeature(session, fileid), 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 DriveDeleteFeature(session, fileid)).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) CryptoWriteFeature(ch.cyberduck.core.cryptomator.features.CryptoWriteFeature) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DriveReadFeature(ch.cyberduck.core.googledrive.DriveReadFeature) 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) DriveWriteFeature(ch.cyberduck.core.googledrive.DriveWriteFeature) DriveDeleteFeature(ch.cyberduck.core.googledrive.DriveDeleteFeature) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DriveAttributesFinderFeature(ch.cyberduck.core.googledrive.DriveAttributesFinderFeature) RandomNonceGenerator(ch.cyberduck.core.cryptomator.random.RandomNonceGenerator) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) DriveFindFeature(ch.cyberduck.core.googledrive.DriveFindFeature) AttributedList(ch.cyberduck.core.AttributedList) ByteArrayInputStream(java.io.ByteArrayInputStream) 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) File(com.google.api.services.drive.model.File) DriveFileIdProvider(ch.cyberduck.core.googledrive.DriveFileIdProvider) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDriveTest(ch.cyberduck.core.googledrive.AbstractDriveTest) Test(org.junit.Test)

Aggregations

Path (ch.cyberduck.core.Path)17 PathCache (ch.cyberduck.core.PathCache)17 Test (org.junit.Test)16 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)11 IntegrationTest (ch.cyberduck.test.IntegrationTest)11 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)10 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)10 Delete (ch.cyberduck.core.features.Delete)10 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)10 AttributedList (ch.cyberduck.core.AttributedList)9 CachingAttributesFinderFeature (ch.cyberduck.core.CachingAttributesFinderFeature)8 PathAttributes (ch.cyberduck.core.PathAttributes)7 Host (ch.cyberduck.core.Host)6 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)5 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)5 CryptoAttributesFeature (ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature)5 CryptoListService (ch.cyberduck.core.cryptomator.features.CryptoListService)5 ListProgressListener (ch.cyberduck.core.ListProgressListener)4 NullSession (ch.cyberduck.core.NullSession)4 TestProtocol (ch.cyberduck.core.TestProtocol)4