@@ -15,15 +15,15 @@ import org.snd.common.exceptions.ValidationException
1515import org.snd.metadata.comicinfo.model.ComicInfo
1616import java.nio.charset.StandardCharsets.UTF_8
1717import java.nio.file.Path
18- import java.nio.file.StandardCopyOption.COPY_ATTRIBUTES
19- import java.nio.file.StandardCopyOption.REPLACE_EXISTING
2018import java.util.zip.Deflater.NO_COMPRESSION
2119import java.util.zip.ZipEntry
2220import kotlin.io.path.createTempFile
2321import kotlin.io.path.deleteIfExists
2422import kotlin.io.path.extension
23+ import kotlin.io.path.getPosixFilePermissions
2524import kotlin.io.path.isWritable
2625import kotlin.io.path.moveTo
26+ import kotlin.io.path.setPosixFilePermissions
2727
2828
2929private const val COMIC_INFO = " ComicInfo.xml"
@@ -67,7 +67,9 @@ class ComicInfoWriter private constructor(
6767 copyEntries(zip, output)
6868 }
6969 }
70- tempFile.moveTo(archivePath, REPLACE_EXISTING , COPY_ATTRIBUTES )
70+
71+ copyPermissions(from = archivePath, to = tempFile)
72+ tempFile.moveTo(archivePath, overwrite = true )
7173 }.onFailure {
7274 tempFile.deleteIfExists()
7375 throw it
@@ -97,7 +99,9 @@ class ComicInfoWriter private constructor(
9799 putComicInfoEntry(comicInfoToWrite, output)
98100 }
99101 }
100- tempFile.moveTo(archivePath, REPLACE_EXISTING , COPY_ATTRIBUTES )
102+
103+ copyPermissions(from = archivePath, to = tempFile)
104+ tempFile.moveTo(archivePath, overwrite = true )
101105 }.onFailure {
102106 tempFile.deleteIfExists()
103107 throw it
@@ -142,6 +146,11 @@ class ComicInfoWriter private constructor(
142146 }
143147 }
144148
149+ private fun copyPermissions (from : Path , to : Path ) {
150+ runCatching { from.getPosixFilePermissions() }.getOrNull()
151+ ?.let { to.setPosixFilePermissions(it) }
152+ }
153+
145154 private fun mergeComicInfoMetadata (old : ComicInfo , new : ComicInfo ): ComicInfo {
146155 return ComicInfo (
147156 title = new.title ? : old.title,
0 commit comments