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