protected PathAttributes toAttributes(final ObjectMetadata metadata) { final PathAttributes attributes = new PathAttributes(); attributes.setSize(Long.valueOf(metadata.getContentLength())); final String lastModified = metadata.getLastModified(); try { attributes.setModificationDate(rfc1123DateFormatter.parse(lastModified).getTime()); } catch(InvalidDateException e) { log.warn(String.format("%s is not RFC 1123 format %s", lastModified, e.getMessage())); } if(StringUtils.isNotBlank(metadata.getETag())) { final String etag = StringUtils.removePattern(metadata.getETag(), "\""); attributes.setETag(etag); if(metadata.getMetaData().containsKey(Constants.X_STATIC_LARGE_OBJECT)) { // For manifest files, the ETag in the response for a GET or HEAD on the manifest file is the MD5 sum of // the concatenated string of ETags for each of the segments in the manifest. attributes.setChecksum(Checksum.NONE); } else { attributes.setChecksum(Checksum.parse(etag)); } } return attributes; } }
@Override public Append append(final Path file, final Long length, final Cache<Path> cache) throws BackgroundException { if(finder.withCache(cache).find(file)) { final PathAttributes attr = attributes.withCache(cache).find(file); return new Append(attr.getSize()).withChecksum(attr.getChecksum()); } return Write.notfound; } }
@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()); }
/** * @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; } }
@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(); } }
public <T> PathAttributes deserialize(T serialized) { final Deserializer dict = deserializer.create(serialized); final PathAttributes attributes = new PathAttributes(); final String sizeObj = dict.stringForKey("Size"); if(sizeObj != null) { attributes.setSize(Long.parseLong(sizeObj)); attributes.setModificationDate(Long.parseLong(modifiedObj)); attributes.setRevision(Long.parseLong(revisionObj)); attributes.setPermission(new PermissionDictionary().deserialize(permissionObj)); attributes.setAcl(new AclDictionary().deserialize(aclObj)); attributes.setChecksum(Checksum.parse(dict.stringForKey("Checksum"))); attributes.setVersionId(dict.stringForKey("Version")); final String duplicateObj = dict.stringForKey("Duplicate"); if(duplicateObj != null) { attributes.setDuplicate(Boolean.valueOf(duplicateObj)); 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().deserialize(vaultObj));
@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); } } }
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; }
public PathAttributes toAttributes(final FileAttributes stat) { final PathAttributes attributes = new PathAttributes(); switch(stat.getType()) { case REGULAR: case UNKNOWN: attributes.setSize(stat.getSize()); } if(0 != stat.getMode().getPermissionsMask()) { attributes.setPermission(new Permission(Integer.toString(stat.getMode().getPermissionsMask(), 8))); } if(0 != stat.getUID()) { attributes.setOwner(String.valueOf(stat.getUID())); } if(0 != stat.getGID()) { attributes.setGroup(String.valueOf(stat.getGID())); } if(0 != stat.getMtime()) { attributes.setModificationDate(stat.getMtime() * 1000L); } if(0 != stat.getAtime()) { attributes.setAccessedDate(stat.getAtime() * 1000L); } return attributes; } }
protected PathAttributes toAttributes(final File f) { final PathAttributes attributes = new PathAttributes(); if(null != f.getExplicitlyTrashed()) { if(f.getExplicitlyTrashed()) { attributes.setDuplicate(true); if(!DRIVE_FOLDER.equals(f.getMimeType()) && !StringUtils.startsWith(f.getMimeType(), GOOGLE_APPS_PREFIX)) { attributes.setSize(f.getSize()); attributes.setVersionId(f.getId()); if(f.getModifiedTime() != null) { attributes.setModificationDate(f.getModifiedTime().getValue()); attributes.setCreationDate(f.getCreatedTime().getValue()); attributes.setChecksum(Checksum.parse(f.getMd5Checksum())); if(StringUtils.isNotBlank(f.getWebViewLink())) { attributes.setLink(new DescriptiveUrl(URI.create(f.getWebViewLink()), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), "HTTP"))); if(!DRIVE_FOLDER.equals(f.getMimeType()) && StringUtils.startsWith(f.getMimeType(), GOOGLE_APPS_PREFIX)) { attributes.setSize(UrlFileWriterFactory.get().write(new DescriptiveUrl(URI.create(f.getWebViewLink()))) .getBytes(Charset.defaultCharset()).length);
public PathAttributes toAttributes(final StorageObject object) { final PathAttributes attributes = new PathAttributes(); attributes.setSize(object.getContentLength()); final Date lastmodified = object.getLastModifiedDate(); if(lastmodified != null) { attributes.setModificationDate(lastmodified.getTime()); attributes.setStorageClass(object.getStorageClass()); attributes.setStorageClass(object.getMetadataMap().get("storage-class").toString()); attributes.setETag(object.getETag()); attributes.setVersionId(((S3Object) object).getVersionId()); attributes.setEncryption(new Encryption.Algorithm(object.getServerSideEncryptionAlgorithm(), object.getMetadata("server-side-encryption-aws-kms-key-id").toString()) { @Override if(null != object.getServerSideEncryptionAlgorithm()) { attributes.setEncryption(new Encryption.Algorithm(object.getServerSideEncryptionAlgorithm(), null) { @Override public String getDescription() { attributes.setChecksum(Checksum.parse(object.getETag())); attributes.setMetadata(metadata); return attributes;
public PathAttributes convert(final MantaObject object) { final PathAttributes attributes = new PathAttributes(); attributes.setPermission(new Permission( session.isUserWritable(object) ? Permission.Action.all : Permission.Action.read, Permission.Action.none, session.isWorldReadable(object) ? Permission.Action.read : Permission.Action.none)); if(object.getLastModifiedTime() != null) { attributes.setModificationDate(object.getLastModifiedTime().getTime()); try { final URI link = new URI(joinedPath); attributes.setLink(new DescriptiveUrl(link, DescriptiveUrl.Type.http)); attributes.setSize(object.getContentLength()); attributes.setETag(object.getEtag()); final byte[] md5Bytes = object.getMd5Bytes(); if(md5Bytes != null) { attributes.setChecksum(new Checksum(HashAlgorithm.md5, Hex.encodeHexString(md5Bytes))); attributes.setStorageClass(storageClass);
/** * @param response List filenames response from server * @return Null when respone filename is not child of working directory directory */ protected PathAttributes parse(final B2FileInfoResponse response) { final PathAttributes attributes = new PathAttributes(); attributes.setChecksum( Checksum.parse(StringUtils.removeStart(StringUtils.lowerCase(response.getContentSha1(), Locale.ROOT), "unverified:")) ); final long timestamp = response.getUploadTimestamp(); 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))); } else { attributes.setModificationDate(timestamp); } attributes.setVersionId(response.getFileId()); switch(response.getAction()) { case hide: // File version marking the file as hidden, so that it will not show up in b2_list_file_names case start: // Large file has been started, but not finished or canceled attributes.setDuplicate(true); attributes.setSize(-1L); break; default: attributes.setSize(response.getSize()); } 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; }
public PathAttributes toAttributes(final OneDriveItem.Metadata metadata) { final PathAttributes attributes = new PathAttributes(); attributes.setETag(metadata.getETag()); attributes.setSize(metadata.getSize()); if(metadata instanceof OneDriveRemoteItem.Metadata) { final OneDriveRemoteItem.Metadata remoteMetadata = (OneDriveRemoteItem.Metadata) metadata; final OneDriveItem.Metadata originMetadata = remoteMetadata.getRemoteItem(); attributes.setVersionId(String.join(String.valueOf(Path.DELIMITER), metadata.getParentReference().getDriveId(), metadata.getId(), originMetadata.getParentReference().getDriveId(), originMetadata.getId())); attributes.setVersionId(String.join(String.valueOf(Path.DELIMITER), metadata.getParentReference().getDriveId(), metadata.getId())); attributes.setLink(new DescriptiveUrl(new URI(metadata.getWebUrl()), DescriptiveUrl.Type.http)); attributes.setModificationDate(metadata.getLastModifiedDateTime().toInstant().toEpochMilli()); attributes.setModificationDate(metadata.getFileSystemInfo().getLastModifiedDateTime().toInstant().toEpochMilli()); attributes.setCreationDate(metadata.getCreatedDateTime().toInstant().toEpochMilli()); attributes.setCreationDate(metadata.getFileSystemInfo().getCreatedDateTime().toInstant().toEpochMilli()); attributes.setModificationDate(metadata.getLastModifiedDateTime().toInstant().toEpochMilli()); attributes.setCreationDate(metadata.getCreatedDateTime().toInstant().toEpochMilli());
try { final String cleartextFilename = cryptor.fileNameCryptor().decryptFilename( ciphertext, file.getParent().attributes().getDirectoryId().getBytes(StandardCharsets.UTF_8)); final PathAttributes attributes = new PathAttributes(file.attributes()); if(inflated.getName().startsWith(DIR_PREFIX)) { final Permission permission = attributes.getPermission(); permission.setUser(permission.getUser().or(Permission.Action.execute)); permission.setGroup(permission.getGroup().or(Permission.Action.execute)); permission.setOther(permission.getOther().or(Permission.Action.execute)); attributes.setSize(-1L); attributes.setVersionId(null); attributes.setSize(this.toCleartextSize(file.attributes().getSize())); attributes.setEncrypted(file); attributes.setVault(home); final EnumSet<AbstractPath.Type> type = EnumSet.copyOf(file.getType()); type.remove(inflated.getName().startsWith(DIR_PREFIX) ? Path.Type.file : Path.Type.directory); type.remove(Path.Type.encrypted); type.add(Path.Type.decrypted); return new Path(file.getParent().attributes().getDecrypted(), cleartextFilename, type, attributes);
protected PathAttributes toAttributes(final DavResource resource) { final PathAttributes attributes = new PathAttributes(); final Map<QName, String> properties = resource.getCustomPropsNS(); if(null != properties && properties.containsKey(DAVTimestampFeature.LAST_MODIFIED_CUSTOM_NAMESPACE)) { attributes.setModificationDate( rfc1123.parse(value).getTime()); attributes.setModificationDate(resource.getModified().getTime()); attributes.setModificationDate(resource.getModified().getTime()); attributes.setModificationDate( rfc1123.parse(value).getTime()); log.warn(String.format("Failure parsing property %s with value %s", DAVTimestampFeature.LAST_MODIFIED_CUSTOM_NAMESPACE, value)); if(resource.getModified() != null) { attributes.setModificationDate(resource.getModified().getTime()); attributes.setModificationDate(resource.getModified().getTime()); attributes.setModificationDate(resource.getModified().getTime()); attributes.setCreationDate(resource.getCreation().getTime()); attributes.setSize(resource.getContentLength()); attributes.setETag(resource.getEtag()); attributes.setDisplayname(resource.getDisplayName());
if(preferences.getBoolean(String.format("browser.column.%s", BrowserColumn.size.name()))) { copy.append(","); if(-1 != next.attributes().getSize()) { copy.append(String.valueOf(next.attributes().getSize())); if(-1 != next.attributes().getModificationDate()) { copy.append(String.valueOf(next.attributes().getModificationDate())); if(StringUtils.isNotBlank(next.attributes().getOwner())) { copy.append(next.attributes().getOwner()); if(StringUtils.isNotBlank(next.attributes().getGroup())) { copy.append(next.attributes().getGroup()); if(Permission.EMPTY != next.attributes().getPermission()) { copy.append(next.attributes().getPermission().getMode()); copy.append(",").append(next.attributes().getRegion()); copy.append(",").append(next.attributes().getVersionId());
parsed.attributes().setSize(Long.parseLong(facts.get("size"))); parsed.attributes().setOwner(facts.get("unix.uid")); parsed.attributes().setOwner(facts.get("unix.owner")); parsed.attributes().setGroup(facts.get("unix.gid")); parsed.attributes().setGroup(facts.get("unix.group")); parsed.attributes().setPermission(new Permission(facts.get("unix.mode"))); parsed.attributes().setPermission(permission); parsed.attributes().setModificationDate(this.parseTimestamp(facts.get("modify"))); parsed.attributes().setCreationDate(this.parseTimestamp(facts.get("create")));