private static TFile newNonArchiveFile(TFile file) { return new TFile(file.getParentFile(), file.getName(), TArchiveDetector.NULL); }
/** * Returns the first parent directory (starting from this file) which is * <em>not</em> an archive file or a file located in an archive file. * * @return The first parent directory (starting from this file) which is * <em>not</em> an archive file or a file located in an archive * file. */ public @Nullable TFile getNonArchivedParentFile() { final TFile enclArchive = this.enclArchive; return null != enclArchive ? enclArchive.getNonArchivedParentFile() : getParentFile(); }
private static TFile newNonArchiveFile(TFile file) { return new TFile(file.getParentFile(), file.getName(), TArchiveDetector.NULL); }
private @Nullable TFile[] newPath(final @CheckForNull TFile node, int level) { assert root != null; // FindBugs final TFile[] path; if (root.equals(node)) { path = new TFile[level]; path[0] = root; } else if (null != node) { path = newPath(node.getParentFile(), level + 1); if (path != null) path[path.length - level] = node; } else { path = null; } return path; }
private static boolean isTrueEntry(TFile file) { //return file.isEntry() && file.getParentFile().isDirectory(); // An archive entry always names a parent. This parent must not be // a regular directory. if (!file.isEntry()) return false; TFile parent = file.getParentFile(); assert parent != null : "An archive entry must always name a parent!"; return parent.isDirectory(); }
@Override public boolean mkdirs() { if (null == innerArchive) return file.mkdirs(); final TFile parent = getParentFile(); if (null != parent && !parent.exists()) parent.mkdirs(); // TODO: Profile: return parent.isDirectory() && mkdir(); // May perform better in certain situations where (probably false // positive) archive files are involved. return mkdir(); }
/** * Creates a file object which uses the provided TArchiveDetector, * but does not recognize its own pathname as an archive file. * Please note that this method just creates a file object, * and does not actually operate on the file system. */ private static TFile newNonArchiveFile( String path, TArchiveDetector detector) { TFile file = new TFile(path, detector); return new TFile(file.getParentFile(), file.getName(), TArchiveDetector.NULL); } }
private boolean isSymlink( TFile file ) throws IOException { TFile fileInCanonicalParent = null; java.io.File parentDir = file.getParentFile(); // truezip-plugin specific change if ( parentDir == null ) { fileInCanonicalParent = file; } else { fileInCanonicalParent = new TFile( parentDir.getCanonicalPath(), file.getName() ); } return !fileInCanonicalParent.getCanonicalFile().equals( fileInCanonicalParent.getAbsoluteFile() ); }
/** * Updates the given node in the tree. * This method calls {@link TreeModelListener#treeNodesChanged(TreeModelEvent)} * on all listeners of this {@code TreeModel}. */ public void nodeChanged(final TFile node) { final TFile parent = node.getParentFile(); final int index = getIndexOfChild(parent, node); // old index if (index == -1) return; fireTreeNodesChanged(new TreeModelEvent( this, newTreePath(parent), new int[] { index }, new TFile[] { node })); }
/** * Inserts the given node in the tree. * If {@code node} already exists, nothing happens. * This method calls {@link TreeModelListener#treeNodesInserted(TreeModelEvent)} * on all listeners of this {@code TreeModel}. */ public void nodeInserted(final TFile node) { if (cache.containsKey(node)) return; final TFile parent = node.getParentFile(); forget(parent, false); final int index = getIndexOfChild(parent, node); // new index if (index == -1) return; fireTreeNodesInserted(new TreeModelEvent( this, newTreePath(parent), new int[] { index }, new TFile[] { node })); }
final TFile oldNode = (TFile) getLeadSelectionPath().getLastPathComponent(); final TFile parent = oldNode.getParentFile(); assert parent != null; if (!oldNode.isDirectory()) {
/** * Returns a file object for the same path name, but does not detect any * archive file name patterns in the last path name segment. * The parent file object is unaffected by this transformation, so the * path name of this file object may address an entry in an archive file. * * @return A file object for the same path name, but does not detect any * archive file name patterns in the last path name segment. * @see TVFS#umount(TFile) * @since TrueZIP 7.5 */ @ExpertFeature( level=INTERMEDIATE, value=INJECTING_A_DIFFERENT_DETECTOR_FOR_THE_SAME_PATH_MAY_CORRUPT_DATA) public TFile toNonArchiveFile() { return isArchive() ? new TFile(getParentFile(), getName(), TArchiveDetector.NULL) : this; }
@Override public File getParentDirectory(File file) { final TFile tfile = wrap(file); if (tfile.isEntry()) return createFileObject(tfile.getParentFile()); return createFileObject(delegate.getParentDirectory(unwrap(file))); } }
if (null != innerArchive) { if (recursive) { final TFile parent = getParentFile(); if (null != parent && !parent.exists()) parent.mkdir(recursive);
public void copyFile( TFile source, TFile dest ) throws IOException TFile destParent = (TFile) dest.getParentFile(); source = new TFile( source.getParentFile(), source.getName(), TArchiveDetector.NULL ); dest = new TFile( dest.getParentFile(), dest.getName(), TArchiveDetector.NULL );
/** * Removes the given node from the tree. * This method calls {@link TreeModelListener#treeNodesRemoved(TreeModelEvent)} * on all listeners of this {@code TreeModel}. */ public void nodeRemoved(final TFile node) { final TFile parent = node.getParentFile(); final int index = getIndexOfChild(parent, node); // old index if (index == -1) return; forget(node, true); forget(parent, false); // Fill cache again so that subsequent removes don't suffer a cache miss. // Otherwise, the display wouldn't mirror the cache anymore. getChildren(parent); fireTreeNodesRemoved(new TreeModelEvent( this, newTreePath(parent), new int[] { index }, new TFile[] { node })); }
@Test public void testGetParentFile() { TFile abcdefgh = new TFile("a/b.mok/c/d/e.mok/f.mok/g/h.mok"); TFile abcdefg = abcdefgh.getParentFile(); TFile abcdef = abcdefg .getParentFile(); TFile abcde = abcdef .getParentFile(); TFile abcd = abcde .getParentFile(); TFile abc = abcd .getParentFile(); TFile ab = abc .getParentFile(); TFile a = ab .getParentFile(); TFile n = a .getParentFile(); assertEquals(abcdefgh.getInnerArchive(), abcdefgh); assertEquals(abcdefgh.getEnclArchive() , abcdef); assertEquals(abcdefg .getInnerArchive(), abcdef); assertEquals(abcdefg .getEnclArchive() , abcdef); assertEquals(abcdef .getInnerArchive(), abcdef); assertEquals(abcdef .getEnclArchive() , abcde); assertEquals(abcde .getInnerArchive(), abcde); assertEquals(abcde .getEnclArchive() , ab); assertEquals(abcd .getInnerArchive(), ab); assertEquals(abcd .getEnclArchive() , ab); assertEquals(abc .getInnerArchive(), ab); assertEquals(abc .getEnclArchive() , ab); assertEquals(ab .getInnerArchive(), ab); assertEquals(ab .getEnclArchive() , null); assertEquals(a .getInnerArchive(), null); assertEquals(a .getEnclArchive() , null); assertNull(n); }
@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); }
private void roundTrip(final TFile outer) throws IOException { final TFile inner = new TFile(outer.getParentFile(), "inner" + getSuffix() + "/" + outer.getName()); // This particular sequence has been selected because of its increased // likeliness to fail in case the cache sync logic is not correct. create(inner); check(inner); inner.mv(outer); check(outer); outer.mv(inner); check(inner); inner.rm(); }
private void assertDirectoryTree(TFile basePath, TFile reversePath) throws IOException { if (reversePath == null) { // We're at the leaf of the directory tree. final TFile test = new TFile(basePath, "test.txt"); //testCreateNewFile(basePath, test); assertFileOutputStream(test); return; } final TFile member = new TFile(basePath, reversePath.getName()); final boolean created = member.mkdir(); final TFile children = reversePath.getParentFile(); assertDirectoryTree(member, children); assertListFiles(basePath, member.getName()); assertTrue(member.exists()); assertTrue(member.isDirectory()); assertFalse(member.isFile()); if (member.isArchive()) assertEquals(0, member.length()); if (created) { member.rm(); assertFalse(member.exists()); assertFalse(member.isDirectory()); assertFalse(member.isFile()); assertEquals(0, member.length()); } }