diff --git a/src/main/kotlin/org/snd/metadata/comicinfo/ComicInfoWriter.kt b/src/main/kotlin/org/snd/metadata/comicinfo/ComicInfoWriter.kt index 640872a2..99942400 100644 --- a/src/main/kotlin/org/snd/metadata/comicinfo/ComicInfoWriter.kt +++ b/src/main/kotlin/org/snd/metadata/comicinfo/ComicInfoWriter.kt @@ -15,15 +15,15 @@ import org.snd.common.exceptions.ValidationException import org.snd.metadata.comicinfo.model.ComicInfo import java.nio.charset.StandardCharsets.UTF_8 import java.nio.file.Path -import java.nio.file.StandardCopyOption.COPY_ATTRIBUTES -import java.nio.file.StandardCopyOption.REPLACE_EXISTING import java.util.zip.Deflater.NO_COMPRESSION import java.util.zip.ZipEntry import kotlin.io.path.createTempFile import kotlin.io.path.deleteIfExists import kotlin.io.path.extension +import kotlin.io.path.getPosixFilePermissions import kotlin.io.path.isWritable import kotlin.io.path.moveTo +import kotlin.io.path.setPosixFilePermissions private const val COMIC_INFO = "ComicInfo.xml" @@ -67,7 +67,9 @@ class ComicInfoWriter private constructor( copyEntries(zip, output) } } - tempFile.moveTo(archivePath, REPLACE_EXISTING, COPY_ATTRIBUTES) + + copyPermissions(from = archivePath, to = tempFile) + tempFile.moveTo(archivePath, overwrite = true) }.onFailure { tempFile.deleteIfExists() throw it @@ -97,7 +99,9 @@ class ComicInfoWriter private constructor( putComicInfoEntry(comicInfoToWrite, output) } } - tempFile.moveTo(archivePath, REPLACE_EXISTING, COPY_ATTRIBUTES) + + copyPermissions(from = archivePath, to = tempFile) + tempFile.moveTo(archivePath, overwrite = true) }.onFailure { tempFile.deleteIfExists() throw it @@ -142,6 +146,11 @@ class ComicInfoWriter private constructor( } } + private fun copyPermissions(from: Path, to: Path) { + runCatching { from.getPosixFilePermissions() }.getOrNull() + ?.let { to.setPosixFilePermissions(it) } + } + private fun mergeComicInfoMetadata(old: ComicInfo, new: ComicInfo): ComicInfo { return ComicInfo( title = new.title ?: old.title,