@Test public void testSetUnixPermission() throws Exception { final LocalSession session = new LocalSession(new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname())); if(session.isPosixFilesystem()) { assertNotNull(session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback())); assertTrue(session.isConnected()); assertNotNull(session.getClient()); session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); final Path workdir = new LocalHomeFinderFeature(session).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, null, 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(); } }
@Override public void setUnixPermission(final Path file, final Permission permission) throws BackgroundException { try { Files.setPosixFilePermissions(session.toPath(file), PosixFilePermissions.fromString(permission.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); } }
LocalUnixPermissionFeature extends DefaultUnixPermissionFeature { @Override public void setUnixPermission(final Path file, final Permission permission) throws BackgroundException { try { Files.setPosixFilePermissions(session.toPath(file), PosixFilePermissions.fromString(permission.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); } } }
LocalUnixPermissionFeature extends DefaultUnixPermissionFeature { @Override public void setUnixPermission(final Path file, final Permission permission) throws BackgroundException { try { Files.setPosixFilePermissions(session.toPath(file), PosixFilePermissions.fromString(permission.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); } } LocalUnixPermissionFeature(final LocalSession session); }
LocalUnixPermissionFeature extends DefaultUnixPermissionFeature { @Override public void setUnixPermission(final Path file, final Permission permission) throws BackgroundException { try { Files.setPosixFilePermissions(session.toPath(file), PosixFilePermissions.fromString(permission.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); } } LocalUnixPermissionFeature(final LocalSession session); @Override void setUnixOwner(final Path file, final String owner); @Override void setUnixGroup(final Path file, final String group); @Override Permission getUnixPermission(final Path file); @Override void setUnixPermission(final Path file, final Permission permission); }
LocalUnixPermissionFeature extends DefaultUnixPermissionFeature { @Override public void setUnixPermission(final Path file, final Permission permission) throws BackgroundException { try { Files.setPosixFilePermissions(session.toPath(file), PosixFilePermissions.fromString(permission.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); } } LocalUnixPermissionFeature(final LocalSession session); @Override void setUnixOwner(final Path file, final String owner); @Override void setUnixGroup(final Path file, final String group); @Override Permission getUnixPermission(final Path file); @Override void setUnixPermission(final Path file, final Permission permission);  }