You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ad...@apache.org on 2003/02/21 14:16:40 UTC
cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl VirtualFileSystem.java
adammurdoch 2003/02/21 05:16:39
Modified: vfs/src/java/org/apache/commons/vfs/provider
AbstractFileObject.java DelegateFileObject.java
vfs/src/java/org/apache/commons/vfs/impl
VirtualFileSystem.java
Log:
Fixed some junction bugs:
- Make sure FileObject.exists() returns true on junction point and ancestors after the
junction is added.
- Don't fire create and delete events twice.
- Fire create events on the junction point and ancestors when the junction is added.
Revision Changes Path
1.26 +34 -26 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
Index: AbstractFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- AbstractFileObject.java 21 Feb 2003 05:16:17 -0000 1.25
+++ AbstractFileObject.java 21 Feb 2003 13:16:39 -0000 1.26
@@ -95,8 +95,8 @@
// Cached info
private boolean attached;
- private AbstractFileObject parent;
private FileType type;
+ private AbstractFileObject parent;
private FileObject[] children;
protected AbstractFileObject( final FileName name,
@@ -481,7 +481,7 @@
}
// List the children
- String[] files;
+ final String[] files;
try
{
files = doListChildren();
@@ -506,7 +506,7 @@
children = new FileObject[ files.length ];
for ( int i = 0; i < files.length; i++ )
{
- String file = files[ i ];
+ final String file = files[ i ];
children[ i ] = fs.resolveFile( name.resolveName( file, NameScope.CHILD ) );
}
}
@@ -674,7 +674,7 @@
}
// Traverse up the heirarchy and make sure everything is a folder
- FileObject parent = getParent();
+ final FileObject parent = getParent();
if ( parent != null )
{
parent.createFolder();
@@ -973,16 +973,19 @@
*/
protected void handleCreate( final FileType newType ) throws Exception
{
- // Fix up state
- type = newType;
- children = EMPTY_FILE_ARRAY;
+ if ( attached )
+ {
+ // Fix up state
+ type = newType;
+ children = EMPTY_FILE_ARRAY;
+
+ // Notify subclass
+ onChange();
+ }
// Notify parent that its child list may no longer be valid
notifyParent();
- // Notify subclass
- onChange();
-
// Notify the file system
fs.fireFileCreated( this );
}
@@ -993,21 +996,36 @@
*/
protected void handleDelete() throws Exception
{
- // Fix up state
- type = null;
- children = null;
+ if ( attached )
+ {
+ // Fix up state
+ type = null;
+ children = null;
+
+ // Notify subclass
+ onChange();
+ }
// Notify parent that its child list may no longer be valid
notifyParent();
- // Notify subclass
- onChange();
-
// Notify the file system
fs.fireFileDeleted( this );
}
/**
+ * Notifies the file that its children have changed.
+ * @todo Indicate whether the child was added or removed, and which child.
+ */
+ protected void childrenChanged() throws Exception
+ {
+ // TODO - this may be called when not attached
+
+ children = null;
+ onChildrenChanged();
+ }
+
+ /**
* Notify the parent of a change to its children, when a child is created
* or deleted.
*/
@@ -1023,16 +1041,6 @@
{
parent.childrenChanged();
}
- }
-
- /**
- * Notifies the file that its children have changed.
- * @todo Indicate whether the child was added or removed, and which child.
- */
- protected void childrenChanged() throws Exception
- {
- children = null;
- onChildrenChanged();
}
/**
1.5 +50 -18 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DelegateFileObject.java
Index: DelegateFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DelegateFileObject.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DelegateFileObject.java 13 Feb 2003 04:28:45 -0000 1.4
+++ DelegateFileObject.java 21 Feb 2003 13:16:39 -0000 1.5
@@ -73,7 +73,6 @@
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
*
- * @todo Deal with case where backing file == null
* @todo Extract subclass that overlays the children
*/
public class DelegateFileObject
@@ -82,43 +81,54 @@
{
private FileObject file;
private final Set children = new HashSet();
+ private boolean ignoreEvent;
public DelegateFileObject( final FileName name,
final AbstractFileSystem fileSystem,
- final FileObject file )
+ final FileObject file ) throws FileSystemException
{
super( name, fileSystem );
this.file = file;
+ if ( file != null )
+ {
+ file.getFileSystem().addListener( file, this );
+ }
}
/** Adds a child to this file. */
public void attachChild( final String baseName ) throws Exception
{
+ final FileType oldType = doGetType();
if ( children.add( baseName ) )
{
childrenChanged();
}
+ maybeTypeChanged( oldType );
}
- /**
- * Attaches this file object to its file resource.
- */
- protected void doAttach() throws Exception
+ /** Attaches or detaches the target file. */
+ public void setFile( final FileObject file ) throws Exception
{
+ final FileType oldType = doGetType();
+
if ( file != null )
{
file.getFileSystem().addListener( file, this );
}
+ this.file = file;
+ maybeTypeChanged( oldType );
}
- /**
- * Detaches this file object from its file resource.
- */
- protected void doDetach() throws Exception
+ private void maybeTypeChanged( final FileType oldType ) throws Exception
{
- if ( file != null )
+ final FileType newType = doGetType();
+ if ( oldType == null && newType != null )
+ {
+ handleCreate( newType );
+ }
+ else if ( oldType != null && newType == null )
{
- file.getFileSystem().removeListener( file, this );
+ handleDelete();
}
}
@@ -126,7 +136,7 @@
* Determines the type of the file, returns null if the file does not
* exist.
*/
- protected FileType doGetType() throws Exception
+ protected FileType doGetType() throws FileSystemException
{
if ( file != null )
{
@@ -199,7 +209,15 @@
*/
protected void doCreateFolder() throws Exception
{
- file.createFolder();
+ ignoreEvent = true;
+ try
+ {
+ file.createFolder();
+ }
+ finally
+ {
+ ignoreEvent = false;
+ }
}
/**
@@ -207,7 +225,15 @@
*/
protected void doDelete() throws Exception
{
- file.delete();
+ ignoreEvent = true;
+ try
+ {
+ file.delete();
+ }
+ finally
+ {
+ ignoreEvent = false;
+ }
}
/**
@@ -284,7 +310,10 @@
*/
public void fileCreated( final FileChangeEvent event ) throws Exception
{
- handleCreate( file.getType() );
+ if ( !ignoreEvent )
+ {
+ handleCreate( file.getType() );
+ }
}
/**
@@ -292,6 +321,9 @@
*/
public void fileDeleted( final FileChangeEvent event ) throws Exception
{
- handleDelete();
+ if ( !ignoreEvent )
+ {
+ handleDelete();
+ }
}
}
1.8 +9 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/VirtualFileSystem.java
Index: VirtualFileSystem.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/VirtualFileSystem.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- VirtualFileSystem.java 20 Feb 2003 01:34:31 -0000 1.7
+++ VirtualFileSystem.java 21 Feb 2003 13:16:39 -0000 1.8
@@ -109,7 +109,7 @@
* file is not cached.
*/
protected FileObject createFile( final FileName name )
- throws FileSystemException
+ throws Exception
{
// Find the file that the name points to
final FileName junctionPoint = getJunctionForFile( name );
@@ -149,6 +149,13 @@
{
// Add to junction table
junctions.put( junctionName, targetFile );
+
+ // Attach to file
+ final DelegateFileObject junctionFile = (DelegateFileObject)getFile( junctionName );
+ if ( junctionFile != null )
+ {
+ junctionFile.setFile( targetFile );
+ }
// Create ancestors of junction point
FileName childName = junctionName;
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org