-
Notifications
You must be signed in to change notification settings - Fork 165
[RORDEV-1502] Fixed ror-tools file permissions #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import tech.beshu.ror.tools.core.patches.internal.FilePatch.FilePatchMetadata | |
import tech.beshu.ror.tools.core.patches.internal.RorPluginDirectory.EsPatchMetadata | ||
import tech.beshu.ror.tools.core.utils.EsDirectory | ||
import tech.beshu.ror.tools.core.utils.EsUtil.{findTransportNetty4JarIn, readonlyrestPluginPath} | ||
import tech.beshu.ror.tools.core.utils.FileUtils.modifyFileWithMaintainingOriginalPermissionsAndOwner | ||
|
||
private[patches] class RorPluginDirectory(val esDirectory: EsDirectory) { | ||
|
||
|
@@ -46,11 +47,19 @@ private[patches] class RorPluginDirectory(val esDirectory: EsDirectory) { | |
} | ||
|
||
def backup(file: Path): Unit = { | ||
os.copy(from = file, to = backupFolderPath / file.last, replaceExisting = true) | ||
modifyFileWithMaintainingOriginalPermissionsAndOwner[Path](file, _.toIO) { originalFile => | ||
val backedUpFile = backupFolderPath / originalFile.last | ||
os.copy(from = originalFile, to = backedUpFile, replaceExisting = true, copyAttributes = true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have os.copy in copyToPluginPath too. But it's not used. Maybe we should remove it? |
||
backedUpFile | ||
} | ||
} | ||
|
||
def restore(file: Path): Unit = { | ||
os.copy(from = backupFolderPath / file.last, to = file, replaceExisting = true) | ||
val backedUpFile = backupFolderPath / file.last | ||
modifyFileWithMaintainingOriginalPermissionsAndOwner[Path](backedUpFile, _.toIO) { backedUpFile => | ||
os.copy(from = backedUpFile, to = file, replaceExisting = true, copyAttributes = true) | ||
file | ||
} | ||
} | ||
|
||
def copyToPluginPath(file: Path): Unit = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ package tech.beshu.ror.tools.core.patches.internal.filePatchers | |
|
||
import better.files.* | ||
import tech.beshu.ror.tools.core.utils.EsDirectory | ||
import tech.beshu.ror.tools.core.utils.FileUtils.modifyFileWithMaintainingOriginalPermissionsAndOwner | ||
|
||
import java.util.UUID | ||
import java.util.jar.{JarFile, JarOutputStream} | ||
|
@@ -28,7 +29,8 @@ object JarManifestModifier { | |
|
||
private val patchedByRorVersionPropertyName = "Patched-By-Ror-Version" | ||
|
||
def addPatchedByRorVersionProperty(file: File, rorVersion: String): Unit = { | ||
def addPatchedByRorVersionProperty(file: File, | ||
rorVersion: String): Unit = modifyFileWithMaintainingOriginalPermissionsAndOwner[File](file, _.toJava) { file => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, it works here, but don't you think it's hard to reason about? Maybe the I mean, the method suggests we modify the jar file, but TBH, we don't have to modify it. |
||
val tempJarFile = File(s"temp-${UUID.randomUUID()}.jar") | ||
Using(new JarFile(file.toJava)) { jarFile => | ||
// Using the better-files temporary files causes problems, probably because of permission issues when copying the file at the end of this method. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,12 +31,16 @@ object FileUtils { | |
digest.digest.map("%02x".format(_)).mkString | ||
} | ||
|
||
def modifyFileWithMaintainingOriginalPermissionsAndOwner(jar: File)(modifyJar: File => Unit): Unit = { | ||
val originalFileOwner = Files.getOwner(jar.toPath) | ||
val originalFilePermissions = getOriginalPermissions(jar.toPath) | ||
modifyJar(jar) | ||
Files.setOwner(jar.toPath, originalFileOwner) | ||
setOriginalPermissions(jar.toPath, originalFilePermissions) | ||
def modifyFileWithMaintainingOriginalPermissionsAndOwner(file: File)(modifyFile: File => Unit): Unit = { | ||
modifyFileWithMaintainingOriginalPermissionsAndOwner[File](file, identity) { f => modifyFile(f); f } | ||
} | ||
|
||
def modifyFileWithMaintainingOriginalPermissionsAndOwner[FILE](file: FILE, toJavaFile: FILE => File)(modifyJar: FILE => FILE): Unit = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH, I'd be nice if we could get rid of So, let's modify the previous interface of the method and adapt other places where we are not so consistent with using better files. |
||
val originalFileOwner = Files.getOwner(toJavaFile(file).toPath) | ||
val originalFilePermissions = getOriginalPermissions(toJavaFile(file).toPath) | ||
val resultFile = modifyJar(file) | ||
Files.setOwner(toJavaFile(resultFile).toPath, originalFileOwner) | ||
setOriginalPermissions(toJavaFile(resultFile).toPath, originalFilePermissions) | ||
} | ||
|
||
private def getOriginalPermissions(jarPath: Path): Any = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here the usage of
modifyFileWithMaintainingOriginalPermissionsAndOwner
looks strange too. Becase we don't modify the file