use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class BrickAttributesFinderFeatureTest method testFindFile.
@Test
public void testFindFile() throws Exception {
final Path folder = new BrickDirectoryFeature(session).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
final Path test = new BrickTouchFeature(session).touch(new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
final BrickAttributesFinderFeature f = new BrickAttributesFinderFeature(session);
final PathAttributes attributes = f.find(test);
assertEquals(0L, attributes.getSize());
assertNotEquals(-1L, attributes.getModificationDate());
assertNull(attributes.getChecksum().algorithm);
assertTrue(attributes.getPermission().isReadable());
assertTrue(attributes.getPermission().isWritable());
// Test wrong type
try {
f.find(new Path(test.getAbsolute(), EnumSet.of(Path.Type.directory)));
fail();
} catch (NotfoundException e) {
// Expected
}
new BrickDeleteFeature(session).delete(Collections.singletonList(folder), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class BrickAttributesFinderFeatureTest method testFindRoot.
@Test
public void testFindRoot() throws Exception {
final BrickAttributesFinderFeature f = new BrickAttributesFinderFeature(session);
final PathAttributes attributes = f.find(new Path("/", EnumSet.of(Path.Type.volume, Path.Type.directory)));
assertNotEquals(PathAttributes.EMPTY, attributes);
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class BoxAttributesFinderFeatureTest method testFindDirectory.
@Test
public void testFindDirectory() throws Exception {
final BoxFileidProvider fileid = new BoxFileidProvider(session);
final Path folder = new BoxDirectoryFeature(session, fileid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
final Path test = new BoxDirectoryFeature(session, fileid).mkdir(new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
final BoxAttributesFinderFeature f = new BoxAttributesFinderFeature(session, fileid);
final PathAttributes attributes = f.find(test);
assertNotEquals(-1L, attributes.getSize());
assertNotEquals(-1L, attributes.getModificationDate());
assertNull(attributes.getChecksum().algorithm);
assertNull(attributes.getETag());
assertTrue(attributes.getPermission().isReadable());
assertTrue(attributes.getPermission().isWritable());
assertTrue(attributes.getPermission().isExecutable());
// Test wrong type
try {
f.find(new Path(test.getAbsolute(), EnumSet.of(Path.Type.file)));
fail();
} catch (NotfoundException e) {
// Expected
}
new BoxDeleteFeature(session, fileid).delete(Collections.singletonList(folder), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class BoxAttributesFinderFeatureTest method testFindFile.
@Test
public void testFindFile() throws Exception {
final BoxFileidProvider fileid = new BoxFileidProvider(session);
final Path folder = new BoxDirectoryFeature(session, fileid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
final Path test = new BoxTouchFeature(session, fileid).touch(new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus().withLength(0L));
final BoxAttributesFinderFeature f = new BoxAttributesFinderFeature(session, fileid);
final PathAttributes attributes = f.find(test);
assertEquals(0L, attributes.getSize());
assertNotEquals(-1L, attributes.getModificationDate());
assertNotNull(attributes.getFileId());
assertNotNull(attributes.getETag());
assertNotNull(attributes.getChecksum().algorithm);
assertTrue(attributes.getPermission().isReadable());
assertTrue(attributes.getPermission().isWritable());
// Test wrong type
try {
f.find(new Path(test.getAbsolute(), EnumSet.of(Path.Type.directory)));
fail();
} catch (NotfoundException e) {
// Expected
}
new BoxDeleteFeature(session, fileid).delete(Collections.singletonList(folder), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.PathAttributes in project cyberduck by iterate-ch.
the class PathAttributesDictionary method deserialize.
public <T> PathAttributes deserialize(T serialized) {
final Deserializer dict = factory.create(serialized);
final PathAttributes attributes = new PathAttributes();
final String sizeObj = dict.stringForKey("Size");
if (sizeObj != null) {
attributes.setSize(Long.parseLong(sizeObj));
}
final String quotaObj = dict.stringForKey("Quota");
if (quotaObj != null) {
attributes.setQuota(Long.parseLong(quotaObj));
}
final String modifiedObj = dict.stringForKey("Modified");
if (modifiedObj != null) {
attributes.setModificationDate(Long.parseLong(modifiedObj));
}
final String createdObj = dict.stringForKey("Created");
if (createdObj != null) {
attributes.setCreationDate(Long.parseLong(createdObj));
}
final String revisionObj = dict.stringForKey("Revision");
if (revisionObj != null) {
attributes.setRevision(Long.parseLong(revisionObj));
}
final List<T> versionsObj = dict.listForKey("Versions");
if (versionsObj != null) {
final AttributedList<Path> versions = new AttributedList<>();
for (T versionDict : versionsObj) {
versions.add(new PathDictionary(factory).deserialize(versionDict));
}
attributes.setVersions(versions);
}
final String etagObj = dict.stringForKey("ETag");
if (etagObj != null) {
attributes.setETag(etagObj);
}
final Object permissionObj = dict.objectForKey("Permission");
if (permissionObj != null) {
attributes.setPermission(new PermissionDictionary().deserialize(permissionObj));
}
final Object aclObj = dict.objectForKey("Acl");
if (aclObj != null) {
attributes.setAcl(new AclDictionary().deserialize(aclObj));
}
if (dict.mapForKey("Link") != null) {
final Map<String, String> link = dict.mapForKey("Link");
attributes.setLink(new DescriptiveUrl(URI.create(link.get("Url")), DescriptiveUrl.Type.valueOf(link.get("Type"))));
} else {
final String linkObj = dict.stringForKey("Link");
if (linkObj != null) {
attributes.setLink(new DescriptiveUrl(URI.create(linkObj), DescriptiveUrl.Type.http));
}
}
if (dict.mapForKey("Checksum") != null) {
final Map<String, String> checksum = dict.mapForKey("Checksum");
attributes.setChecksum(new Checksum(HashAlgorithm.valueOf(checksum.get("Algorithm")), checksum.get("Hash")));
} else {
attributes.setChecksum(Checksum.parse(dict.stringForKey("Checksum")));
}
attributes.setVersionId(dict.stringForKey("Version"));
attributes.setFileId(dict.stringForKey("File Id"));
attributes.setLockId(dict.stringForKey("Lock Id"));
final String duplicateObj = dict.stringForKey("Duplicate");
if (duplicateObj != null) {
attributes.setDuplicate(Boolean.parseBoolean(duplicateObj));
}
final String hiddenObj = dict.stringForKey("Hidden");
if (hiddenObj != null) {
attributes.setHidden(Boolean.parseBoolean(hiddenObj));
}
attributes.setMetadata(Collections.emptyMap());
attributes.setRegion(dict.stringForKey("Region"));
attributes.setStorageClass(dict.stringForKey("Storage Class"));
final Object vaultObj = dict.objectForKey("Vault");
if (vaultObj != null) {
attributes.setVault(new PathDictionary(factory).deserialize(vaultObj));
}
final Map<String, String> customObj = dict.mapForKey("Custom");
if (customObj != null) {
attributes.setCustom(customObj);
}
return attributes;
}
Aggregations