private void copyAttributes(final RemoteResourceInfo remote, final LocalDestFile local) throws IOException { final FileAttributes attrs = remote.getAttributes(); local.setPermissions(attrs.getMode().getPermissionsMask()); if (attrs.has(FileAttributes.Flag.ACMODTIME)) { local.setLastAccessedTime(attrs.getAtime()); local.setLastModifiedTime(attrs.getMtime()); } }
public int gid(String path) throws IOException { return stat(path).getGID(); }
@SuppressWarnings("PMD.MissingBreakInSwitch") private void download(final TransferListener listener, final RemoteResourceInfo remote, final LocalDestFile local) throws IOException { final LocalDestFile adjustedFile; switch (remote.getAttributes().getType()) { case DIRECTORY: adjustedFile = downloadDir(listener.directory(remote.getName()), remote, local); break; case UNKNOWN: log.warn("Server did not supply information about the type of file at `{}` " + "-- assuming it is a regular file!", remote.getPath()); case REGULAR: adjustedFile = downloadFile(listener.file(remote.getName(), remote.getAttributes().getSize()), remote, local); break; default: throw new IOException(remote + " is not a regular file or directory"); } if (getPreserveAttributes()) copyAttributes(remote, adjustedFile); }
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; } }
public boolean isDirectory() { return attrs.getType() == FileMode.Type.DIRECTORY; }
public FileMode mode(String path) throws IOException { return stat(path).getMode(); }
public long size(String path) throws IOException { return stat(path).getSize(); }
@Override public String toString() { final StringBuilder sb = new StringBuilder("["); if (has(Flag.SIZE)) sb.append("size=").append(size).append(";"); if (has(Flag.UIDGID)) sb.append("uid=").append(uid).append(",gid=").append(gid).append(";"); if (has(Flag.MODE)) sb.append("mode=").append(mode.toString()).append(";"); if (has(Flag.ACMODTIME)) sb.append("atime=").append(atime).append(",mtime=").append(mtime).append(";"); if (has(Flag.EXTENDED)) sb.append("ext=").append(ext); sb.append("]"); return sb.toString(); }
public long atime(String path) throws IOException { return stat(path).getAtime(); }
public long mtime(String path) throws IOException { return stat(path).getMtime(); }
public int uid(String path) throws IOException { return stat(path).getUID(); }
public Set<FilePermission> perms(String path) throws IOException { return stat(path).getPermissions(); }
public FileAttributes build() { return new FileAttributes(mask, size, uid, gid, mode, atime, mtime, ext); }
public boolean isRegularFile() { return attrs.getType() == FileMode.Type.REGULAR; }
private boolean isDirectory(final String remote) throws IOException { try { FileAttributes attrs = engine.stat(remote); return attrs.getMode().getType() == FileMode.Type.DIRECTORY; } catch (SFTPException e) { if (e.getStatusCode() == StatusCode.NO_SUCH_FILE) { log.debug("isDir: {} does not exist", remote); return false; } else { throw e; } } }
public long length() throws IOException { return fetchAttributes().getSize(); }
public byte[] toBytes() { Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); buf.putUInt32(mask); if (has(Flag.SIZE)) buf.putUInt64(size); if (has(Flag.UIDGID)) { buf.putUInt32(uid); buf.putUInt32(gid); } if (has(Flag.MODE)) buf.putUInt32(mode.getMask()); if (has(Flag.ACMODTIME)) { buf.putUInt32(atime); buf.putUInt32(mtime); } if (has(Flag.EXTENDED)) { buf.putUInt32(ext.size()); for (Entry<String, String> entry : ext.entrySet()) { buf.putString(entry.getKey()); buf.putString(entry.getValue()); } } return buf.getCompactData(); }
public long atime(String path) throws IOException { return stat(path).getAtime(); }
public long mtime(String path) throws IOException { return stat(path).getMtime(); }
public int uid(String path) throws IOException { return stat(path).getUID(); }