Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2012-03-02 19:35:11 +0000
committerDavid Green2012-03-02 19:35:11 +0000
commit2befecfd0c9ea65a84504ad94eea486e317407cf (patch)
treed8ae786d9caa90e9abcf7ea5a6978637e207d8ff /org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn
parent20cefdff005db68155f001f06733accae2382a1c (diff)
downloadorg.eclipse.mylyn.tasks-2befecfd0c9ea65a84504ad94eea486e317407cf.tar.gz
org.eclipse.mylyn.tasks-2befecfd0c9ea65a84504ad94eea486e317407cf.tar.xz
org.eclipse.mylyn.tasks-2befecfd0c9ea65a84504ad94eea486e317407cf.zip
bug 372725: handle changes to task data directory
https://bugs.eclipse.org/bugs/show_bug.cgi?id=372725 Change-Id: I24cc1a042b41a0fc83c28638b78c25fb74a818f1
Diffstat (limited to 'org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn')
-rw-r--r--org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java73
1 files changed, 58 insertions, 15 deletions
diff --git a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java
index 1d6b5af36..00ee23ea9 100644
--- a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java
+++ b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java
@@ -110,6 +110,7 @@ import org.eclipse.mylyn.tasks.core.data.TaskData;
* </p>
*
* @author David Green
+ * @author Steffen Pingel
*/
public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeListener, IRepositoryListener {
@@ -337,21 +338,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL
Assert.isNotNull(indexLocation);
this.startupDelay = startupDelay;
- if (!indexLocation.exists()) {
- rebuildIndex = true;
- if (!indexLocation.mkdirs()) {
- StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN,
- "Cannot create task list index folder: " + indexLocation)); //$NON-NLS-1$
- }
- }
- if (indexLocation.exists() && indexLocation.isDirectory()) {
- try {
- directory = new NIOFSDirectory(indexLocation);
- } catch (IOException e) {
- StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN,
- "Cannot create task list index", e)); //$NON-NLS-1$
- }
- }
+ setLocationInternal(indexLocation);
initialize();
}
@@ -393,6 +380,62 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL
this.reindexDelay = reindexDelay;
}
+ public void setLocation(File indexLocation) {
+ try {
+ waitUntilIdle();
+ } catch (InterruptedException e1) {
+ // ignore
+ }
+ setLocationInternal(indexLocation);
+ rebuildIndex = true;
+ scheduleIndexMaintenance(MaintainIndexType.STARTUP);
+ }
+
+ private void setLocationInternal(File indexLocation) {
+ final boolean newLocationExists = indexLocation.exists();
+ if (!newLocationExists) {
+ if (!indexLocation.mkdirs()) {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN,
+ "Cannot create task list index folder: " + indexLocation)); //$NON-NLS-1$
+ }
+ }
+
+ Lock writeLock = indexReaderLock.writeLock();
+ writeLock.lock();
+ try {
+ synchronized (this) {
+ if (indexReader != null) {
+ try {
+ indexReader.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ indexReader = null;
+ }
+
+ if (indexLocation.exists() && indexLocation.isDirectory()) {
+ if (directory != null) {
+ try {
+ directory.close();
+ } catch (IOException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN,
+ "Cannot close index: " + e.getMessage(), e)); //$NON-NLS-1$
+ }
+ }
+ try {
+ directory = new NIOFSDirectory(indexLocation);
+ } catch (IOException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN,
+ "Cannot create task list index", e)); //$NON-NLS-1$
+ }
+ }
+
+ }
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
/**
* the default field used to match tasks when unspecified in the query
*/

Back to the top