Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Michel-Lemieux2002-03-04 17:37:35 -0500
committerJean Michel-Lemieux2002-03-04 17:37:35 -0500
commit21f90aa474b04dbe3954fde2e2de2d9dac66c74c (patch)
treef8e4f59f9fb923f56e96e84666dc2c158f7875cf
parent27e4e14d7dde11c590db32fa7f713c2faf864a49 (diff)
downloadeclipse.platform.team-21f90aa474b04dbe3954fde2e2de2d9dac66c74c.tar.gz
eclipse.platform.team-21f90aa474b04dbe3954fde2e2de2d9dac66c74c.tar.xz
eclipse.platform.team-21f90aa474b04dbe3954fde2e2de2d9dac66c74c.zip
refactoring for IResource progress...
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java30
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFolder.java46
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java31
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseSynchronizer.java266
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java24
5 files changed, 249 insertions, 148 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java
index 353a6938e..a2d430ad0 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java
@@ -7,6 +7,7 @@ package org.eclipse.team.internal.ccvs.core.resources;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -16,6 +17,7 @@ import java.util.Date;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
@@ -118,7 +120,13 @@ class EclipseFile extends EclipseResource implements ICVSFile {
throw new CVSException(Policy.bind("LocalFile.invalidDateFormat", date), e); //$NON-NLS-1$
}
}
- getIOFile().setLastModified(millSec);
+ getIOFile().setLastModified(millSec);
+ try {
+ // Needed for workaround to Platform Core Bug #
+ resource.refreshLocal(IResource.DEPTH_ZERO, null);
+ } catch (CoreException e) {
+ throw CVSException.wrapException(e);
+ }
}
/*
@@ -178,14 +186,7 @@ class EclipseFile extends EclipseResource implements ICVSFile {
public String getRemoteLocation(ICVSFolder stopSearching) throws CVSException {
return getParent().getRemoteLocation(stopSearching) + SEPARATOR + getName();
}
-
- /*
- * @see ICVSResource#unmanage()
- */
- public void unmanage() throws CVSException {
- EclipseSynchronizer.getInstance().deleteResourceSync(resource, new NullProgressMonitor());
- }
-
+
/*
* @see ICVSFile#setReadOnly()
*/
@@ -199,4 +200,15 @@ class EclipseFile extends EclipseResource implements ICVSFile {
private IFile getIFile() {
return (IFile)resource;
}
+
+ /*
+ * To allow accessing size and timestamp for the underlying java.io.File
+ */
+ private File getIOFile() {
+ IPath location = resource.getLocation();
+ if(location!=null) {
+ return location.toFile();
+ }
+ return null;
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFolder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFolder.java
index 9806a8013..33a00e0cc 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFolder.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFolder.java
@@ -14,6 +14,8 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -213,8 +215,9 @@ class EclipseFolder extends EclipseResource implements ICVSFolder {
/*
* @see ICVSResource#unmanage()
*/
- public void unmanage() throws CVSException {
+ public void unmanage() throws CVSException {
EclipseSynchronizer.getInstance().deleteFolderSync((IContainer)resource, new NullProgressMonitor());
+ super.unmanage();
}
/*
@@ -249,25 +252,32 @@ class EclipseFolder extends EclipseResource implements ICVSFolder {
/*
* @see ICVSFolder#run(ICVSRunnable, IProgressMonitor)
*/
- public void run(ICVSRunnable job, IProgressMonitor monitor) throws CVSException {
- monitor = Policy.monitorFor(monitor);
+ public void run(final ICVSRunnable job, IProgressMonitor monitor) throws CVSException {
+ final CVSException[] error = new CVSException[1];
try {
- monitor.beginTask(null, 100);
- try {
- EclipseSynchronizer.getInstance().beginOperation(Policy.subMonitorFor(monitor, 5));
- job.run(Policy.subMonitorFor(monitor, 85));
- } finally {
- EclipseSynchronizer.getInstance().endOperation(Policy.subMonitorFor(monitor, 8));
- try {
- // this is temporary until core allows setting of timestamp via a
- // IResource handle
- resource.refreshLocal(IResource.DEPTH_INFINITE, Policy.subMonitorFor(monitor, 2));
- } catch(CoreException e) {
- throw CVSException.wrapException(e);
+ ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor) throws CoreException {
+ monitor = Policy.monitorFor(monitor);
+ try {
+ monitor.beginTask(null, 100);
+ try {
+ EclipseSynchronizer.getInstance().beginOperation(Policy.subMonitorFor(monitor, 5));
+ job.run(Policy.subMonitorFor(monitor, 85));
+ } finally {
+ EclipseSynchronizer.getInstance().endOperation(Policy.subMonitorFor(monitor, 8));
+ }
+ } catch(CVSException e) {
+ error[0] = e;
+ } finally {
+ monitor.done();
+ }
}
- }
- } finally {
- monitor.done();
+ }, monitor);
+ } catch(CoreException e) {
+ throw CVSException.wrapException(e);
+ }
+ if(error[0]!=null) {
+ throw error[0];
}
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java
index 0fd4c2db8..e752f4e23 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java
@@ -5,14 +5,10 @@ package org.eclipse.team.internal.ccvs.core.resources;
* All Rights Reserved.
*/
-import java.io.File;
-
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.team.ccvs.core.CVSProviderPlugin;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.team.ccvs.core.ICVSFolder;
import org.eclipse.team.ccvs.core.ICVSResource;
import org.eclipse.team.core.IIgnoreInfo;
@@ -75,7 +71,7 @@ abstract class EclipseResource implements ICVSResource {
*/
public void delete() throws CVSException {
try {
- resource.delete(true /*force*/, null);
+ resource.delete(false /*force*/, null);
} catch(CoreException e) {
throw new CVSException(e.getStatus());
}
@@ -235,28 +231,11 @@ abstract class EclipseResource implements ICVSResource {
public String toString() {
return getPath();
}
-
- /*
- * REFACTOR Temporary helper for accessing the underlying file associated with this
- * eclipse resource. Must be removed when the refactoring is complete.
- */
- protected File getIOFile() {
- IPath location = resource.getLocation();
- if(location!=null) {
- return location.toFile();
- }
- return null;
- }
/*
- * @see ICVSResource#reloadSyncInfo(IProgressMonitor)
- */
- public void reloadSyncInfo(IProgressMonitor monitor) throws CVSException {
- }
-
- /*
- * @see ICVSResource#saveSyncInfo(IProgressMonitor)
+ * @see ICVSResource#unmanage()
*/
- public void saveSyncInfo(IProgressMonitor monitor) throws CVSException {
+ public void unmanage() throws CVSException {
+ EclipseSynchronizer.getInstance().deleteResourceSync(resource, new NullProgressMonitor());
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseSynchronizer.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseSynchronizer.java
index 6f72d7fce..409debca4 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseSynchronizer.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseSynchronizer.java
@@ -18,6 +18,7 @@ import java.util.Set;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.ISynchronizer;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -31,6 +32,7 @@ import org.eclipse.team.ccvs.core.ICVSFile;
import org.eclipse.team.ccvs.core.ICVSFolder;
import org.eclipse.team.ccvs.core.ICVSResource;
import org.eclipse.team.core.TeamPlugin;
+import org.eclipse.team.core.sync.ISyncProvider;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
@@ -57,8 +59,12 @@ public class EclipseSynchronizer {
// are keys for storing the sync info.
private static final QualifiedName FOLDER_SYNC_KEY = new QualifiedName(CVSProviderPlugin.ID, "folder-sync");
private static final QualifiedName RESOURCE_SYNC_KEY = new QualifiedName(CVSProviderPlugin.ID, "resource-sync");
+ private static final QualifiedName RESOURCE_SYNC_LOADED_KEY = new QualifiedName(CVSProviderPlugin.ID, "folder-has-loaded-childsync");
private static final QualifiedName IGNORE_SYNC_KEY = new QualifiedName(CVSProviderPlugin.ID, "folder-ignore");
+ private static final byte[] EMPTY_BYTES = new byte[0];
+ private static final FolderSyncInfo EMPTY_FOLDER_SYNC_INFO = new FolderSyncInfo("", "", null, false);
+
// the cvs eclipse synchronizer is a singleton
private static EclipseSynchronizer instance;
@@ -67,23 +73,30 @@ public class EclipseSynchronizer {
private Set changedResources = new HashSet();
private Set changedFolders = new HashSet();
+ private static final boolean DEBUG = false;
+
private EclipseSynchronizer() {
getSynchronizer().add(RESOURCE_SYNC_KEY);
+ getSynchronizer().add(RESOURCE_SYNC_LOADED_KEY);
getSynchronizer().add(FOLDER_SYNC_KEY);
getSynchronizer().add(IGNORE_SYNC_KEY);
+ try {
+ flushAll(ResourcesPlugin.getWorkspace().getRoot(), false /*don't purge from disk*/);
+ } catch(CVSException e) {
+ // severe problem, it would mean that we are working with stale sync info
+ CVSProviderPlugin.log(e.getStatus());
+ }
}
public static EclipseSynchronizer getInstance() {
if (instance == null) {
- ResourcesPlugin.getWorkspace().getSynchronizer().remove(RESOURCE_SYNC_KEY);
- ResourcesPlugin.getWorkspace().getSynchronizer().remove(FOLDER_SYNC_KEY);
- ResourcesPlugin.getWorkspace().getSynchronizer().remove(IGNORE_SYNC_KEY);
- instance = new EclipseSynchronizer();
+ instance = new EclipseSynchronizer();
}
return instance;
}
public void setFolderSync(IContainer folder, FolderSyncInfo info) throws CVSException {
+ Assert.isNotNull(info);
try {
beginOperation(null);
setCachedFolderSync(folder, info);
@@ -94,53 +107,46 @@ public class EclipseSynchronizer {
}
public FolderSyncInfo getFolderSync(IContainer folder) throws CVSException {
- try {
- beginOperation(null);
- if(folder.getType()==IResource.ROOT) return null;
- FolderSyncInfo info = getCachedFolderSync(folder);
- if (info == null) {
- info = SyncFileWriter.readFolderConfig(CVSWorkspaceRoot.getCVSFolderFor(folder));
- if(info!=null) {
- setCachedFolderSync(folder, info);
- // read the child meta-files also
- getMetaResourceSyncForFolder(folder, null);
- }
- }
- return info;
- } finally {
- endOperation(null);
+ if (folder.getType() == IResource.ROOT) return null;
+ FolderSyncInfo info = getCachedFolderSync(folder);
+ if (info == null && folder.exists()) {
+ // read folder sync info and remember it
+ // -- if none found then remember that fact for later
+ info = SyncFileWriter.readFolderConfig(CVSWorkspaceRoot.getCVSFolderFor(folder));
+ if (info == null) info = EMPTY_FOLDER_SYNC_INFO;
+ setCachedFolderSync(folder, info);
}
+ if (info == EMPTY_FOLDER_SYNC_INFO) info = null;
+ return info;
}
public void setResourceSync(IResource resource, ResourceSyncInfo info) throws CVSException {
+ Assert.isNotNull(info);
try {
beginOperation(null);
+ ensureChildResourceSyncLoaded(resource.getParent());
setCachedResourceSync(resource, info);
changedResources.add(resource);
} finally {
endOperation(null);
- }
+ }
}
public ResourceSyncInfo getResourceSync(IResource resource) throws CVSException {
- try {
- beginOperation(null);
- if(resource.getType()==IResource.ROOT) return null;
- ResourceSyncInfo info = getCachedResourceSync(resource);
- if(info==null) {
- info = getMetaResourceSyncForFolder(resource.getParent(), resource);
- }
- return info;
- } finally {
- endOperation(null);
- }
+ if (resource.getType() == IResource.ROOT) return null;
+ ensureChildResourceSyncLoaded(resource.getParent());
+ return getCachedResourceSync(resource);
}
public void deleteFolderSync(IContainer folder, IProgressMonitor monitor) throws CVSException {
try {
beginOperation(null);
- setCachedFolderSync(folder, null);
- changedFolders.add(folder);
+ FolderSyncInfo info = getCachedFolderSync(folder);
+ if (info != null && info != EMPTY_FOLDER_SYNC_INFO) {
+ // remember that we deleted the folder sync info
+ setCachedFolderSync(folder, EMPTY_FOLDER_SYNC_INFO);
+ changedFolders.add(folder);
+ }
} finally {
endOperation(null);
}
@@ -149,6 +155,7 @@ public class EclipseSynchronizer {
public void deleteResourceSync(IResource resource, IProgressMonitor monitor) throws CVSException {
try {
beginOperation(null);
+ ensureChildResourceSyncLoaded(resource.getParent());
setCachedResourceSync(resource, null);
changedResources.add(resource);
} finally {
@@ -177,15 +184,12 @@ public class EclipseSynchronizer {
public IResource[] members(IContainer folder) throws CVSException {
try {
// initialize cache if needed, this will create phantoms
- FolderSyncInfo info = getCachedFolderSync(folder);
- if(info==null) {
- getMetaResourceSyncForFolder(folder, null);
- }
+ ensureChildResourceSyncLoaded(folder);
IResource[] children = folder.members(true);
List list = new ArrayList(children.length);
for (int i = 0; i < children.length; ++i) {
IResource child = children[i];
- if (!child.isPhantom() || getCachedResourceSync(child) != null) {
+ if (! child.isPhantom() || getCachedResourceSync(child) != null) {
list.add(child);
}
}
@@ -197,7 +201,10 @@ public class EclipseSynchronizer {
public void beginOperation(IProgressMonitor monitor) throws CVSException {
if (nestingCount++ == 0) {
- // any work here?
+ // any work here?
+
+ // uncomment this line to bypass cache for testing
+ //flushAll(ResourcesPlugin.getWorkspace().getRoot(), false /*don't purge from disk*/);
}
}
@@ -207,33 +214,58 @@ public class EclipseSynchronizer {
try {
monitor = Policy.monitorFor(monitor);
int numResources = changedFolders.size() + changedResources.size();
- monitor.beginTask("Updating CVS synchronization information...", numResources);
- // write sync info to disk
+ monitor.beginTask(null, numResources);
+ monitor.subTask("Updating CVS synchronization information...");
+ /* write sync info to disk */
+ List deletedFolderSync = new ArrayList();
+
+ // folder sync info changes
Iterator it = changedFolders.iterator();
while (it.hasNext()) {
IContainer folder = (IContainer) it.next();
FolderSyncInfo info = getCachedFolderSync(folder);
ICVSFolder cvsFolder = CVSWorkspaceRoot.getCVSFolderFor(folder);
- if (info != null) {
- SyncFileWriter.writeFolderConfig(cvsFolder, info);
+ if (info == EMPTY_FOLDER_SYNC_INFO) {
+ // deleted folder sync info since we loaded it, postpone change until later
+ deletedFolderSync.add(folder);
+ } else if (info == null) {
+ // attempted to delete folder sync info for a previously unmanaged folder
+ // no-op
} else {
- SyncFileWriter.deleteFolderSync(cvsFolder);
+ // modified or created new folder sync info since we loaded it
+ SyncFileWriter.writeFolderConfig(cvsFolder, info);
}
monitor.worked(1);
}
+
+ // resource sync info changes
it = changedResources.iterator();
while (it.hasNext()) {
IResource resource = (IResource) it.next();
ResourceSyncInfo info = getCachedResourceSync(resource);
ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
- if (info != null) {
- SyncFileWriter.writeResourceSync(cvsResource, info);
- } else {
+ if(!isChildResourceSyncLoaded(resource.getParent())) {
+ return;
+ }
+ Assert.isTrue(isChildResourceSyncLoaded(resource.getParent()));
+ if (info == null) {
+ // deleted resource sync info since we loaded it
SyncFileWriter.deleteSync(cvsResource);
+ } else {
+ // modified or created new resource sync info since we loaded it
+ SyncFileWriter.writeResourceSync(cvsResource, info);
}
monitor.worked(1);
}
+ // folder sync info deletes
+ it = deletedFolderSync.iterator();
+ while (it.hasNext()) {
+ IContainer folder = (IContainer) it.next();
+ // flush everything that was cached from the CVS subdirectory
+ flushAll(folder, true /*purge from disk*/);
+ }
+
// broadcast events
changedResources.addAll(changedFolders);
IResource[] resources = (IResource[]) changedResources.toArray(
@@ -253,22 +285,26 @@ public class EclipseSynchronizer {
return ResourcesPlugin.getWorkspace().getSynchronizer();
}
+ /*
+ * Returns the cached resource sync info, or null if none found.
+ */
private ResourceSyncInfo getCachedResourceSync(IResource resource) throws CVSException {
try {
byte[] bytes = getSynchronizer().getSyncInfo(RESOURCE_SYNC_KEY, resource);
- if(bytes==null) {
- return null;
- }
+ if(bytes == null) return null;
return new ResourceSyncInfo(new String(bytes), null, null);
} catch(CoreException e) {
throw CVSException.wrapException(e);
}
}
+ /*
+ * Sets the cached resource sync info, use null to delete it.
+ */
private void setCachedResourceSync(IResource resource, ResourceSyncInfo info) throws CVSException {
try {
if(info==null) {
- getSynchronizer().flushSyncInfo(RESOURCE_SYNC_KEY, resource, IResource.DEPTH_ZERO);
+ getSynchronizer().setSyncInfo(RESOURCE_SYNC_KEY, resource, null); // faster than flush
} else {
getSynchronizer().setSyncInfo(RESOURCE_SYNC_KEY, resource, info.getEntryLine(true).getBytes());
}
@@ -277,12 +313,15 @@ public class EclipseSynchronizer {
}
}
+ /*
+ * Returns the cached sync info for a folder, null if none found, or
+ * special placeholder EMPTY_FOLDER_SYNC_INFO for deleted sync info.
+ */
private FolderSyncInfo getCachedFolderSync(IContainer folder) throws CVSException {
try {
byte[] bytes = getSynchronizer().getSyncInfo(FOLDER_SYNC_KEY, folder);
- if(bytes==null) {
- return null;
- }
+ if (bytes == null) return null;
+ if (bytes.length == 0) return EMPTY_FOLDER_SYNC_INFO; // return placeholder for deleted sync info
DataInputStream is = new DataInputStream(new ByteArrayInputStream(bytes));
String repo = is.readUTF();
String root = is.readUTF();
@@ -300,10 +339,17 @@ public class EclipseSynchronizer {
}
}
+ /*
+ * Sets the cached sync info for a folder, use null to flush, or special
+ * EMPTY_FOLDER_SYNC_INFO placeholder for deleted sync info.
+ */
private void setCachedFolderSync(IContainer folder, FolderSyncInfo info) throws CVSException {
try {
- if(info==null) {
- getSynchronizer().flushSyncInfo(FOLDER_SYNC_KEY, folder, IResource.DEPTH_INFINITE);
+ if (info == null) {
+ getSynchronizer().setSyncInfo(FOLDER_SYNC_KEY, folder, null); // faster than flush
+ } else if (info == EMPTY_FOLDER_SYNC_INFO ) {
+ // memorize placeholder for deleted sync info
+ getSynchronizer().setSyncInfo(FOLDER_SYNC_KEY, folder, EMPTY_BYTES);
} else {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream os = new DataOutputStream(bos);
@@ -329,9 +375,7 @@ public class EclipseSynchronizer {
private String[] getCachedFolderIgnores(IContainer folder) throws CVSException {
try {
byte[] bytes = getSynchronizer().getSyncInfo(IGNORE_SYNC_KEY, folder);
- if(bytes==null) {
- return null;
- }
+ if (bytes == null) return null;
DataInputStream is = new DataInputStream(new ByteArrayInputStream(bytes));
int count = is.readInt();
String[] ignoreList = new String[count];
@@ -348,9 +392,10 @@ public class EclipseSynchronizer {
private void setCachedFolderIgnores(IContainer folder, String[] ignores) throws CVSException {
try {
- if(ignores==null || ignores.length==0) {
- getSynchronizer().flushSyncInfo(IGNORE_SYNC_KEY, folder, IResource.DEPTH_ZERO);
+ if (ignores == null) {
+ getSynchronizer().setSyncInfo(IGNORE_SYNC_KEY, folder, null); // faster than flush
} else {
+ // a zero-length array indicates there were no ignores found
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream os = new DataOutputStream(bos);
os.writeInt(ignores.length);
@@ -368,33 +413,86 @@ public class EclipseSynchronizer {
}
/*
- * Reads and caches the ResourceSyncInfos for this folder. If target is non-null, then
- * returns the ResourceSync for this resource is it is found.
+ * Reads and caches the ResourceSyncInfos for this folder if not already cached.
*/
- private ResourceSyncInfo getMetaResourceSyncForFolder(IContainer folder, IResource target) throws CVSException {
- ResourceSyncInfo info = null;
- if (folder!=null) {
- ResourceSyncInfo[] infos = SyncFileWriter.readEntriesFile(CVSWorkspaceRoot.getCVSFolderFor(folder));
- if (infos != null) {
- for (int i = 0; i < infos.length; i++) {
- ResourceSyncInfo syncInfo = infos[i];
- IResource peer;
- if (target!=null && target.getName().equals(syncInfo.getName())) {
- info = syncInfo;
- peer = target;
- } else {
- IPath path = new Path(syncInfo.getName());
- if (syncInfo.isDirectory()) {
- peer = folder.getFolder(path);
- } else {
- peer = folder.getFile(path);
+ private void ensureChildResourceSyncLoaded(IContainer folder) throws CVSException {
+ // don't try to load if the information is already cached
+ if (isChildResourceSyncLoaded(folder)) return;
+ ResourceSyncInfo[] infos = SyncFileWriter.readEntriesFile(CVSWorkspaceRoot.getCVSFolderFor(folder));
+ if (infos != null) {
+ for (int i = 0; i < infos.length; i++) {
+ ResourceSyncInfo syncInfo = infos[i];
+ IResource peer;
+ IPath path = new Path(syncInfo.getName());
+ if (syncInfo.isDirectory()) {
+ peer = folder.getFolder(path);
+ } else {
+ peer = folder.getFile(path);
+ }
+ // may create a phantom if the sibling resource does not exist.
+ setCachedResourceSync(peer, syncInfo);
+ }
+ }
+ setChildResourceSyncLoaded(folder, true);
+ }
+
+ private boolean isChildResourceSyncLoaded(IContainer folder) throws CVSException {
+ try {
+ // root folder has no entries therefore info is always loaded
+ if (folder.getType() == IResource.ROOT || ! folder.exists()) return true;
+ return getSynchronizer().getSyncInfo(RESOURCE_SYNC_LOADED_KEY, folder) != null;
+ } catch(CoreException e) {
+ throw CVSException.wrapException(e);
+ }
+ }
+
+ private void setChildResourceSyncLoaded(IContainer folder, boolean isLoaded) throws CVSException {
+ try {
+ getSynchronizer().setSyncInfo(RESOURCE_SYNC_LOADED_KEY, folder, isLoaded ? EMPTY_BYTES : null);
+ } catch(CoreException e) {
+ throw CVSException.wrapException(e);
+ }
+
+ }
+
+ private void flushChildResourceSync(IContainer folder, int depth) throws CVSException {
+ // flushSyncInfo fails with an exception if the folder does not exist
+ if (! folder.exists()) return;
+ try {
+ byte[] folderSyncBytes = getSynchronizer().getSyncInfo(RESOURCE_SYNC_KEY, folder);
+ getSynchronizer().flushSyncInfo(RESOURCE_SYNC_KEY, folder, depth);
+ getSynchronizer().setSyncInfo(RESOURCE_SYNC_KEY, folder, folderSyncBytes);
+ } catch(CoreException e) {
+ throw CVSException.wrapException(folder, "Error flushing a folder's children sync", e);
+ }
+ }
+
+ private void flushAll(final IContainer root, final boolean purgeFromDisk) throws CVSException {
+ if (! (root.exists() || root.isPhantom())) return;
+ try {
+ // purge sync information from children
+ root.accept(new IResourceVisitor() {
+ public boolean visit(IResource resource) throws CoreException {
+ if(! root.equals(resource)) {
+ // don't clear resource sync on root since it might still be managed
+ // by its parent
+ getSynchronizer().setSyncInfo(RESOURCE_SYNC_KEY, resource, null);
+ }
+ if(resource.getType()!=IResource.FILE) {
+ IContainer folder = (IContainer) resource;
+ getSynchronizer().setSyncInfo(RESOURCE_SYNC_LOADED_KEY, folder, null);
+ getSynchronizer().setSyncInfo(FOLDER_SYNC_KEY, folder, null);
+ getSynchronizer().setSyncInfo(IGNORE_SYNC_KEY, folder, null);
+ if(purgeFromDisk) {
+ SyncFileWriter.deleteCVSSubDirectory(folder);
}
}
- // may create a phantom if the sibling resource does not exist.
- setCachedResourceSync(peer, syncInfo);
+ return true;
}
- }
+
+ }, IResource.DEPTH_INFINITE, true /*include phantoms*/);
+ } catch(CoreException e) {
+ throw CVSException.wrapException(root, "Problems occured flushing synchronizer cache", e);
}
- return info;
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java
index 3bd908695..f55486c27 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java
@@ -17,7 +17,10 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.team.ccvs.core.CVSTag;
import org.eclipse.team.ccvs.core.ICVSFile;
import org.eclipse.team.ccvs.core.ICVSFolder;
@@ -125,20 +128,19 @@ public class SyncFileWriter {
* Delete this file from Entries/Permissions file
*/
public static void deleteSync(ICVSResource file) throws CVSException {
- if(file.isFolder()) {
- writeEntriesLog(file, new ResourceSyncInfo(file.getName()), REMOVE_TAG);
- } else {
- writeEntriesLog(file, new ResourceSyncInfo(file.getName(), "0", "", "", null, ""), REMOVE_TAG); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ICVSFolder parent = file.getParent();
+ if(parent!=null && parent.exists()) {
+ if(file.isFolder()) {
+ writeEntriesLog(file, new ResourceSyncInfo(file.getName()), REMOVE_TAG);
+ } else {
+ writeEntriesLog(file, new ResourceSyncInfo(file.getName(), "0", "", "", null, ""), REMOVE_TAG); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
}
}
- public static void deleteFolderSync(ICVSFolder folder) throws CVSException {
- ICVSFolder[] children = folder.getFolders();
- for (int i = 0; i < children.length; i++) {
- deleteFolderSync(children[i]);
- }
- ICVSFolder cvsSubDir = getCVSSubdirectory(folder);
- cvsSubDir.delete();
+ public static void deleteCVSSubDirectory(IContainer folder) throws CoreException {
+ IContainer cvsSubDir = folder.getFolder(new Path("CVS"));
+ cvsSubDir.delete(false /*force*/, null);
}
/**

Back to the top