Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SaveIndex.java')
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SaveIndex.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SaveIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SaveIndex.java
new file mode 100644
index 00000000000..2e96e94fcb2
--- /dev/null
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SaveIndex.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.internal.core.index.sourceindexer;
+
+import java.io.IOException;
+
+import org.eclipse.cdt.internal.core.index.IIndex;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
+import org.eclipse.cdt.internal.core.search.processing.JobManager;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/*
+ * Save the index of a project.
+ */
+public class SaveIndex extends IndexRequest {
+ public SaveIndex(IPath indexPath, SourceIndexer indexer) {
+ super(indexPath, indexer);
+ }
+
+ public boolean execute(IProgressMonitor progressMonitor) {
+ if (progressMonitor != null && progressMonitor.isCanceled()) return true;
+
+ /* ensure no concurrent write access to index */
+ IIndex index = indexer.getIndex(this.indexPath, true /*reuse index file*/, false /*don't create if none*/);
+ if (index == null) return true;
+ ReadWriteMonitor monitor = indexer.getMonitorFor(index);
+ if (monitor == null) return true; // index got deleted since acquired
+
+ try {
+ monitor.enterWrite(); // ask permission to write
+ indexer.saveIndex(index);
+ } catch (IOException e) {
+ if (IndexManager.VERBOSE) {
+ JobManager.verbose("-> failed to save index " + this.indexPath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
+ e.printStackTrace();
+ }
+ return false;
+ } finally {
+ monitor.exitWrite(); // free write lock
+ }
+ return true;
+ }
+
+ public String toString() {
+ return "saving index for " + this.indexPath; //$NON-NLS-1$
+ }
+}

Back to the top