@Override public boolean accept(final Path file) { if(file.getName().toLowerCase(Locale.ROOT).contains(input.toLowerCase(Locale.ROOT))) { // Matching filename return true; } if(StringUtils.isNotBlank(file.attributes().getVersionId())) { if(file.attributes().getVersionId().toLowerCase(Locale.ROOT).contains(input.toLowerCase(Locale.ROOT))) { // Matching version return true; } } return false; }
@Override protected int compareFirst(final Path p1, final Path p2) { if(StringUtils.isBlank(p1.attributes().getVersionId()) && StringUtils.isBlank(p2.attributes().getVersionId())) { return 0; } if(StringUtils.isBlank(p1.attributes().getVersionId())) { return -1; } if(StringUtils.isBlank(p2.attributes().getVersionId())) { return 1; } if(ascending) { return p1.attributes().getVersionId().compareToIgnoreCase(p2.attributes().getVersionId()); } return -p1.attributes().getVersionId().compareToIgnoreCase(p2.attributes().getVersionId()); }
@Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot()) { return null; } return new S3AttributesFinderFeature(session).find(file).getVersionId(); }
@Override public String getTooltip(final Path file) { final StringBuilder tooltip = new StringBuilder(file.getAbsolute()); final Checksum checksum = file.attributes().getChecksum(); if(Checksum.NONE != checksum) { tooltip.append("\n").append(String.format("%s %s", StringUtils.upperCase(checksum.algorithm.name()), checksum.hash)); } if(StringUtils.isNotBlank(file.attributes().getVersionId())) { tooltip.append("\n").append(file.attributes().getVersionId()); } return tooltip.toString(); } }
@Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } final AttributedList<Path> list = session._getFeature(ListService.class).list(file.getParent(), listener); final Path found = list.find(new SimplePathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); }
protected String copy(final Path source, final S3Object destination, final TransferStatus status) throws BackgroundException { try { // Copying object applying the metadata of the original final Map<String, Object> stringObjectMap = session.getClient().copyVersionedObject(source.attributes().getVersionId(), containerService.getContainer(source).getName(), containerService.getKey(source), destination.getBucketName(), destination, false); final Map complete = (Map) stringObjectMap.get(Constants.KEY_FOR_COMPLETE_METADATA); return (String) complete.get(Constants.AMZ_VERSION_ID); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot copy {0}", e, source); } }
public DefaultPathPredicate(final Path file) { final Path.Type type = file.isSymbolicLink() ? Path.Type.symboliclink : file.isFile() ? Path.Type.file : Path.Type.directory; String qualifier = StringUtils.EMPTY; if(StringUtils.isNotBlank(file.attributes().getRegion())) { if(new PathContainerService().isContainer(file)) { qualifier += file.attributes().getRegion(); } } if(file.isFile()) { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { qualifier += file.attributes().getVersionId(); } } final String path = file.getAbsolute(); reference = "[" + type + "]" + "-" + qualifier + path; }
@Override public DescriptiveUrlBag toUrl(final Path file) { final String nodeid = file.isDirectory() ? file.attributes().getVersionId() : file.getParent().attributes().getVersionId(); if(StringUtils.isBlank(nodeid)) { return DescriptiveUrlBag.empty(); } return new DescriptiveUrlBag(Collections.singletonList( new DescriptiveUrl(URI.create(String.format("%s/#/node/%s", new HostUrlProvider().withUsername(false).get(session.getHost()), URIEncoder.encode( nodeid ))), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), session.getHost().getProtocol().getScheme().toString().toUpperCase(Locale.ROOT))) )); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final GroupItem group = new GroupItem(session.getClient(), directory.attributes().getVersionId()); final GroupDrivesIterator iterator = new GroupDrivesIterator(session.getClient(), group); return this.iterate(iterator, directory, listener); }
@Override public InputStream open() throws IOException { try { return session.getClient().getObjectImpl( false, containerService.getContainer(file).getName(), containerService.getKey(file), null, null, null, null, null, null, file.attributes().getVersionId(), new HashMap<String, Object>(), chunk.getParameters()) .getDataInputStream(); } catch(ServiceException e) { throw new IOException(e.getMessage(), e); } } });
@Override public MultipartPart call() throws BackgroundException { try { final HttpRange range = HttpRange.byLength(offset, length); final MultipartPart part = session.getClient().multipartUploadPartCopy(multipart, partNumber, containerService.getContainer(source).getName(), containerService.getKey(source), null, null, null, null, range.getStart(), range.getEnd(), source.attributes().getVersionId()); if(log.isInfoEnabled()) { log.info(String.format("Received response %s for part number %d", part, partNumber)); } // Populate part with response data that is accessible via the object's metadata return new MultipartPart(partNumber, null == part.getLastModified() ? new Date(System.currentTimeMillis()) : part.getLastModified(), null == part.getEtag() ? StringUtils.EMPTY : part.getEtag(), part.getSize()); } catch(S3ServiceException e) { throw new S3ExceptionMappingService().map("Cannot copy {0}", e, source); } } });
if(StringUtils.isNotBlank(file.attributes().getVersionId())) { attributes += file.attributes().getVersionId();
@Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); throw new NotfoundException(file.getAbsolute()); return this.set(file, found.attributes().getVersionId()); throw new NotfoundException(file.getAbsolute()); return this.set(file, found.attributes().getVersionId());
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final HttpRange range = HttpRange.withStatus(status); final RequestEntityRestStorageService client = session.getClient(); final S3Object object = client.getVersionedObject( file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file), null, // ifModifiedSince null, // ifUnmodifiedSince null, // ifMatch null, // ifNoneMatch status.isAppend() ? range.getStart() : null, status.isAppend() ? (range.getEnd() == -1 ? null : range.getEnd()) : null); if(log.isDebugEnabled()) { log.debug(String.format("Reading stream with content length %d", object.getContentLength())); } return object.getDataInputStream(); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Download {0} failed", e, file); } }
protected StorageObject details(final Path file) throws BackgroundException { final String container = containerService.getContainer(file).getName(); try { return session.getClient().getVersionedObjectDetails(file.attributes().getVersionId(), container, containerService.getKey(file)); final S3Object object = session.getClient().getVersionedObject(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file)); IOUtils.closeQuietly(object.getDataInputStream());
multipartService.delete(new MultipartUpload(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file));
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { final String directoryId = random.random(); final Path encrypt = vault.encrypt(session, folder, directoryId, false); // Create metadata file for directory final Path directoryMetadataFile = vault.encrypt(session, folder, true); if(log.isDebugEnabled()) { log.debug(String.format("Write metadata %s for folder %s", directoryMetadataFile, folder)); } new ContentWriter(session).write(directoryMetadataFile, directoryId.getBytes(Charset.forName("UTF-8"))); final Path intermediate = encrypt.getParent(); if(!session._getFeature(Find.class).find(intermediate)) { session._getFeature(Directory.class).mkdir(intermediate, region, new TransferStatus()); } // Write header final Cryptor cryptor = vault.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); status.setNonces(new RandomNonceGenerator()); final Path target = proxy.mkdir(encrypt, region, status); // Implementation may return new copy of attributes without encryption attributes target.attributes().setDirectoryId(directoryId); target.attributes().setDecrypted(encrypt.attributes().getDecrypted()); // Make reference of encrypted path in attributes of decrypted file point to metadata file final Path decrypt = vault.decrypt(session, vault.encrypt(session, target, true)); decrypt.attributes().setVersionId(target.attributes().getVersionId()); return decrypt; }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { // Write header final Cryptor cryptor = vault.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); status.setNonces(new RandomNonceGenerator()); final Path target = proxy.touch(vault.encrypt(session, file), status); final Path decrypt = vault.decrypt(session, target); decrypt.attributes().withVersionId(target.attributes().getVersionId()); return decrypt; }
session.getClient().copyVersionedObject(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file), containerService.getContainer(file).getName(), destination, false); if(file.getParent().attributes().getCustom().containsKey(S3VersionedObjectListService.KEY_DELETE_MARKER)) { file.getParent().attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file.getParent()));
return this.convert(session.getClient().getVersionedObjectAcl(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file)));