Skip to content

Commit 66095ed

Browse files
committed
explict permission copy
1 parent 8799843 commit 66095ed

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/main/kotlin/org/snd/metadata/comicinfo/ComicInfoWriter.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import org.snd.common.exceptions.ValidationException
1515
import org.snd.metadata.comicinfo.model.ComicInfo
1616
import java.nio.charset.StandardCharsets.UTF_8
1717
import java.nio.file.Path
18-
import java.nio.file.StandardCopyOption.COPY_ATTRIBUTES
19-
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
2018
import java.util.zip.Deflater.NO_COMPRESSION
2119
import java.util.zip.ZipEntry
2220
import kotlin.io.path.createTempFile
2321
import kotlin.io.path.deleteIfExists
2422
import kotlin.io.path.extension
23+
import kotlin.io.path.getPosixFilePermissions
2524
import kotlin.io.path.isWritable
2625
import kotlin.io.path.moveTo
26+
import kotlin.io.path.setPosixFilePermissions
2727

2828

2929
private 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

Comments
 (0)