Skip to content

Commit

Permalink
explict permission copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Snd-R committed Sep 21, 2023
1 parent 8799843 commit 66095ed
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/kotlin/org/snd/metadata/comicinfo/ComicInfoWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 66095ed

Please sign in to comment.