@Test public void testRun() throws Exception { final ReadPermissionWorker worker = new ReadPermissionWorker( Arrays.<Path>asList( new Path("/a", EnumSet.of(Path.Type.file), new TestPermissionAttributes(Permission.Action.all, Permission.Action.all, Permission.Action.none)), new Path("/b", EnumSet.of(Path.Type.file), new TestPermissionAttributes(Permission.Action.all, Permission.Action.read_write, Permission.Action.read)))) { @Override public void cleanup(final PermissionOverwrite result) { } }; PermissionOverwrite overwrite = worker.run(new NullSession(new Host(new TestProtocol())) { @Override @SuppressWarnings("unchecked") public <T> T _getFeature(final Class<T> type) { if(type == UnixPermission.class) { return (T) new DefaultUnixPermissionFeature() { @Override public void setUnixOwner(final Path file, final String owner) { throw new UnsupportedOperationException(); } @Override public void setUnixGroup(final Path file, final String group) { throw new UnsupportedOperationException(); } @Override public Permission getUnixPermission(final Path file) { return file.attributes().getPermission(); } @Override public void setUnixPermission(final Path file, final Permission permission) { throw new UnsupportedOperationException(); } }; } return super._getFeature(type); } }); assertEquals(Boolean.TRUE, overwrite.user.read); assertEquals(Boolean.TRUE, overwrite.user.write); assertEquals(Boolean.TRUE, overwrite.user.execute); assertEquals(Boolean.TRUE, overwrite.group.read); assertEquals(Boolean.TRUE, overwrite.group.write); assertNull(overwrite.group.execute); assertNull(overwrite.other.read); assertEquals(Boolean.FALSE, overwrite.other.write); assertEquals(Boolean.FALSE, overwrite.other.execute); assertEquals("Getting permission of a… (Multiple files) (2)", worker.getActivity()); }
@Override public PermissionOverwrite run(final Session<?> session) throws BackgroundException { final UnixPermission feature = session.getFeature(UnixPermission.class); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", feature)); } final List<Permission> permissions = new ArrayList<>(); for(Path next : files) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } if(Permission.EMPTY == next.attributes().getPermission()) { next.attributes().setPermission(feature.getUnixPermission(next)); } permissions.add(next.attributes().getPermission()); } final PermissionOverwrite overwrite = new PermissionOverwrite(); final Supplier<Stream<Permission>> supplier = permissions::stream; overwrite.user.read = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.read)); overwrite.user.write = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.write)); overwrite.user.execute = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.execute)); overwrite.group.read = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.read)); overwrite.group.write = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.write)); overwrite.group.execute = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.execute)); overwrite.other.read = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.read)); overwrite.other.write = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.write)); overwrite.other.execute = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.execute)); return overwrite; }
ReadPermissionWorker extends Worker<PermissionOverwrite> { @Override public PermissionOverwrite run(final Session<?> session) throws BackgroundException { final UnixPermission feature = session.getFeature(UnixPermission.class); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", feature)); } final List<Permission> permissions = new ArrayList<>(); for(Path next : files) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } if(Permission.EMPTY == next.attributes().getPermission()) { next.attributes().setPermission(feature.getUnixPermission(next)); } permissions.add(next.attributes().getPermission()); } final PermissionOverwrite overwrite = new PermissionOverwrite(); final Supplier<Stream<Permission>> supplier = permissions::stream; overwrite.user.read = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.read)); overwrite.user.write = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.write)); overwrite.user.execute = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.execute)); overwrite.group.read = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.read)); overwrite.group.write = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.write)); overwrite.group.execute = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.execute)); overwrite.other.read = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.read)); overwrite.other.write = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.write)); overwrite.other.execute = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.execute)); return overwrite; } }
ReadPermissionWorker extends Worker<PermissionOverwrite> { @Override public PermissionOverwrite run(final Session<?> session) throws BackgroundException { final UnixPermission feature = session.getFeature(UnixPermission.class); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", feature)); } final List<Permission> permissions = new ArrayList<>(); for(Path next : files) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } if(Permission.EMPTY == next.attributes().getPermission()) { next.attributes().setPermission(feature.getUnixPermission(next)); } permissions.add(next.attributes().getPermission()); } final PermissionOverwrite overwrite = new PermissionOverwrite(); final Supplier<Stream<Permission>> supplier = permissions::stream; overwrite.user.read = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.read)); overwrite.user.write = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.write)); overwrite.user.execute = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.execute)); overwrite.group.read = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.read)); overwrite.group.write = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.write)); overwrite.group.execute = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.execute)); overwrite.other.read = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.read)); overwrite.other.write = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.write)); overwrite.other.execute = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.execute)); return overwrite; } ReadPermissionWorker(final List<Path> files); }
ReadPermissionWorker extends Worker<PermissionOverwrite> { @Override public PermissionOverwrite run(final Session<?> session) throws BackgroundException { final UnixPermission feature = session.getFeature(UnixPermission.class); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", feature)); } final List<Permission> permissions = new ArrayList<>(); for(Path next : files) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } if(Permission.EMPTY == next.attributes().getPermission()) { next.attributes().setPermission(feature.getUnixPermission(next)); } permissions.add(next.attributes().getPermission()); } final PermissionOverwrite overwrite = new PermissionOverwrite(); final Supplier<Stream<Permission>> supplier = permissions::stream; overwrite.user.read = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.read)); overwrite.user.write = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.write)); overwrite.user.execute = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.execute)); overwrite.group.read = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.read)); overwrite.group.write = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.write)); overwrite.group.execute = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.execute)); overwrite.other.read = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.read)); overwrite.other.write = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.write)); overwrite.other.execute = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.execute)); return overwrite; } ReadPermissionWorker(final List<Path> files); @Override PermissionOverwrite run(final Session<?> session); @Override String getActivity(); @Override PermissionOverwrite initialize(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
ReadPermissionWorker extends Worker<PermissionOverwrite> { @Override public PermissionOverwrite run(final Session<?> session) throws BackgroundException { final UnixPermission feature = session.getFeature(UnixPermission.class); if(log.isDebugEnabled()) { log.debug(String.format("Run with feature %s", feature)); } final List<Permission> permissions = new ArrayList<>(); for(Path next : files) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } if(Permission.EMPTY == next.attributes().getPermission()) { next.attributes().setPermission(feature.getUnixPermission(next)); } permissions.add(next.attributes().getPermission()); } final PermissionOverwrite overwrite = new PermissionOverwrite(); final Supplier<Stream<Permission>> supplier = permissions::stream; overwrite.user.read = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.read)); overwrite.user.write = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.write)); overwrite.user.execute = resolveOverwrite(map(supplier, Permission::getUser, Permission.Action.execute)); overwrite.group.read = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.read)); overwrite.group.write = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.write)); overwrite.group.execute = resolveOverwrite(map(supplier, Permission::getGroup, Permission.Action.execute)); overwrite.other.read = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.read)); overwrite.other.write = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.write)); overwrite.other.execute = resolveOverwrite(map(supplier, Permission::getOther, Permission.Action.execute)); return overwrite; } ReadPermissionWorker(final List<Path> files); @Override PermissionOverwrite run(final Session<?> session); @Override String getActivity(); @Override PermissionOverwrite initialize(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }