/** * Deletes the file or (probably not empty) directory {@code node} * and updates the tree accordingly. * Note that the current selection may get lost. * * @throws IOException On any I/O failure. */ public void rm_r(TFile node) throws IOException { TFile.rm_r(node); nodeRemoved(node); }
@Deprecated @SuppressWarnings("ResultOfMethodCallIgnored") private void backup() throws IOException { if (!backup) return; final TFile backupDir = new TFile(createTempFile( backupPrefix + '.', '.' + backupExtension, buildDirectory)); getLog().info(backupDir + ": Creating class file backup directory."); outputDirectory().cp_rp(backupDir.rm_r()); }
private void rm(final String[] args, final boolean recursive) throws IllegalUsageException, IOException { if (args.length < 1) throw new IllegalUsageException(); for (int i = 0; i < args.length; i++) { final TFile file = new TFile(args[i]); try { if (recursive) file.rm_r(); else file.rm(); } catch (IOException ex) { final String msg; if (!file.exists()) msg = resources.getString("rm.nsfod"); else if (file.isDirectory()) if (file.list().length > 0) msg = resources.getString("rm.dne"); else msg = resources.getString("rm.crd"); else if (file.isFile()) msg = resources.getString("rm.crf"); else msg = resources.getString("rm.crsfod"); throw new IOException(file + " (" + msg + ")", ex); } } }
void roundTrip(final int i) throws IOException { final TFile archive = newTempArchive(); final TFile file = new TFile(archive, i + getSuffix() + "/" + i); roundTrip(file); archive.rm_r(); }
private void assertMultithreadedSingleArchiveMultipleEntriesReading( final int nEntries, final int nThreads) throws Exception { // Create test archive file. createTestArchive(nEntries); class CheckAllEntries implements Callable<Void> { @Override public Void call() throws IOException { assertArchiveEntries(archive, nEntries); return null; } } // CheckAllEntries class CheckAllEntriesFactory implements TaskFactory { @Override public Callable<?> newTask(int threadNum) { return new CheckAllEntries(); } } // CheckAllEntriesFactory try { runConcurrent(nThreads, new CheckAllEntriesFactory()).join(); } finally { TFile.rm_r(archive); } }
@Test public final void testIllegalDirectoryOperations() throws IOException { try { final String[] names = { "inner" + getSuffix(), "dir", }; TPath file = archive; for (int i = 0; i <= names.length; i++) { final TPath file2 = file.toNonArchivePath(); createDirectory(file2); assertIllegalDirectoryOperations(file2); delete(file2); createDirectory(file); assertIllegalDirectoryOperations(file); if (i < names.length) file = file.resolve(names[i]); } } finally { archive.toFile().rm_r(); } }
@Test public final void testCopyContainingOrSameFiles() throws IOException { assert !exists(archive); final TPath dir = archive.getParent(); assertNotNull(dir); final TPath entry = archive.resolve("entry"); assertCopyContainingOrSameFiles0(dir, archive); assertCopyContainingOrSameFiles0(archive, entry); copy(new ByteArrayInputStream(getData()), entry); assertCopyContainingOrSameFiles0(dir, archive); assertCopyContainingOrSameFiles0(archive, entry); archive.toFile().rm_r(); }
@Test public final void testList() throws IOException { final Path dir = createTempFile(); final TPath tdir = new TPath(dir); assertNull(listFiles(dir)); assertNull(listFiles(tdir)); assertNull(listFiles(tdir.toNonArchivePath())); delete(dir); // Create regular directory for testing. createDirectory(dir); for (int i = MEMBERS.length; --i >= 0; ) createFile(dir.resolve(MEMBERS[i])); final Path[] files = listFiles(dir); Arrays.sort(files); assertList(files, tdir); tdir.toFile().rm_r(); // Repeat test with regular archive file. createDirectory(tdir); for (int i = MEMBERS.length; --i >= 0; ) createFile(tdir.resolve(MEMBERS[i])); assertList(files, tdir); tdir.toFile().rm_r(); }
private void assertRenameArchiveToTemp(final TPath archive) throws IOException { assert archive.isArchive(); // regular archive or false positive assert !archive.isEntry(); // not contained in another archive file // Create a temporary file. TPath tmp = new TPath(Files.createTempFile(TEMP_FILE_PREFIX, null)); delete(tmp); assertFalse(exists(tmp)); assertFalse(exists(tmp.toNonArchivePath())); // Now rename the archive to the temporary path. // Depending on the true state of the object "archive", this will // either create a directory (iff archive is a regular archive) or a // plain file (iff archive is a false positive). archive.toFile().mv(tmp.toFile()); assertFalse(exists(archive)); assertFalse(exists(archive.toNonArchivePath())); // Now delete resulting temporary file or directory. tmp.toFile().rm_r(); assertFalse(exists(tmp)); assertFalse(exists(tmp.toNonArchivePath())); }
private void assertMultithreadedSingleArchiveMultipleEntriesReading( final int nEntries, final int nThreads) throws Exception { // Create test archive file. createTestArchive(nEntries); class CheckAllEntries implements Callable<Void> { @Override public Void call() throws IOException { assertArchiveEntries(archive, nEntries); return null; } } // CheckAllEntries class CheckAllEntriesFactory implements TaskFactory { @Override public Callable<?> newTask(int threadNum) { return new CheckAllEntries(); } } // CheckAllEntriesFactory try { runConcurrent(nThreads, new CheckAllEntriesFactory()).join(); } finally { archive.toFile().rm_r(); } }
@Test public final void testList() throws IOException { final File dir = createTempFile(); final TFile tdir = new TFile(dir); assertNull(dir.listFiles()); assertNull(tdir.listFiles()); assertNull(tdir.toNonArchiveFile().listFiles()); TFile.rm(dir); // Create regular directory for testing. assertTrue(dir.mkdir()); for (int i = MEMBERS.length; --i >= 0; ) assertTrue(new File(dir, MEMBERS[i]).createNewFile()); final File[] files = dir.listFiles(); Arrays.sort(files); assertList(files, tdir); TFile.rm_r(tdir); // Repeat test with regular archive file. assertTrue(tdir.mkdir()); for (int i = MEMBERS.length; --i >= 0; ) assertTrue(new TFile(tdir, MEMBERS[i]).createNewFile()); assertList(files, tdir); TFile.rm_r(tdir); }
@Test public final void testCopyContainingOrSameFiles() throws IOException { assert !archive.exists(); final TFile dir = archive.getParentFile(); assertNotNull(dir); final TFile entry = new TFile(archive, "entry"); assertCopyContainingOrSameFiles0(dir, archive); assertCopyContainingOrSameFiles0(archive, entry); entry.input(new ByteArrayInputStream(getData())); assertCopyContainingOrSameFiles0(dir, archive); assertCopyContainingOrSameFiles0(archive, entry); TFile.rm_r(archive); }
} finally { assertArchiveEntries(archive, NUM_IO_THREADS); TFile.rm_r(archive);
} finally { assertArchiveEntries(archive, NUM_IO_THREADS); archive.toFile().rm_r();
@Test public final void testIllegalDirectoryOperations() throws IOException { try { final String[] names = { "inner" + getSuffix(), "dir", }; TFile file = archive; for (int i = 0; i <= names.length; i++) { final TFile file2 = file.toNonArchiveFile(); assertTrue(file2.mkdir()); assertIllegalDirectoryOperations(file2); file2.rm(); assertTrue(file.mkdir()); assertIllegalDirectoryOperations(file); if (i < names.length) file = new TFile(file, names[i]); } } finally { archive.rm_r(); } }
private void assertRenameArchiveToTemp(final TFile archive) throws IOException { assert archive.isArchive(); // regular archive or false positive assert !archive.isEntry(); // not contained in another archive file // Create a temporary file. TFile tmp = new TFile(TFile.createTempFile(TEMP_FILE_PREFIX, null)); tmp.rm(); assertFalse(tmp.exists()); assertFalse(tmp.toNonArchiveFile().exists()); // Now rename the archive to the temporary path. // Depending on the true state of the object "archive", this will // either create a directory (iff archive is a regular archive) or a // plain file (iff archive is a false positive). archive.mv(tmp); assertFalse(archive.exists()); assertFalse(archive.toNonArchiveFile().exists()); // Now delete resulting temporary file or directory. tmp.rm_r(); assertFalse(tmp.exists()); assertFalse(tmp.toNonArchiveFile().exists()); }