public Path(final Path copy) { this.parent = copy.parent; this.path = copy.path; this.symlink = copy.symlink; this.type = EnumSet.copyOf(copy.type); this.attributes = new PathAttributes(copy.attributes); }
/** * @param absolute The absolute path of the remote file * @param type File type */ public Path(final String absolute, final EnumSet<Type> type) { this.type = type; this.attributes = new PathAttributes(); this.setPath(absolute); }
public CryptoVault(final Path home, final String masterkey, final byte[] pepper) { this.home = home; this.masterkey = new Path(home, masterkey, EnumSet.of(Path.Type.file, Path.Type.vault)); this.pepper = pepper; // New vault home with vault flag set for internal use final EnumSet<AbstractPath.Type> type = EnumSet.copyOf(home.getType()); type.add(Path.Type.vault); final Path vault = new Path(home.getAbsolute(), type, new PathAttributes(home.attributes())); this.filenameProvider = new CryptoFilenameProvider(vault); this.directoryProvider = new CryptoDirectoryProvider(vault, this); }
/** * @param parent the absolute directory * @param name the file relative to param path * @param type File type */ public Path(final Path parent, final String name, final EnumSet<Type> type) { this.type = type; this.attributes = new PathAttributes(); this.attributes.setRegion(parent.attributes.getRegion()); this._setPath(parent, name); }
protected PathAttributes toAttributes(final Metadata metadata) { final PathAttributes attributes = new PathAttributes(); if(metadata instanceof FileMetadata) { final FileMetadata fm = (FileMetadata) metadata; attributes.setSize(fm.getSize()); attributes.setModificationDate(fm.getClientModified().getTime()); } return attributes; } }
protected PathAttributes toAttributes(final B2FileResponse response) { final PathAttributes attributes = new PathAttributes(); attributes.setSize(response.getContentLength()); if(response.getFileInfo().containsKey(X_BZ_INFO_LARGE_FILE_SHA1)) { attributes.setChecksum(Checksum.parse(response.getFileInfo().get(X_BZ_INFO_LARGE_FILE_SHA1))); } else { attributes.setChecksum(Checksum.parse(StringUtils.removeStart(StringUtils.lowerCase(response.getContentSha1(), Locale.ROOT), "unverified:"))); } final Map<String, String> metadata = new HashMap<>(); for(Map.Entry<String, String> entry : response.getFileInfo().entrySet()) { metadata.put(entry.getKey(), entry.getValue()); } attributes.setMetadata(metadata); attributes.setVersionId(response.getFileId()); if(response.getFileInfo().containsKey(X_BZ_INFO_SRC_LAST_MODIFIED_MILLIS)) { attributes.setModificationDate(Long.valueOf(response.getFileInfo().get(X_BZ_INFO_SRC_LAST_MODIFIED_MILLIS))); } return attributes; }
protected final AttributedList<Path> iterate(final Iterator<OneDriveDrive.Metadata> iterator, final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> children = new AttributedList<>(); while(iterator.hasNext()) { final OneDriveDrive.Metadata metadata; try { metadata = iterator.next(); } catch(OneDriveRuntimeException e) { log.warn(e.getMessage()); continue; } final PathAttributes attributes = new PathAttributes(); attributes.setVersionId(metadata.getId()); attributes.setSize(metadata.getTotal()); String name = metadata.getName(); if(StringUtils.isBlank(metadata.getName())) { name = metadata.getId(); } children.add(new Path(directory, name, EnumSet.of(Path.Type.directory, Path.Type.volume), attributes)); listener.chunk(directory, children); } return children; }
@Override public Path move(final Path file, final Path renamed, TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException { try { if(status.isExists()) { delete.delete(Collections.singletonList(renamed), connectionCallback, callback); } session.sftp().rename(file.getAbsolute(), renamed.getAbsolute()); // Copy original file attributes return new Path(renamed.getParent(), renamed.getName(), renamed.getType(), new PathAttributes(file.attributes())); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Cannot rename {0}", e, file); } }
public PathAttributes toAttributes(final Node node) throws BackgroundException { final PathAttributes attributes = new PathAttributes(); attributes.setVersionId(String.valueOf(node.getId())); attributes.setRevision(node.getBranchVersion()); attributes.setChecksum(Checksum.parse(node.getHash())); attributes.setCreationDate(node.getCreatedAt() != null ? node.getCreatedAt().getMillis() : -1L); attributes.setModificationDate(node.getUpdatedAt() != null ? node.getUpdatedAt().getMillis() : -1L); attributes.setSize(node.getSize()); attributes.setPermission(this.toPermission(node)); attributes.setAcl(this.toAcl(node)); final Map<String, String> custom = new HashMap<>(); if(null != node.getCntDownloadShares()) { custom.put(SDSAttributesFinderFeature.KEY_CNT_DOWNLOADSHARES, String.valueOf(node.getCntDownloadShares())); } if(null != node.getCntUploadShares()) { custom.put(SDSAttributesFinderFeature.KEY_CNT_UPLOADSHARES, String.valueOf(node.getCntUploadShares())); } custom.put(SDSAttributesFinderFeature.KEY_ENCRYPTED, String.valueOf(node.getIsEncrypted())); attributes.setCustom(custom); return attributes; }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { try { if(nodeid.isEncrypted(file)) { nodeid.setFileKey(status); } final StatusOutputStream<VersionId> out = writer.write(file, status, new DisabledConnectionCallback()); out.close(); return new Path(file.getParent(), file.getName(), file.getType(), new PathAttributes(file.attributes()).withVersionId(out.getStatus().id)); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot create file {0}", e, file); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> children = new AttributedList<>(); final GroupsIterator groupsIterator = new GroupsIterator(session.getClient()); while(groupsIterator.hasNext()) { final GroupItem.Metadata metadata; try { metadata = groupsIterator.next(); } catch(OneDriveRuntimeException e) { log.warn(e.getMessage()); continue; } final PathAttributes attributes = new PathAttributes(); attributes.setVersionId(metadata.getId()); children.add(new Path(directory, metadata.getDisplayName(), EnumSet.of(Path.Type.directory, Path.Type.volume), attributes)); listener.chunk(directory, children); } return children; }
@Override public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException { try { if(status.isExists()) { delete.delete(Collections.singletonList(renamed), connectionCallback, callback); } if(!session.getClient().rename(file.getAbsolute(), renamed.getAbsolute())) { throw new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString()); } // Copy original file attributes return new Path(renamed.getParent(), renamed.getName(), renamed.getType(), new PathAttributes(file.attributes())); } catch(IOException e) { throw new FTPExceptionMappingService().map("Cannot rename {0}", e, file); } }
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } if(file.getType().contains(Path.Type.upload)) { return PathAttributes.EMPTY; } if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); attributes.setRegion(new S3LocationFeature(session, session.getClient().getRegionEndpointCache()).getLocation(file).getIdentifier()); return attributes; } return this.toAttributes(this.details(file)); }
@Override public PathAttributes find(final Path file) throws BackgroundException { final PathAttributes attributes = new PathAttributes(delegate.withCache(new CryptoPathCache(cache)).find(vault.encrypt(session, file))); if(file.isFile()) { attributes.setSize(vault.toCleartextSize(attributes.getSize())); } return attributes; }
@Override public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback deleteCallback, final ConnectionCallback connectionCallback) throws BackgroundException { try { session.getClient().move(file.getAbsolute(), renamed.getAbsolute()); // Copy original file attributes return new Path(renamed.getParent(), renamed.getName(), renamed.getType(), new PathAttributes(file.attributes())); } catch(MantaException e) { throw new MantaExceptionMappingService().map("Cannot rename {0}", e, file); } catch(MantaClientHttpResponseException e) { throw new MantaHttpExceptionMappingService().map("Cannot rename {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot rename {0}", e, file); } }
@Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { InputStream in; StatusOutputStream out; in = from.getFeature(Read.class).read(source, new TransferStatus(status), callback); Write write = to.getFeature(MultipartWrite.class); if(null == write) { // Fallback if multipart write is not available write = to.getFeature(Write.class); } out = write.write(target, status, callback); new StreamCopier(status, status).transfer(in, out); final Object reply = out.getStatus(); if(reply instanceof VersionId) { return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(target.attributes()).withVersionId(((VersionId) reply).id)); } return target; }
@Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { session.getClient().copyObject(regionService.lookup(source), containerService.getContainer(source).getName(), containerService.getKey(source), containerService.getContainer(target).getName(), containerService.getKey(target)); // Copy original file attributes return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(source.attributes())); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Cannot copy {0}", e, source); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot copy {0}", e, source); } }
@Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final File copy = session.getClient().files().copy(fileid.getFileid(source, new DisabledListProgressListener()), new File() .setParents(Collections.singletonList(fileid.getFileid(target.getParent(), new DisabledListProgressListener()))) .setName(target.getName())) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(target.attributes()).withVersionId(copy.getId())); } catch(IOException e) { throw new DriveExceptionMappingService().map("Cannot copy {0}", e, source); } }
@Override public PathAttributes find(final Path file) throws BackgroundException { try { final IRODSFileSystemAO fs = session.getClient(); final IRODSFile f = fs.getIRODSFileFactory().instanceIRODSFile(file.getAbsolute()); if(!f.exists()) { throw new NotfoundException(file.getAbsolute()); } final PathAttributes attributes = new PathAttributes(); final ObjStat stats = fs.getObjStat(f.getAbsolutePath()); attributes.setModificationDate(stats.getModifiedAt().getTime()); attributes.setCreationDate(stats.getCreatedAt().getTime()); attributes.setSize(stats.getObjSize()); attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(stats.getChecksum())))); attributes.setOwner(stats.getOwnerName()); attributes.setGroup(stats.getOwnerZone()); return attributes; } catch(JargonException e) { throw new IRODSExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } }
@Override public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException { try { final String target = new DefaultUrlProvider(session.getHost()).toUrl(renamed).find(DescriptiveUrl.Type.provider).getUrl(); if(file.isDirectory()) { session.getClient().move(new DAVPathEncoder().encode(file), String.format("%s/", target), true); } else { session.getClient().move(new DAVPathEncoder().encode(file), target, true); } // Copy original file attributes return new Path(renamed.getParent(), renamed.getName(), renamed.getType(), new PathAttributes(file.attributes())); } catch(SardineException e) { throw new DAVExceptionMappingService().map("Cannot rename {0}", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, file); } }