Skip to content

Commit 1b95044

Browse files
Fix race condition on Windows by consolidating two file writes
1 parent 256d910 commit 1b95044

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/scala/scoverage/Invoker.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ import java.io.FileWriter
55
/** @author Stephen Samuel */
66
object Invoker {
77

8+
/**
9+
* We record that the given id has been invoked by appending its id to the coverage
10+
* data file.
11+
* This will happen concurrently on as many threads as the application is using,
12+
* but appending small amounts of data to a file is atomic on both POSIX and Windows
13+
* if it is a single write of a small enough string.
14+
*
15+
* @see http://stackoverflow.com/questions/1154446/is-file-append-atomic-in-unix
16+
* @see http://stackoverflow.com/questions/3032482/is-appending-to-a-file-atomic-with-windows-ntfs
17+
*/
818
def invoked(id: Int, path: String) = {
919
val writer = new FileWriter(path, true)
10-
writer.append(id.toString)
11-
writer.append(';')
20+
writer.append(id.toString + ';')
1221
writer.close()
1322
}
1423
}

0 commit comments

Comments
 (0)