@Override
    public void setUnixPermission(final Path file, final TransferStatus status) throws BackgroundException {
        try {
            Files.setPosixFilePermissions(session.toPath(file), PosixFilePermissions.fromString(status.getPermission().getSymbol()));
        }
        catch(IllegalArgumentException e) {
            throw new LocalExceptionMappingService().map("Failure to write attributes of {0}", new IOException(e), file);
        }
        catch(IOException e) {
            throw new LocalExceptionMappingService().map("Failure to write attributes of {0}", e, file);
        }
    }
@Test
    public void testSetUnixPermission() throws Exception {
        final LocalSession session = new LocalSession(new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname()));
        if(session.isPosixFilesystem()) {
            assertNotNull(session.open(new DisabledProxyFinder(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback()));
            assertTrue(session.isConnected());
            assertNotNull(session.getClient());
            session.login(new DisabledLoginCallback(), new DisabledCancelCallback());
            final Path workdir = new LocalHomeFinderFeature().find();
            {
                final Path file = new Path(workdir, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
                new LocalTouchFeature(session).touch(file, new TransferStatus());
                new LocalUnixPermissionFeature(session).setUnixPermission(file, new Permission(666));
                assertEquals("666", new LocalListService(session).list(workdir, new DisabledListProgressListener()).get(file).attributes().getPermission().getMode());
                new LocalDeleteFeature(session).delete(Collections.<Path>singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
            }
            {
                final Path directory = new Path(workdir, UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory));
                new LocalDirectoryFeature(session).mkdir(directory, new TransferStatus());
                new LocalUnixPermissionFeature(session).setUnixPermission(directory, new Permission(666));
                assertEquals("666", new LocalListService(session).list(workdir, new DisabledListProgressListener()).get(directory).attributes().getPermission().getMode());
                new LocalDeleteFeature(session).delete(Collections.<Path>singletonList(directory), new DisabledLoginCallback(), new Delete.DisabledCallback());
            }
            session.close();
        }
    }