private Path inflate(final Session<?> session, final Path file) throws BackgroundException { final String fileName = file.getName(); if(filenameProvider.isDeflated(fileName)) { final String filename = filenameProvider.inflate(session, fileName); return new Path(file.getParent(), filename, EnumSet.of(Path.Type.file), file.attributes()); } return file; }
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); }
public String encode(final Path file) { final String encoded = URIEncoder.encode(file.getAbsolute()); if(file.isDirectory()) { if(file.isRoot()) { return encoded; } return String.format("%s/", encoded); } return encoded; } }
public SimplePathPredicate(final Path file) { this.file = file; this.type = file.isSymbolicLink() ? Path.Type.symboliclink : file.isFile() ? Path.Type.file : Path.Type.directory; this.path = file.getAbsolute(); }
private Path buildNormalizedHomePath(final String rawHomePath) { final String defaultPath = StringUtils.defaultIfBlank(rawHomePath, Path.HOME); final String accountRootRegex = String.format("^/?(%s|~~?)/?", accountRoot.getAbsolute()); final String subdirectoryRawPath = defaultPath.replaceFirst(accountRootRegex, ""); if(StringUtils.isEmpty(subdirectoryRawPath)) { return accountRoot; } final String[] subdirectoryPathSegments = StringUtils.split(subdirectoryRawPath, Path.DELIMITER); Path homePath = accountRoot; for(final String pathSegment : subdirectoryPathSegments) { EnumSet<Path.Type> types = EnumSet.of(Path.Type.directory); if(homePath.getParent().equals(accountRoot) && StringUtils.equalsAny(pathSegment, HOME_PATH_PRIVATE, HOME_PATH_PUBLIC)) { types.add(Path.Type.volume); } homePath = new Path(homePath, pathSegment, types); } return homePath; }
protected Path expand(final Path remote, final String format) { if(remote.getAbsolute().startsWith(format)) { return new Path(StringUtils.replaceOnce(remote.getAbsolute(), format, workdir.getAbsolute()), remote.getType()); } return remote; } }
@Override public Permission getUnixPermission(final Path file) throws BackgroundException { try { return new FTPAttributesFinderFeature(session).find(file).getPermission(); } catch(InteroperabilityException e) { for(Path f : session.getFeature(ListService.class).list(file.getParent(), new DisabledListProgressListener())) { if(f.equals(file)) { return f.attributes().getPermission(); } } } throw new NotfoundException(file.getAbsolute()); }
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 Path getContainer(final Path file) { if(file.isRoot()) { return file; } Path previous = file; Path parent = file.getParent(); while(!parent.isRoot()) { if(SharepointListService.DEFAULT_NAME.equals(parent.getParent())) { return parent; } else if(SharepointListService.GROUPS_NAME.equals(parent.getParent())) { return previous; } previous = parent; parent = parent.getParent(); } return file; } }
@Override public String getKind(final Path file) { if(file.isFile()) { return this.getKind(file.getName()); } if(file.isDirectory()) { return LocaleFactory.localizedString("Folder"); } return LocaleFactory.localizedString("Unknown"); }
private List<Path> findObjectsAsPaths(final Path workdir, final Predicate<MantaObject> searchPredicate) { return session.getClient().find(workdir.getAbsolute(), searchPredicate) .map(adapter::toPath) .collect(Collectors.toList()); }
protected void write(final Session<?> session, final Redundancy feature, final Path file) throws BackgroundException { if(this.isCanceled()) { throw new ConnectionCanceledException(); } if(!level.equals(file.attributes().getStorageClass())) { listener.message(MessageFormat.format(LocaleFactory.localizedString("Writing metadata of {0}", "Status"), file.getName())); feature.setClass(file, level); } if(file.isDirectory()) { if(callback.recurse(file, level)) { for(Path child : session.getFeature(ListService.class).list(file, new WorkerListProgressListener(this, listener))) { this.write(session, feature, child); } } } }
@Override public String getKey(final Path file) { final String key = super.getKey(file); if(!file.isRoot() && !this.isContainer(file) && file.isDirectory()) { return key.concat(String.valueOf(Path.DELIMITER)); } return key; } }
@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))) )); } }
@Action public void pathPopupSelectionChanged(final NSPopUpButton sender) { final String selected = sender.selectedItem().representedObject(); if(selected != null) { final Path workdir = this.workdir(); Path p = workdir; while(!p.getAbsolute().equals(selected)) { p = p.getParent(); } this.setWorkdir(p); if(workdir.getParent().equals(p)) { this.setWorkdir(p, workdir); } else { this.setWorkdir(p); } } }
@Override public int compare(final Path o1, final Path o2) { if(o1.isDirectory() && o2.isDirectory()) { return 0; } if(o1.isFile() && o2.isFile()) { return 0; } if(o1.isDirectory()) { return -1; } if(o2.isDirectory()) { return 1; } return 0; } }
public Path resolve(final String filename) { // Intermediate directory final Path first = new Path(metadataRoot, filename.substring(0, 2), metadataRoot.getType()); // Intermediate directory final Path second = new Path(first, filename.substring(2, 4), metadataRoot.getType()); return new Path(second, filename, EnumSet.of(Path.Type.file, Path.Type.encrypted, Path.Type.vault)); }