Search in sources :

Example 21 with PathAttributes

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

the class SDSListService method list.

protected AttributedList<Path> list(final Path directory, final ListProgressListener listener, final int chunksize) throws BackgroundException {
    final AttributedList<Path> children = new AttributedList<Path>();
    try {
        int offset = 0;
        final SDSAttributesAdapter feature = new SDSAttributesAdapter(session);
        NodeList nodes;
        do {
            nodes = new NodesApi(session.getClient()).requestNodes(null, 0, Long.parseLong(nodeid.getVersionId(directory, new DisabledListProgressListener())), false, null, "name:asc", offset, chunksize, StringUtils.EMPTY);
            for (Node node : nodes.getItems()) {
                final PathAttributes attributes = feature.toAttributes(node);
                final EnumSet<Path.Type> type = feature.toType(node);
                final Path file = new Path(directory, node.getName(), type, attributes);
                if (references && node.getCntDeletedVersions() != null && node.getCntDeletedVersions() > 0) {
                    try {
                        final AttributedList<Path> versions = new SDSAttributesFinderFeature(session, nodeid).findDeleted(file, chunksize);
                        children.addAll(versions);
                        attributes.setVersions(versions);
                    } catch (AccessDeniedException e) {
                        log.warn(String.format("Ignore failure %s fetching versions for %s", e, file));
                    }
                }
                children.add(file);
                listener.chunk(directory, children);
            }
            offset += chunksize;
        } while (nodes.getItems().size() == chunksize);
    } catch (ApiException e) {
        throw new SDSExceptionMappingService(nodeid).map("Listing directory {0} failed", e, directory);
    }
    return children;
}
Also used : Path(ch.cyberduck.core.Path) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) NodeList(ch.cyberduck.core.sds.io.swagger.client.model.NodeList) Node(ch.cyberduck.core.sds.io.swagger.client.model.Node) PathAttributes(ch.cyberduck.core.PathAttributes) NodesApi(ch.cyberduck.core.sds.io.swagger.client.api.NodesApi) AttributedList(ch.cyberduck.core.AttributedList) ApiException(ch.cyberduck.core.sds.io.swagger.client.ApiException)

Example 22 with PathAttributes

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

the class SDSMoveFeature method move.

@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException {
    try {
        final long nodeId = Long.parseLong(nodeid.getVersionId(file, new DisabledListProgressListener()));
        if (containerService.isContainer(file)) {
            final Node node = new NodesApi(session.getClient()).updateRoom(new UpdateRoomRequest().name(renamed.getName()), nodeId, StringUtils.EMPTY, null);
            nodeid.cache(renamed, file.attributes().getVersionId());
            nodeid.cache(file, null);
            return renamed.withAttributes(new SDSAttributesAdapter(session).toAttributes(node));
        } else {
            if (status.isExists()) {
                // Handle case insensitive. Find feature will have reported target to exist if same name with different case
                if (!new CaseInsensitivePathPredicate(file).test(renamed)) {
                    log.warn(String.format("Delete existing file %s", renamed));
                    new SDSDeleteFeature(session, nodeid).delete(Collections.singletonMap(renamed, status), connectionCallback, callback);
                }
            }
            if (new SimplePathPredicate(file.getParent()).test(renamed.getParent())) {
                // Rename only
                if (file.isDirectory()) {
                    new NodesApi(session.getClient()).updateFolder(new UpdateFolderRequest().name(renamed.getName()), nodeId, StringUtils.EMPTY, null);
                } else {
                    new NodesApi(session.getClient()).updateFile(new UpdateFileRequest().name(renamed.getName()), nodeId, StringUtils.EMPTY, null);
                }
            } else {
                // Move to different parent
                new NodesApi(session.getClient()).moveNodes(new MoveNodesRequest().resolutionStrategy(MoveNodesRequest.ResolutionStrategyEnum.OVERWRITE).addItemsItem(new MoveNode().id(nodeId).name(renamed.getName())).keepShareLinks(new HostPreferences(session.getHost()).getBoolean("sds.upload.sharelinks.keep")), Long.parseLong(nodeid.getVersionId(renamed.getParent(), new DisabledListProgressListener())), StringUtils.EMPTY, null);
            }
            nodeid.cache(renamed, file.attributes().getVersionId());
            nodeid.cache(file, null);
            // Copy original file attributes
            return renamed.withAttributes(new PathAttributes(file.attributes()).withVersionId(String.valueOf(nodeId)));
        }
    } catch (ApiException e) {
        throw new SDSExceptionMappingService(nodeid).map("Cannot rename {0}", e, file);
    }
}
Also used : CaseInsensitivePathPredicate(ch.cyberduck.core.CaseInsensitivePathPredicate) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) Node(ch.cyberduck.core.sds.io.swagger.client.model.Node) MoveNode(ch.cyberduck.core.sds.io.swagger.client.model.MoveNode) PathAttributes(ch.cyberduck.core.PathAttributes) MoveNode(ch.cyberduck.core.sds.io.swagger.client.model.MoveNode) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) NodesApi(ch.cyberduck.core.sds.io.swagger.client.api.NodesApi) UpdateRoomRequest(ch.cyberduck.core.sds.io.swagger.client.model.UpdateRoomRequest) MoveNodesRequest(ch.cyberduck.core.sds.io.swagger.client.model.MoveNodesRequest) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) UpdateFileRequest(ch.cyberduck.core.sds.io.swagger.client.model.UpdateFileRequest) UpdateFolderRequest(ch.cyberduck.core.sds.io.swagger.client.model.UpdateFolderRequest) ApiException(ch.cyberduck.core.sds.io.swagger.client.ApiException)

Example 23 with PathAttributes

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

the class SDSAttributesFinderFeatureTest method testFindRoom.

@Test
public void testFindRoom() throws Exception {
    final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session);
    final Path room = new SDSDirectoryFeature(session, nodeid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
    final PathAttributes attributes = new SDSAttributesFinderFeature(session, nodeid).find(room);
    assertNotEquals(PathAttributes.EMPTY, attributes);
    assertEquals(0L, attributes.getSize());
    assertNotEquals(-1L, attributes.getModificationDate());
    assertNull(attributes.getChecksum().algorithm);
    assertTrue(attributes.getPermission().isReadable());
    assertTrue(attributes.getPermission().isWritable());
    assertTrue(attributes.getPermission().isExecutable());
    new SDSDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) PathAttributes(ch.cyberduck.core.PathAttributes) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 24 with PathAttributes

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

the class SDSAttributesFinderFeatureTest method testVersioning.

@Test
public void testVersioning() throws Exception {
    final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session);
    final Path room = new SDSDirectoryFeature(session, nodeid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
    final Path folder = new SDSDirectoryFeature(session, nodeid).mkdir(new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
    final SDSAttributesFinderFeature f = new SDSAttributesFinderFeature(session, nodeid, true);
    final PathAttributes previous = f.find(folder, new DisabledListProgressListener(), 1);
    assertNotEquals(-1L, previous.getRevision().longValue());
    final Path test = new SDSTouchFeature(session, nodeid).touch(new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    final String initialVersion = test.attributes().getVersionId();
    assertEquals(test.getParent(), folder);
    assertTrue(new SDSFindFeature(session, nodeid).find(test));
    final byte[] content = RandomUtils.nextBytes(32769);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    final SDSMultipartWriteFeature writer = new SDSMultipartWriteFeature(session, nodeid);
    final StatusOutputStream<Node> out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    assertNotNull(test.attributes().getVersionId());
    assertNotEquals(initialVersion, test.attributes().getVersionId());
    final PathAttributes updated = new SDSAttributesFinderFeature(session, nodeid, true).find(test, new DisabledListProgressListener(), 1);
    assertFalse(updated.getVersions().isEmpty());
    assertEquals(previous.getModificationDate(), new SDSAttributesFinderFeature(session, nodeid).find(folder, new DisabledListProgressListener(), 1).getModificationDate());
    // Branch version is changing with background task only
    // assertNotEquals(previous.getRevision(), new SDSAttributesFinderFeature(session, nodeid).find(folder, 1).getRevision());
    new SDSDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) PathAttributes(ch.cyberduck.core.PathAttributes) Node(ch.cyberduck.core.sds.io.swagger.client.model.Node) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 25 with PathAttributes

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

the class SDSDirectS3MultipartWriteFeatureTest method testWriteEncrypted.

@Test
public void testWriteEncrypted() throws Exception {
    final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session);
    final Path room = new SDSDirectoryFeature(session, nodeid).createRoom(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), true);
    final byte[] content = RandomUtils.nextBytes(new HostPreferences(session.getHost()).getInteger("sds.upload.multipart.chunksize") + 1);
    final Path test = new Path(room, new NFDNormalizer().normalize(String.format("รค%s", new AlphanumericRandomStringService().random())).toString(), EnumSet.of(Path.Type.file));
    {
        final TripleCryptWriteFeature writer = new TripleCryptWriteFeature(session, nodeid, new SDSDirectS3MultipartWriteFeature(session, nodeid));
        final TransferStatus status = new TransferStatus();
        status.setLength(content.length);
        status.setChecksum(new MD5ChecksumCompute().compute(new ByteArrayInputStream(content), new TransferStatus()));
        status.setTimestamp(1632127025217L);
        final StatusOutputStream<Node> out = writer.write(test, status, new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    }
    assertNotNull(test.attributes().getVersionId());
    assertTrue(new DefaultFindFeature(session).find(test));
    assertTrue(new SDSFindFeature(session, nodeid).find(test));
    final PathAttributes attr = new SDSAttributesFinderFeature(session, nodeid).find(test);
    assertEquals(test.attributes().getVersionId(), attr.getVersionId());
    assertEquals(1632127025217L, attr.getModificationDate());
    assertEquals(1632127025217L, new DefaultAttributesFinderFeature(session).find(test).getModificationDate());
    final byte[] compare = new byte[content.length];
    final InputStream stream = new TripleCryptReadFeature(session, nodeid, new SDSReadFeature(session, nodeid)).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) {
            return new VaultCredentials("eth[oh8uv4Eesij");
        }
    });
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    String previousVersion = test.attributes().getVersionId();
    // Overwrite
    {
        final byte[] change = RandomUtils.nextBytes(256);
        final TransferStatus status = new TransferStatus();
        status.setLength(change.length);
        final TripleCryptWriteFeature writer = new TripleCryptWriteFeature(session, nodeid, new SDSDirectS3MultipartWriteFeature(session, nodeid));
        final StatusOutputStream<Node> out = writer.write(test, status.exists(true), new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(status, status).transfer(new ByteArrayInputStream(change), out);
        assertNotEquals(test.attributes().getVersionId(), out.getStatus());
    }
    assertNotEquals(attr.getRevision(), new SDSAttributesFinderFeature(session, nodeid).find(test));
    // Read with previous version must fail
    try {
        test.attributes().withVersionId(previousVersion);
        new TripleCryptReadFeature(session, nodeid, new SDSReadFeature(session, nodeid)).read(test, new TransferStatus(), new DisabledConnectionCallback() {

            @Override
            public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) {
                return new VaultCredentials("eth[oh8uv4Eesij");
            }
        });
        fail();
    } catch (NotfoundException e) {
    // Expected
    }
    new SDSDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Delete(ch.cyberduck.core.features.Delete) LoginOptions(ch.cyberduck.core.LoginOptions) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) TripleCryptWriteFeature(ch.cyberduck.core.sds.triplecrypt.TripleCryptWriteFeature) Path(ch.cyberduck.core.Path) NotfoundException(ch.cyberduck.core.exception.NotfoundException) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) Host(ch.cyberduck.core.Host) TripleCryptReadFeature(ch.cyberduck.core.sds.triplecrypt.TripleCryptReadFeature) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) MD5ChecksumCompute(ch.cyberduck.core.io.MD5ChecksumCompute) NFDNormalizer(ch.cyberduck.core.unicode.NFDNormalizer) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) Credentials(ch.cyberduck.core.Credentials) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

PathAttributes (ch.cyberduck.core.PathAttributes)291 Path (ch.cyberduck.core.Path)233 Test (org.junit.Test)200 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)176 IntegrationTest (ch.cyberduck.test.IntegrationTest)175 Delete (ch.cyberduck.core.features.Delete)153 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)143 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)139 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)74 ByteArrayInputStream (java.io.ByteArrayInputStream)55 StreamCopier (ch.cyberduck.core.io.StreamCopier)49 InputStream (java.io.InputStream)49 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)45 NotfoundException (ch.cyberduck.core.exception.NotfoundException)45 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)41 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)36 AttributedList (ch.cyberduck.core.AttributedList)34 Local (ch.cyberduck.core.Local)32 Host (ch.cyberduck.core.Host)31 OutputStream (java.io.OutputStream)31