Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Montplaisir2012-07-12 13:29:11 +0000
committerPatrick Tasse2012-07-13 18:57:25 +0000
commit8f175a3fc089926a2e3ae2955ae44b63a11a8525 (patch)
tree575f720a12dac789feba4e2bd8b2ca9202705a2c
parent24b554bc1fc2ad4aa75d420676d802b10d96632c (diff)
downloadorg.eclipse.linuxtools-8f175a3fc089926a2e3ae2955ae44b63a11a8525.tar.gz
org.eclipse.linuxtools-8f175a3fc089926a2e3ae2955ae44b63a11a8525.tar.xz
org.eclipse.linuxtools-8f175a3fc089926a2e3ae2955ae44b63a11a8525.zip
tmf: Close the state history files before deleting them
When a state history construction gets cancelled, we delete the partial files, so we are not stuck with an incomplete file that looks exactly like a complete and valid one. However, we should close the file descriptors before attempting the deletion. On Linux, lsof would still report the descriptors to the deleted files after we stopped using them. On Windows it was even worse, the deletion would fail because the file lock was still taken. Change-Id: I29d0bf39621bdf6713bb2c3fe908e16f8d4f2bcc Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HT_IO.java29
1 files changed, 18 insertions, 11 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HT_IO.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HT_IO.java
index f004b29638..b3aaa7129e 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HT_IO.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HT_IO.java
@@ -2,12 +2,12 @@
* Copyright (c) 2012 Ericsson
* Copyright (c) 2010, 2011 École Polytechnique de Montréal
* Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
- *
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
*******************************************************************************/
package org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree;
@@ -23,9 +23,9 @@ import java.nio.channels.FileChannel;
* contains all the methods and descriptors to handle reading/writing to the
* tree-file on disk and all the caching mechanisms. Every HistoryTree should
* contain 1 and only 1 HT_IO element.
- *
+ *
* @author alexmont
- *
+ *
*/
class HT_IO {
@@ -34,14 +34,14 @@ class HT_IO {
/* Fields related to the file I/O */
private final File historyTreeFile;
- private FileInputStream fis;
- private FileOutputStream fos;
- private FileChannel fcIn;
- private FileChannel fcOut;
+ private final FileInputStream fis;
+ private final FileOutputStream fos;
+ private final FileChannel fcIn;
+ private final FileChannel fcOut;
/**
* Standard constructor
- *
+ *
* @param tree
* @param newFile
* Are we creating a new file from scratch?
@@ -80,7 +80,7 @@ class HT_IO {
/**
* Generic "read node" method, which checks if the node is in memory first,
* and if it's not it goes to disk to retrieve it.
- *
+ *
* @param seqNumber
* Sequence number of the node we want
* @return The wanted node in object form
@@ -157,6 +157,13 @@ class HT_IO {
}
synchronized void deleteFile() {
+ try {
+ fis.close();
+ fos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
if(!historyTreeFile.delete()) {
/* We didn't succeed in deleting the file */
//TODO log it?
@@ -166,7 +173,7 @@ class HT_IO {
/**
* Seek the given FileChannel to the position corresponding to the node that
* has seqNumber
- *
+ *
* @param seqNumber
* @throws IOException
*/

Back to the top