aboutsummaryrefslogtreecommitdiffstats
path: root/packages/midpath/files/fix-openfile.patch
blob: df677e10118718a30ad1d9946382caa97fd09f92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Index: midpath-0.3rc2/components/core/src/org/thenesis/midpath/io/backend/j2se/FileHandlerImpl.java
===================================================================
--- midpath-0.3rc2.orig/components/core/src/org/thenesis/midpath/io/backend/j2se/FileHandlerImpl.java	2008-05-19 13:56:18.000000000 +0200
+++ midpath-0.3rc2/components/core/src/org/thenesis/midpath/io/backend/j2se/FileHandlerImpl.java	2008-12-17 07:08:54.000000000 +0100
@@ -181,10 +181,14 @@
 
 	public void openForRead() throws IOException {
 		if (randomAccessFile == null) {
-			//stream = new FileRandomAccessStream(file);
-			randomAccessFile = new RandomAccessFile(file, "rws");
+			// Try to get maximum rights to avoid closing the stream if openForWrite is called next
+			if (file.canWrite()) {
+				randomAccessFile = new RandomAccessFile(file, "rws");
+			} else {
+				randomAccessFile = new RandomAccessFile(file, "r");
+			}
 		}
-	}
+  }
 
 	public void openForWrite() throws IOException {
 		if (randomAccessFile == null) {