@Test public void testConvert() throws Exception { final LocalSession session = new LocalSession(new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname())); if(session.isPosixFilesystem()) { session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); final Path file = new Path(new LocalHomeFinderFeature(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); new LocalTouchFeature(session).touch(file, new TransferStatus()); final java.nio.file.Path local = session.toPath(file); final PosixFileAttributes posixAttributes = Files.readAttributes(local, PosixFileAttributes.class); final LocalAttributesFinderFeature finder = new LocalAttributesFinderFeature(session); assertEquals(PosixFilePermissions.toString(posixAttributes.permissions()), finder.find(file).getPermission().getSymbol()); Files.setPosixFilePermissions(local, PosixFilePermissions.fromString("rw-------")); assertEquals("rw-------", finder.find(file).getPermission().getSymbol()); Files.setPosixFilePermissions(local, PosixFilePermissions.fromString("rwxrwxrwx")); assertEquals("rwxrwxrwx", finder.find(file).getPermission().getSymbol()); Files.setPosixFilePermissions(local, PosixFilePermissions.fromString("rw-rw----")); assertEquals("rw-rw----", finder.find(file).getPermission().getSymbol()); assertEquals(posixAttributes.size(), finder.find(file).getSize()); assertEquals(posixAttributes.lastModifiedTime().toMillis(), finder.find(file).getModificationDate()); assertEquals(posixAttributes.creationTime().toMillis(), finder.find(file).getCreationDate()); assertEquals(posixAttributes.lastAccessTime().toMillis(), finder.find(file).getAccessedDate()); new LocalDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); } }
protected PathAttributes convert(final java.nio.file.Path file) throws IOException { final boolean isPosix = session.isPosixFilesystem(); final PathAttributes attributes = new PathAttributes(); final Class<? extends BasicFileAttributes> provider = isPosix ? PosixFileAttributes.class : DosFileAttributes.class; final BasicFileAttributes a = Files.readAttributes(file, provider, LinkOption.NOFOLLOW_LINKS); if(a.isRegularFile()) { attributes.setSize(a.size()); } attributes.setModificationDate(a.lastModifiedTime().toMillis()); attributes.setCreationDate(a.creationTime().toMillis()); attributes.setAccessedDate(a.lastAccessTime().toMillis()); if(isPosix) { attributes.setOwner(((PosixFileAttributes) a).owner().getName()); attributes.setGroup(((PosixFileAttributes) a).group().getName()); attributes.setPermission(new Permission(PosixFilePermissions.toString(((PosixFileAttributes) a).permissions()))); } else { Permission.Action actions = Permission.Action.none; if(Files.isReadable(file)) { actions = actions.or(Permission.Action.read); } if(Files.isWritable(file)) { actions = actions.or(Permission.Action.write); } if(Files.isExecutable(file)) { actions = actions.or(Permission.Action.execute); } attributes.setPermission(new Permission( actions, Permission.Action.none, Permission.Action.none )); } return attributes; }
LocalAttributesFinderFeature implements AttributesFinder { protected PathAttributes convert(final java.nio.file.Path file) throws IOException { final boolean isPosix = session.isPosixFilesystem(); final PathAttributes attributes = new PathAttributes(); final Class<? extends BasicFileAttributes> provider = isPosix ? PosixFileAttributes.class : DosFileAttributes.class; final BasicFileAttributes a = Files.readAttributes(file, provider, LinkOption.NOFOLLOW_LINKS); if(a.isRegularFile()) { attributes.setSize(a.size()); } attributes.setModificationDate(a.lastModifiedTime().toMillis()); attributes.setCreationDate(a.creationTime().toMillis()); attributes.setAccessedDate(a.lastAccessTime().toMillis()); if(isPosix) { attributes.setOwner(((PosixFileAttributes) a).owner().getName()); attributes.setGroup(((PosixFileAttributes) a).group().getName()); attributes.setPermission(new Permission(PosixFilePermissions.toString(((PosixFileAttributes) a).permissions()))); } else { Permission.Action actions = Permission.Action.none; if(Files.isReadable(file)) { actions = actions.or(Permission.Action.read); } if(Files.isWritable(file)) { actions = actions.or(Permission.Action.write); } if(Files.isExecutable(file)) { actions = actions.or(Permission.Action.execute); } attributes.setPermission(new Permission( actions, Permission.Action.none, Permission.Action.none )); } return attributes; } }
LocalAttributesFinderFeature implements AttributesFinder { protected PathAttributes convert(final java.nio.file.Path file) throws IOException { final boolean isPosix = session.isPosixFilesystem(); final PathAttributes attributes = new PathAttributes(); final Class<? extends BasicFileAttributes> provider = isPosix ? PosixFileAttributes.class : DosFileAttributes.class; final BasicFileAttributes a = Files.readAttributes(file, provider, LinkOption.NOFOLLOW_LINKS); if(a.isRegularFile()) { attributes.setSize(a.size()); } attributes.setModificationDate(a.lastModifiedTime().toMillis()); attributes.setCreationDate(a.creationTime().toMillis()); attributes.setAccessedDate(a.lastAccessTime().toMillis()); if(isPosix) { attributes.setOwner(((PosixFileAttributes) a).owner().getName()); attributes.setGroup(((PosixFileAttributes) a).group().getName()); attributes.setPermission(new Permission(PosixFilePermissions.toString(((PosixFileAttributes) a).permissions()))); } else { Permission.Action actions = Permission.Action.none; if(Files.isReadable(file)) { actions = actions.or(Permission.Action.read); } if(Files.isWritable(file)) { actions = actions.or(Permission.Action.write); } if(Files.isExecutable(file)) { actions = actions.or(Permission.Action.execute); } attributes.setPermission(new Permission( actions, Permission.Action.none, Permission.Action.none )); } return attributes; } LocalAttributesFinderFeature(final LocalSession session); }
LocalAttributesFinderFeature implements AttributesFinder { protected PathAttributes convert(final java.nio.file.Path file) throws IOException { final boolean isPosix = session.isPosixFilesystem(); final PathAttributes attributes = new PathAttributes(); final Class<? extends BasicFileAttributes> provider = isPosix ? PosixFileAttributes.class : DosFileAttributes.class; final BasicFileAttributes a = Files.readAttributes(file, provider, LinkOption.NOFOLLOW_LINKS); if(a.isRegularFile()) { attributes.setSize(a.size()); } attributes.setModificationDate(a.lastModifiedTime().toMillis()); attributes.setCreationDate(a.creationTime().toMillis()); attributes.setAccessedDate(a.lastAccessTime().toMillis()); if(isPosix) { attributes.setOwner(((PosixFileAttributes) a).owner().getName()); attributes.setGroup(((PosixFileAttributes) a).group().getName()); attributes.setPermission(new Permission(PosixFilePermissions.toString(((PosixFileAttributes) a).permissions()))); } else { Permission.Action actions = Permission.Action.none; if(Files.isReadable(file)) { actions = actions.or(Permission.Action.read); } if(Files.isWritable(file)) { actions = actions.or(Permission.Action.write); } if(Files.isExecutable(file)) { actions = actions.or(Permission.Action.execute); } attributes.setPermission(new Permission( actions, Permission.Action.none, Permission.Action.none )); } return attributes; } LocalAttributesFinderFeature(final LocalSession session); @Override PathAttributes find(final Path file); }
LocalAttributesFinderFeature implements AttributesFinder { protected PathAttributes convert(final java.nio.file.Path file) throws IOException { final boolean isPosix = session.isPosixFilesystem(); final PathAttributes attributes = new PathAttributes(); final Class<? extends BasicFileAttributes> provider = isPosix ? PosixFileAttributes.class : DosFileAttributes.class; final BasicFileAttributes a = Files.readAttributes(file, provider, LinkOption.NOFOLLOW_LINKS); if(a.isRegularFile()) { attributes.setSize(a.size()); } attributes.setModificationDate(a.lastModifiedTime().toMillis()); attributes.setCreationDate(a.creationTime().toMillis()); attributes.setAccessedDate(a.lastAccessTime().toMillis()); if(isPosix) { attributes.setOwner(((PosixFileAttributes) a).owner().getName()); attributes.setGroup(((PosixFileAttributes) a).group().getName()); attributes.setPermission(new Permission(PosixFilePermissions.toString(((PosixFileAttributes) a).permissions()))); } else { Permission.Action actions = Permission.Action.none; if(Files.isReadable(file)) { actions = actions.or(Permission.Action.read); } if(Files.isWritable(file)) { actions = actions.or(Permission.Action.write); } if(Files.isExecutable(file)) { actions = actions.or(Permission.Action.execute); } attributes.setPermission(new Permission( actions, Permission.Action.none, Permission.Action.none )); } return attributes; } LocalAttributesFinderFeature(final LocalSession session); @Override PathAttributes find(final Path file);  }