mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-09 08:04:45 +00:00
minor sonar fixes
This commit is contained in:
@@ -30,8 +30,11 @@ import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
import com.vitorpamplona.quartz.nip19Bech32.bech32.bechToBytes
|
||||
import com.vitorpamplona.quartz.nip19Bech32.toNpub
|
||||
import com.vitorpamplona.quartz.nip19Bech32.toNsec
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
import java.io.File
|
||||
|
||||
private const val TAG = "Config"
|
||||
|
||||
/**
|
||||
* Persisted identity.
|
||||
*
|
||||
@@ -184,7 +187,9 @@ class DataDir(
|
||||
val file = Json.mapper.readValue<IdentityFile>(identityFile.readText())
|
||||
file.secret?.let { secrets.delete(it) }
|
||||
}
|
||||
identityFile.delete()
|
||||
if (!identityFile.delete() && identityFile.exists()) {
|
||||
Log.w(TAG) { "Failed to delete identity file ${identityFile.absolutePath}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.cli
|
||||
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
import java.io.File
|
||||
import java.io.OutputStream
|
||||
import java.nio.file.AtomicMoveNotSupportedException
|
||||
@@ -153,11 +154,23 @@ object SecureFileIO {
|
||||
return
|
||||
}
|
||||
val f = path.toFile()
|
||||
f.setReadable(false, false)
|
||||
f.setWritable(false, false)
|
||||
f.setExecutable(false, false)
|
||||
f.setReadable(true, true)
|
||||
f.setWritable(true, true)
|
||||
if (isDir) f.setExecutable(true, true)
|
||||
warnIfFailed(f, "setReadable(false)") { f.setReadable(false, false) }
|
||||
warnIfFailed(f, "setWritable(false)") { f.setWritable(false, false) }
|
||||
warnIfFailed(f, "setExecutable(false)") { f.setExecutable(false, false) }
|
||||
warnIfFailed(f, "setReadable(true, owner)") { f.setReadable(true, true) }
|
||||
warnIfFailed(f, "setWritable(true, owner)") { f.setWritable(true, true) }
|
||||
if (isDir) warnIfFailed(f, "setExecutable(true, owner)") { f.setExecutable(true, true) }
|
||||
}
|
||||
|
||||
private inline fun warnIfFailed(
|
||||
file: File,
|
||||
op: String,
|
||||
action: () -> Boolean,
|
||||
) {
|
||||
if (!action()) {
|
||||
Log.w(TAG) { "$op failed on ${file.absolutePath}" }
|
||||
}
|
||||
}
|
||||
|
||||
private const val TAG = "SecureFileIO"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user