Avoid overwriting counters file of Lookups storage if it hasn't changed
This commit is contained in:
committed by
TeamCityServer
parent
cb92413cd8
commit
c3344549a8
@@ -48,12 +48,14 @@ open class LookupStorage(
|
|||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var size: Int = 0
|
private var size: Int = 0
|
||||||
|
private var oldSize: Int = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
try {
|
try {
|
||||||
if (countersFile.exists()) {
|
if (countersFile.exists()) {
|
||||||
val lines = countersFile.readLines()
|
val lines = countersFile.readLines()
|
||||||
size = lines[0].toInt()
|
size = lines[0].toInt()
|
||||||
|
oldSize = size
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw IOException("Could not read $countersFile", e)
|
throw IOException("Could not read $countersFile", e)
|
||||||
@@ -120,13 +122,15 @@ open class LookupStorage(
|
|||||||
@Synchronized
|
@Synchronized
|
||||||
override fun flush(memoryCachesOnly: Boolean) {
|
override fun flush(memoryCachesOnly: Boolean) {
|
||||||
try {
|
try {
|
||||||
if (size > 0) {
|
if (size != oldSize) {
|
||||||
if (!countersFile.exists()) {
|
if (size > 0) {
|
||||||
countersFile.parentFile.mkdirs()
|
if (!countersFile.exists()) {
|
||||||
countersFile.createNewFile()
|
countersFile.parentFile.mkdirs()
|
||||||
}
|
countersFile.createNewFile()
|
||||||
|
}
|
||||||
|
|
||||||
countersFile.writeText("$size\n0")
|
countersFile.writeText("$size\n0")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
super.flush(memoryCachesOnly)
|
super.flush(memoryCachesOnly)
|
||||||
|
|||||||
Reference in New Issue
Block a user