public List<T> listFiles() { logger.trace("[{}] listFiles()", name); List<T> result = new ArrayList<>(); final LsOutputParser parser = new LsOutputParser(); final List<LsOutputBean> beans = new ArrayList<>(); shell.addCommand("ls -la " + absPath, 0, new Shell.OnCommandLineListener() { @Override public void onLine(String s) { LsOutputBean bean = parser.parseLine(s); if (bean != null) { beans.add(bean); } } @Override public void onCommandResult(int i, int i1) { } }); shell.waitForIdle(); for (LsOutputBean bean : beans) { String path = absPath + "/" + bean.getName(); result.add(createFile(shell, bean, path)); } return result; }
public RootFile(Shell.Interactive shell, LsOutputBean bean, String absPath) { super( absPath, bean.getName(), bean.getDate() != null ? bean.getDate().getTime() : 0, bean.getSize(), true, bean.isExists(), bean.isDir()); this.shell = shell; this.bean = bean; }
bean = findFinalLinkTarget(bean, parser); file = bean.getName();
@Test public void nameWithSpaces() throws IOException { List<LsOutputBean> beans = new LsOutputParser().parse(stream("name-with-spaces.txt")); Assert.assertEquals(4, beans.size()); Assert.assertEquals("dir name", beans.get(0).getName()); Assert.assertEquals("file name", beans.get(1).getName()); Assert.assertEquals("file 2", beans.get(2).getName()); Assert.assertEquals("link name", beans.get(3).getName()); Assert.assertEquals("/absolute/link target", beans.get(3).getLinkTarget()); }
@Test public void symLink() throws IOException { List<LsOutputBean> beans = new LsOutputParser().parse(stream("sym-link.txt")); Assert.assertEquals(1, beans.size()); LsOutputBean link = beans.get(0); Assert.assertFalse(link.isDir()); Assert.assertFalse(link.isFile()); Assert.assertTrue(link.isLink()); Assert.assertEquals("link_name", link.getName()); Assert.assertEquals("/absolute/link/target", link.getLinkTarget()); Assert.assertNotNull(link.getDate()); Assert.assertTrue(link.getDate().getTime() > 0); }
Assert.assertEquals("group", dir.getGroup()); Assert.assertEquals(1234, dir.getSize()); Assert.assertEquals("dir_name", dir.getName()); Assert.assertNull(dir.getLinkTarget()); Assert.assertNotNull(dir.getDate()); Assert.assertFalse(file1.isDir()); Assert.assertFalse(file1.isLink()); Assert.assertEquals("file_name", file1.getName()); Assert.assertNotNull(file1.getDate()); Assert.assertEquals(86400000, file1.getDate().getTime()); Assert.assertTrue(file2.isFile()); Assert.assertTrue(file2.isHasAcl()); Assert.assertEquals("file_2", file2.getName()); Assert.assertNotNull(file2.getDate()); long expectedTime =
Assert.assertEquals("group", dir.getGroup()); Assert.assertEquals(1234, dir.getSize()); Assert.assertEquals("dir_name", dir.getName()); Assert.assertNull(dir.getLinkTarget()); Assert.assertNotNull(dir.getDate()); Assert.assertFalse(file1.isDir()); Assert.assertFalse(file1.isLink()); Assert.assertEquals("file_name", file1.getName()); Assert.assertNotNull(file1.getDate()); Assert.assertEquals(86400000, file1.getDate().getTime()); Assert.assertTrue(file2.isFile()); Assert.assertTrue(file2.isHasAcl()); Assert.assertEquals("file_2", file2.getName()); Assert.assertNotNull(file2.getDate()); long expectedTime =