-
Notifications
You must be signed in to change notification settings - Fork 132
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
Keep permisions of additionalResources on packaging [Linux] #155
Comments
Hi @Ali-RS! JavaPackager is using Apache Commons FileUtils to copy additional files/folders, which doesn't copy permissions, only content: JavaPackager/src/main/java/io/github/fvarrui/javapackager/packagers/Packager.java Lines 191 to 233 in 1420f52
Then, when creating the tarball, permissions are set only for those files that JavaPackager considers executable: like the app binary, JavaPackager/src/main/java/io/github/fvarrui/javapackager/gradle/CreateTarball.java Lines 56 to 72 in 1420f52
In the case of Gradle, this behaviour is hardcoded ... in Maven, you could make your own VTL template to create a customized tarball. JavaPackager/src/main/resources/linux/assembly.xml.vtl Lines 8 to 34 in 1420f52
Options:
|
I see, thanks for explaining. Because in my case it is a single file it is easy to manually change permissions after packaging.
Maybe you can use
@fvarrui should I keep this issue open? |
I've not tested yet, but I read about this method, and it seems not to be working on MacOS. But could be a first and easy approach.
Yes, please! I think it's an interesting question. |
Option 2 released to issue-155 branch as JavaPackager 1.6.4-SNAPSHOT (you have to install it manually to your local repo). Now it's using JavaPackager/src/main/java/io/github/fvarrui/javapackager/utils/FileUtils.java Lines 85 to 94 in 222549f
I've tested on Linux and Windows, and it seems to be working fine (remember that when packaging from Windows to Linux/MacOS, additional resources will not have the expected permissions). Try it and give me some feedback, please! |
Cool, will try it soon. Thank you so much! |
Tested it on Linux and it works like charm! Thanks @fvarrui |
Branch issue-155 merged into devel. |
JavaPackager 1.6.4 released to Maven Central. |
Thanks! |
Sadly |
😞 |
@maths22 what java version are you using? l found a similar bug report at https://bugs.openjdk.java.net/browse/JDK-8204848 but seems it is already resolved. |
I'm on java 17. It doesn't throw an error; it just also doesn't preserve permissions. |
A quick fix would be to check if the original file has execute permissions, set them to the copied file: public static void copyFileToFolder(File source, File destFolder, boolean overwrite) throws Exception {
Logger.info("Copying file [" + source + "] to folder [" + destFolder + "]");
if (new File(destFolder, source.getName()).exists() && !overwrite) return;
try {
//copyFileToDirectory(source, destFolder);
File destFile = new File(destFolder, source.getName());
Files.copy(source.toPath(), destFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES);
if (source.canExecute()) {
destFile.setExecutable(true, false); // set execution permissions for all (ugo+x)
}
} catch (IOException e) {
throw new Exception(e.getMessage(), e);
}
} I've applied this change for JavaPackager 1.6.6.-SNAPSHOT and published in issue-155 branch. Please, could you test it and give some feedback? Thanks! |
That didn't work for me, probably because that only checks the permissions of the parent file, and if the parent file is a directory it's not going to check and set permissions on the child files |
Mmmmh ... yeah! you are right ... this change only works when an |
This is what JavaPackager does when copying additional resources: protected void copyAdditionalResources(List<File> resources, File destination) {
[...]
resources.stream().forEach(r -> {
if (!r.exists()) {
Logger.warn("Additional resource " + r + " doesn't exist");
return;
}
try {
if (r.isDirectory()) {
FileUtils.copyFolderToFolder(r, destination);
} else if (r.isFile()) {
FileUtils.copyFileToFolder(r, destination);
}
} catch (Exception e) {
Logger.error(e.getMessage(), e);
}
});
[...]
} Whay if we use the copy native command on MacOS and Linux? public static void copyFileToFolder(File source, File destFolder, boolean overwrite) throws Exception {
Logger.info("Copying file [" + source + "] to folder [" + destFolder + "]");
if (new File(destFolder, source.getName()).exists() && !overwrite) return;
try {
File destFile = new File(destFolder, source.getName());
if (Platform.windows.isCurrentPlatform())
Files.copy(source.toPath(), destFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES);
else {
CommandUtils.execute("cp", source, destFile);
}
} catch (IOException e) {
throw new Exception(e.getMessage(), e);
}
}
public static void copyFolderToFolder(File from, File to) throws Exception {
Logger.info("Copying folder [" + from + "] to folder [" + to + "]");
if (!from.isDirectory()) throw new Exception("Source folder " + from + " is not a directory");
try {
if (Platform.windows.isCurrentPlatform())
copyDirectoryToDirectory(from, to);
else {
CommandUtils.execute("cp", "-R", from, to);
}
} catch (IOException e) {
throw new Exception(e.getMessage(), e);
}
} so, it would keep the permissions of the original files |
Yes, sounds good to me. |
Changes published in issue-155 branch. |
JavaPackager v1.6.6 released to Maven Central |
Hello!
I'm submitting a…
Short description of the issue/suggestion:
In the
packageMyAppForLinux
task I have added a file intoadditionalResources
to be included in the package. The original file is marked as executable (chmod +x
) but when packaged into the tarball it does not keep that permission.Can you please help me to solve this issue?
What is the expected behavior?
I am expecting the packaged file to keep the permissions of its original file. (In my case the executable permission)
What is the current behavior?
It does not keep the original file permissions. (In my case the executable permission)
Do you have outputs, screenshots, demos or samples which demonstrate the problem or enhancement?
Here is my packageMyAppForLinux task:
The file
blue-cube.desktop
is the one I want to preserve its permission when packaging.Please tell us about your environment:
Regards
The text was updated successfully, but these errors were encountered: