private static Iterable<Path> fileTreeChildren(Path dir) { if (Files.isDirectory(dir, NOFOLLOW_LINKS)) { try { return listFiles(dir); } catch (IOException e) { // the exception thrown when iterating a DirectoryStream if an I/O exception occurs throw new DirectoryIteratorException(e); } } return ImmutableList.of(); }
private static Iterable<Path> fileTreeChildren(Path dir) { if (Files.isDirectory(dir, NOFOLLOW_LINKS)) { try { return listFiles(dir); } catch (IOException e) { // the exception thrown when iterating a DirectoryStream if an I/O exception occurs throw new DirectoryIteratorException(e); } } return ImmutableList.of(); }
@Override public void assertDeleteSucceeded(Path path) throws IOException { assertEquals( "contents of directory " + path + " not deleted with delete method " + this, 0, MoreFiles.listFiles(path).size()); } },
private static Iterable<Path> fileTreeChildren(Path dir) { if (Files.isDirectory(dir, NOFOLLOW_LINKS)) { try { return listFiles(dir); } catch (IOException e) { // the exception thrown when iterating a DirectoryStream if an I/O exception occurs throw new DirectoryIteratorException(e); } } return ImmutableList.of(); }
public void testDeleteDirectoryContents_symlinkToDir_sdsNotSupported_allowInsecure() throws IOException { try (FileSystem fs = newTestFileSystem()) { Path symlink = fs.getPath("/symlinktodir"); Path dir = fs.getPath("dir"); assertEquals(6, MoreFiles.listFiles(dir).size()); MoreFiles.deleteDirectoryContents(symlink, ALLOW_INSECURE); assertEquals(0, MoreFiles.listFiles(dir).size()); } }
public void testDeleteRecursively_symlinkToDir_sdsNotSupported_allowInsecure() throws IOException { try (FileSystem fs = newTestFileSystem()) { Path symlink = fs.getPath("/symlinktodir"); Path dir = fs.getPath("dir"); assertEquals(6, MoreFiles.listFiles(dir).size()); MoreFiles.deleteRecursively(symlink, ALLOW_INSECURE); assertFalse(Files.exists(symlink)); assertTrue(Files.exists(dir)); assertEquals(6, MoreFiles.listFiles(dir).size()); } }
public void testDeleteRecursively_symlinkToDir() throws IOException { try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) { Path symlink = fs.getPath("/symlinktodir"); Path dir = fs.getPath("dir"); assertEquals(6, MoreFiles.listFiles(dir).size()); MoreFiles.deleteRecursively(symlink); assertFalse(Files.exists(symlink)); assertTrue(Files.exists(dir)); assertEquals(6, MoreFiles.listFiles(dir).size()); } }
public void testDirectoryDeletion_sdsNotSupported_allowInsecure() throws IOException { for (DirectoryDeleteMethod method : EnumSet.allOf(DirectoryDeleteMethod.class)) { try (FileSystem fs = newTestFileSystem()) { Path dir = fs.getPath("dir"); assertEquals(6, MoreFiles.listFiles(dir).size()); method.delete(dir, ALLOW_INSECURE); method.assertDeleteSucceeded(dir); assertEquals( "contents of /dontdelete deleted by delete method " + method, 3, MoreFiles.listFiles(fs.getPath("/dontdelete")).size()); } } }
public void testDirectoryDeletion_basic() throws IOException { for (DirectoryDeleteMethod method : EnumSet.allOf(DirectoryDeleteMethod.class)) { try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) { Path dir = fs.getPath("dir"); assertEquals(6, MoreFiles.listFiles(dir).size()); method.delete(dir); method.assertDeleteSucceeded(dir); assertEquals( "contents of /dontdelete deleted by delete method " + method, 3, MoreFiles.listFiles(fs.getPath("/dontdelete")).size()); } } }
public void testDeleteDirectoryContents_symlinkToDir() throws IOException { try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) { Path symlink = fs.getPath("/symlinktodir"); Path dir = fs.getPath("dir"); assertEquals(6, MoreFiles.listFiles(symlink).size()); MoreFiles.deleteDirectoryContents(symlink); assertTrue(Files.exists(symlink, NOFOLLOW_LINKS)); assertTrue(Files.exists(symlink)); assertTrue(Files.exists(dir)); assertEquals(0, MoreFiles.listFiles(symlink).size()); } }
public void testDirectoryDeletion_sdsNotSupported_fails() throws IOException { for (DirectoryDeleteMethod method : EnumSet.allOf(DirectoryDeleteMethod.class)) { try (FileSystem fs = newTestFileSystem()) { Path dir = fs.getPath("dir"); assertEquals(6, MoreFiles.listFiles(dir).size()); try { method.delete(dir); fail("expected InsecureRecursiveDeleteException"); } catch (InsecureRecursiveDeleteException expected) { } assertTrue(Files.exists(dir)); assertEquals(6, MoreFiles.listFiles(dir).size()); } } }
public void testDirectoryDeletion_emptyDir() throws IOException { for (DirectoryDeleteMethod method : EnumSet.allOf(DirectoryDeleteMethod.class)) { try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) { Path emptyDir = fs.getPath("dir/e"); assertEquals(0, MoreFiles.listFiles(emptyDir).size()); method.delete(emptyDir); method.assertDeleteSucceeded(emptyDir); } } }
java.nio.file.Files.createTempFile(spillPath2.toPath(), "blah", "blah"); assertEquals(listFiles(spillPath1.toPath()).size(), 3); assertEquals(listFiles(spillPath2.toPath()).size(), 3); spillerFactory.cleanupOldSpillFiles(); assertEquals(listFiles(spillPath1.toPath()).size(), 1); assertEquals(listFiles(spillPath2.toPath()).size(), 2);
assertEquals(3, MoreFiles.listFiles(symlinkTarget).size());
@Test public void testDistributesSpillOverPaths() throws Exception { List<Type> types = ImmutableList.of(BIGINT); BlockEncodingSerde blockEncodingSerde = new BlockEncodingManager(new TypeRegistry()); List<Path> spillPaths = ImmutableList.of(spillPath1.toPath(), spillPath2.toPath()); FileSingleStreamSpillerFactory spillerFactory = new FileSingleStreamSpillerFactory( executor, // executor won't be closed, because we don't call destroy() on the spiller factory blockEncodingSerde, new SpillerStats(), spillPaths, 1.0); assertEquals(listFiles(spillPath1.toPath()).size(), 0); assertEquals(listFiles(spillPath2.toPath()).size(), 0); Page page = buildPage(); List<SingleStreamSpiller> spillers = new ArrayList<>(); for (int i = 0; i < 10; ++i) { SingleStreamSpiller singleStreamSpiller = spillerFactory.create(types, bytes -> {}, newSimpleAggregatedMemoryContext().newLocalMemoryContext("test")); getUnchecked(singleStreamSpiller.spill(page)); spillers.add(singleStreamSpiller); } assertEquals(listFiles(spillPath1.toPath()).size(), 5); assertEquals(listFiles(spillPath2.toPath()).size(), 5); spillers.forEach(SingleStreamSpiller::close); assertEquals(listFiles(spillPath1.toPath()).size(), 0); assertEquals(listFiles(spillPath2.toPath()).size(), 0); }
private static Iterable<Path> fileTreeChildren(Path dir) { if (Files.isDirectory(dir, NOFOLLOW_LINKS)) { try { return listFiles(dir); } catch (IOException e) { // the exception thrown when iterating a DirectoryStream if an I/O exception occurs throw new DirectoryIteratorException(e); } } return ImmutableList.of(); }
public void testDirectoryDeletion_basic() throws IOException { for (DirectoryDeleteMethod method : EnumSet.allOf(DirectoryDeleteMethod.class)) { try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) { Path dir = fs.getPath("dir"); assertEquals(6, MoreFiles.listFiles(dir).size()); method.delete(dir); method.assertDeleteSucceeded(dir); assertEquals("contents of /dontdelete deleted by delete method " + method, 3, MoreFiles.listFiles(fs.getPath("/dontdelete")).size()); } } }
public void testDeleteRecursively_symlinkToDir() throws IOException { try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) { Path symlink = fs.getPath("/symlinktodir"); Path dir = fs.getPath("dir"); assertEquals(6, MoreFiles.listFiles(dir).size()); MoreFiles.deleteRecursively(symlink); assertFalse(Files.exists(symlink)); assertTrue(Files.exists(dir)); assertEquals(6, MoreFiles.listFiles(dir).size()); } }
public void testDeleteDirectoryContents_symlinkToDir() throws IOException { try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) { Path symlink = fs.getPath("/symlinktodir"); Path dir = fs.getPath("dir"); assertEquals(6, MoreFiles.listFiles(symlink).size()); MoreFiles.deleteDirectoryContents(symlink); assertTrue(Files.exists(symlink, NOFOLLOW_LINKS)); assertTrue(Files.exists(symlink)); assertTrue(Files.exists(dir)); assertEquals(0, MoreFiles.listFiles(symlink).size()); } }