On 15/01/2013 13:02, Gerd Petermann wrote:
Hi Steve,
>
> Its difficult to delete files on Windows compared to Unix.
> I'm part way through fixing it now.
>
Thanks. I think on windows a file must not be open, so
we probably have to code some close() calls.
Eclipse has a function to show warnings for potentially missing
close() calls.
Almost all the real ones were in the test code, since I didn't want any
try/finally clutter in there.
The attached patch fixes. There is one test failure which I believe is a
genuine bug on windows, which I'll look into some time later.
I'll check this in when I've tried it out on unix again.
..Steve
Index: test/func/files/GmapsuppTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- test/func/files/GmapsuppTest.java (revision 2330)
+++ test/func/files/GmapsuppTest.java (revision )
@@ -14,6 +14,7 @@
package func.files;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -21,6 +22,7 @@
import java.util.Comparator;
import java.util.List;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.imgfmt.fs.DirectoryEntry;
import uk.me.parabola.imgfmt.fs.FileSystem;
import uk.me.parabola.imgfmt.fs.ImgChannel;
@@ -55,7 +57,7 @@
assertTrue("gmapsupp.img is created", f.exists());
- FileSystem fs = ImgFS.openFs(GMAPSUPP_IMG);
+ FileSystem fs = openFs(GMAPSUPP_IMG);
DirectoryEntry entry = fs.lookup("63240001.TRE");
assertNotNull("first file TRE", entry);
assertEquals("first file TRE size", getFileSize(Args.TEST_RESOURCE_IMG + "63240001.img", "63240001.TRE"), entry.getSize());
@@ -296,7 +298,7 @@
// All we are doing here is checking that the file was created and that it is
// not completely empty.
- FileSystem fs = ImgFS.openFs(GMAPSUPP_IMG);
+ FileSystem fs = openFs(GMAPSUPP_IMG);
ImgChannel r = fs.open("00000101.MDR", "r");
r.position(2);
ByteBuffer buf = ByteBuffer.allocate(1024);
@@ -333,7 +335,7 @@
// All we are doing here is checking that the file was created and that it is
// not completely empty.
- FileSystem fs = ImgFS.openFs(GMAPSUPP_IMG);
+ FileSystem fs = openFs(GMAPSUPP_IMG);
ImgChannel r = fs.open("00000101.MDR", "r");
r.position(2);
ByteBuffer buf = ByteBuffer.allocate(1024);
@@ -375,14 +377,14 @@
// All we are doing here is checking that the file was created and that it is
// not completely empty.
- FileSystem fs = ImgFS.openFs(GMAPSUPP_IMG);
+ FileSystem fs = openFs(GMAPSUPP_IMG);
ImgChannel r = fs.open("00000101.MDR", "r");
r.position(2);
ByteBuffer buf = ByteBuffer.allocate(1024);
int read = r.read(buf);
assertEquals(1024, read);
- fs = ImgFS.openFs(GMAPSUPP_IMG);
+ fs = openFs(GMAPSUPP_IMG);
r = fs.open("00000202.MDR", "r");
r.position(2);
buf.clear();
@@ -423,7 +425,7 @@
assertFalse(new File("osmmap_mdr.img").exists());
- FileSystem fs = ImgFS.openFs(GMAPSUPP_IMG);
+ FileSystem fs = openFs(GMAPSUPP_IMG);
ImgChannel r = fs.open("00006324.MDR", "r");
ByteBuffer buf = ByteBuffer.allocate(1024);
@@ -463,12 +465,18 @@
}
private MpsFileReader getMpsFile() throws IOException {
- FileSystem fs = ImgFS.openFs(GMAPSUPP_IMG);
- return new MpsFileReader(fs.open("MAKEGMAP.MPS", "r"));
+ FileSystem fs = openFs(GMAPSUPP_IMG);
+ MpsFileReader reader = new MpsFileReader(fs.open("MAKEGMAP.MPS", "r"));
+ TestUtils.registerFile(reader);
+ return reader;
}
private int getFileSize(String imgName, String fileName) throws IOException {
FileSystem fs = ImgFS.openFs(imgName);
+ try {
- return fs.lookup(fileName).getSize();
+ return fs.lookup(fileName).getSize();
+ } finally {
+ Utils.closeFile(fs);
+ }
}
}
Index: test/func/SimpleTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- test/func/SimpleTest.java (revision 2330)
+++ test/func/SimpleTest.java (revision )
@@ -32,6 +32,7 @@
import func.lib.Args;
import func.lib.RangeMatcher;
import func.lib.TestUtils;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -42,7 +43,7 @@
*
* @author Steve Ratcliffe
*/
-public class SimpleTest {
+public class SimpleTest extends Base {
/**
* A very basic check that the size of all the sections has not changed.
@@ -62,6 +63,7 @@
});
MapReader mr = new MapReader(Args.DEF_MAP_ID + ".img");
+ TestUtils.registerFile(mr);
//FileSystem fs = ImgFS.openFs(Args.DEF_MAP_ID + ".img");
assertNotNull("file exists", mr);
@@ -91,7 +93,7 @@
Args.TEST_RESOURCE_MP + "test1.mp"
});
- FileSystem fs = ImgFS.openFs(Args.DEF_MAP_FILENAME);
+ FileSystem fs = openFs(Args.DEF_MAP_FILENAME);
assertNotNull("file exists", fs);
List<DirectoryEntry> entries = fs.list();
@@ -113,10 +115,4 @@
}
assertTrue("enough checks run", count >= 3);
}
-
- @Before
- public void setUp() {
- TestUtils.deleteOutputFiles();
- }
-
}
Index: test/func/files/IndexTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- test/func/files/IndexTest.java (revision 2330)
+++ test/func/files/IndexTest.java (revision )
@@ -17,8 +17,8 @@
import uk.me.parabola.imgfmt.fs.DirectoryEntry;
import uk.me.parabola.imgfmt.fs.FileSystem;
-import uk.me.parabola.imgfmt.sys.ImgFS;
+import func.Base;
import func.lib.Args;
import func.lib.Outputs;
import func.lib.TestUtils;
@@ -26,7 +26,7 @@
import static org.junit.Assert.*;
-public class IndexTest {
+public class IndexTest extends Base {
private static final String OVERVIEW_NAME = "testname";
private static final String MDR_IMG = OVERVIEW_NAME + "_mdr.img";
@@ -54,11 +54,12 @@
assertTrue(MDR_IMG + " is created", f.exists());
- FileSystem fs = ImgFS.openFs(MDR_IMG);
+ FileSystem fs = openFs(MDR_IMG);
DirectoryEntry entry = fs.lookup(OVERVIEW_NAME.toUpperCase() + ".MDR");
assertNotNull("Contains the MDR file", entry);
entry = fs.lookup(OVERVIEW_NAME.toUpperCase() + ".SRT");
assertNotNull("contains the SRT file", entry);
+ fs.close();
}
}
Index: test/uk/me/parabola/mkgmap/OptionsTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- test/uk/me/parabola/mkgmap/OptionsTest.java (revision 2330)
+++ test/uk/me/parabola/mkgmap/OptionsTest.java (revision )
@@ -29,6 +29,8 @@
"pool", "ocean"
};
+ String PATH_SEP = System.getProperty("file.separator");
+
private final List<Option> found = new ArrayList<Option>();
private final List<String> options = new ArrayList<String>();
private final List<String> values = new ArrayList<String>();
@@ -124,7 +126,7 @@
opts.readOptionFile(r, "/bar/string.args");
String filename = values.get(0);
File file = new File(filename);
- assertEquals("directory part", "/bar", file.getParent());
+ assertEquals("directory part", PATH_SEP + "bar", file.getParent());
assertEquals("file part", "foo", file.getName());
}
@@ -146,7 +148,7 @@
String filename = values.get(0);
File file = new File(filename);
- assertEquals("directory part", "/home", file.getParent());
+ assertEquals("directory part", PATH_SEP + "home", file.getParent());
assertEquals("file part", "foo", file.getName());
}
Index: test/func/lib/TestUtils.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- test/func/lib/TestUtils.java (revision 2330)
+++ test/func/lib/TestUtils.java (revision )
@@ -17,14 +17,18 @@
package func.lib;
import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
import java.io.File;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Deque;
import java.util.List;
+import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.mkgmap.main.Main;
import static org.junit.Assert.*;
@@ -36,6 +40,7 @@
*/
public class TestUtils {
private static final List<String> files = new ArrayList<String>();
+ private static final Deque<Closeable> open = new ArrayDeque<Closeable>();
static {
files.add(Args.DEF_MAP_FILENAME);
@@ -61,12 +66,21 @@
File f = new File(fname);
if (f.exists())
- assertTrue("delete existing file", f.delete());
+ assertTrue("delete existing file: " + f.getName(), f.delete());
}
}
+ public static void closeFiles() {
+ while (!open.isEmpty())
+ Utils.closeFile(open.remove());
+ }
+
public static void registerFile(String ... names) {
Collections.addAll(files, names);
+ }
+
+ public static void registerFile(Closeable... files) {
+ Collections.addAll(open, files);
}
/**
Index: test/func/Base.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- test/func/Base.java (revision 2330)
+++ test/func/Base.java (revision )
@@ -17,10 +17,16 @@
package func;
import java.io.File;
+import java.io.FileNotFoundException;
+import uk.me.parabola.imgfmt.fs.FileSystem;
+import uk.me.parabola.imgfmt.sys.ImgFS;
+
import func.lib.Args;
import func.lib.TestUtils;
import static org.junit.Assert.*;
+
+import org.junit.After;
import org.junit.Before;
/**
@@ -35,6 +41,10 @@
TestUtils.deleteOutputFiles();
}
+ @After
+ public void baseTeardown() {
+ TestUtils.closeFiles();
+ }
protected void checkStdFile() {
assertTrue("std output file exists", new File(Args.DEF_MAP_FILENAME).exists());
@@ -42,5 +52,11 @@
protected void checkNoStdFile() {
assertFalse("std output file exists", new File(Args.DEF_MAP_FILENAME).exists());
+ }
+
+ protected FileSystem openFs(String filename) throws FileNotFoundException {
+ FileSystem fs = ImgFS.openFs(filename);
+ TestUtils.registerFile(fs);
+ return fs;
}
}
Index: test/func/route/SimpleRouteTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- test/func/route/SimpleRouteTest.java (revision 2330)
+++ test/func/route/SimpleRouteTest.java (revision )
@@ -21,13 +21,15 @@
import uk.me.parabola.imgfmt.sys.ImgFS;
import uk.me.parabola.mkgmap.main.Main;
+import func.Base;
import func.lib.Args;
import func.lib.RangeMatcher;
+import func.lib.TestUtils;
import org.junit.Test;
import static org.junit.Assert.*;
-public class SimpleRouteTest {
+public class SimpleRouteTest extends Base {
/**
* Simple test to ensure that nothing has changed. Of course
@@ -43,7 +45,7 @@
Args.TEST_RESOURCE_MP + "test1.mp"
});
- FileSystem fs = ImgFS.openFs(Args.DEF_MAP_ID + ".img");
+ FileSystem fs = openFs(Args.DEF_MAP_ID + ".img");
assertNotNull("file exists", fs);
List<DirectoryEntry> entries = fs.list();
@@ -71,7 +73,7 @@
}
assertTrue("enough checks run", count == 5);
- fs = ImgFS.openFs(Args.DEF_MAP_FILENAME2);
+ fs = openFs(Args.DEF_MAP_FILENAME2);
assertNotNull("file exists", fs);
entries = fs.list();
Index: src/uk/me/parabola/mkgmap/combiners/GmapsuppBuilder.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- src/uk/me/parabola/mkgmap/combiners/GmapsuppBuilder.java (revision 2330)
+++ src/uk/me/parabola/mkgmap/combiners/GmapsuppBuilder.java (revision )
@@ -271,8 +271,9 @@
*/
private void addMpsFile(FileInfo info) {
String name = info.getFilename();
+ FileSystem fs = null;
try {
- FileSystem fs = ImgFS.openFs(name);
+ fs = ImgFS.openFs(name);
MpsFileReader mr = new MpsFileReader(fs.open(info.getMpsName(), "r"));
for (MapBlock block : mr.getMaps())
mpsFile.addMap(block);
@@ -282,6 +283,8 @@
mr.close();
} catch (IOException e) {
log.error("Could not read MPS file from gmapsupp", e);
+ } finally {
+ Utils.closeFile(fs);
}
}
Index: src/uk/me/parabola/imgfmt/mps/MpsFileReader.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- src/uk/me/parabola/imgfmt/mps/MpsFileReader.java (revision 2330)
+++ src/uk/me/parabola/imgfmt/mps/MpsFileReader.java (revision )
@@ -16,6 +16,7 @@
*/
package uk.me.parabola.imgfmt.mps;
+import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +34,7 @@
*
* @author Steve Ratcliffe
*/
-public class MpsFileReader {
+public class MpsFileReader implements Closeable {
private final List<MapBlock> maps = new ArrayList<MapBlock>();
private final List<ProductBlock> products = new ArrayList<ProductBlock>();
Index: test/func/ArgsTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- test/func/ArgsTest.java (revision 2330)
+++ test/func/ArgsTest.java (revision )
@@ -85,7 +85,7 @@
Args.TEST_RESOURCE_OSM + "uk-test-1.osm.gz");
op.checkNoError();
- FileSystem fs = ImgFS.openFs(Args.DEF_MAP_FILENAME);
+ FileSystem fs = openFs(Args.DEF_MAP_FILENAME);
ImgChannel chan = fs.open(Args.DEF_MAP_ID + ".TRE", "r");
TREFileReader treFile = new TREFileReader(chan);
Index: test/func/StructureTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- test/func/StructureTest.java (revision 2330)
+++ test/func/StructureTest.java (revision )
@@ -92,12 +92,12 @@
*/
@AfterClass
public static void cleanup() {
- TestUtils.deleteOutputFiles();
if (fs != null) {
fs.close();
treFile.close();
lblFile.close();
rgnFile.close();
}
+ TestUtils.deleteOutputFiles();
}
}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://lists.mkgmap.org.uk/mailman/listinfo/mkgmap-dev