You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2019/01/30 05:14:59 UTC

[karaf] branch master updated: [KARAF-6124] Handle Windows permissions when POSIX not supported

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f762f2  [KARAF-6124] Handle Windows permissions when POSIX not supported
     new 4dd5610  Merge pull request #744 from diamondq/KARAF-6124
7f762f2 is described below

commit 7f762f27480450ba0e1e2da1abe74ba0117bf6f1
Author: Mike Mansell <me...@michaelmansell.com>
AuthorDate: Tue Jan 29 18:53:25 2019 -0800

    [KARAF-6124] Handle Windows permissions when POSIX not supported
    
    Handle the UnsupportedOperationException that is thrown when attempting to use the Files.getPosixFilePermissions() under Windows (as POSIX is not supported) by using the File.setExecutable() instead in that scenario.
---
 .../core/internal/InstanceServiceImpl.java         | 24 ++++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java b/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
index 0a15e73..3ac2df3 100644
--- a/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
+++ b/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
@@ -1206,15 +1206,21 @@ public class InstanceServiceImpl implements InstanceService {
     }
 
     private void makeFileExecutable(File serviceFile) throws IOException {
-        Set<PosixFilePermission> permissions = new HashSet<>();
-        permissions.add(PosixFilePermission.OWNER_EXECUTE);
-        permissions.add(PosixFilePermission.GROUP_EXECUTE);
-        permissions.add(PosixFilePermission.OTHERS_EXECUTE);
-
-        // Get the existing permissions and add the executable permissions to them
-        Set<PosixFilePermission> filePermissions = Files.getPosixFilePermissions(serviceFile.toPath());
-        filePermissions.addAll(permissions);
-        Files.setPosixFilePermissions(serviceFile.toPath(), filePermissions);
+        try {
+            Set<PosixFilePermission> permissions = new HashSet<>();
+            permissions.add(PosixFilePermission.OWNER_EXECUTE);
+            permissions.add(PosixFilePermission.GROUP_EXECUTE);
+            permissions.add(PosixFilePermission.OTHERS_EXECUTE);
+
+            // Get the existing permissions and add the executable permissions to them
+            Set<PosixFilePermission> filePermissions = Files.getPosixFilePermissions(serviceFile.toPath());
+            filePermissions.addAll(permissions);
+            Files.setPosixFilePermissions(serviceFile.toPath(), filePermissions);
+        }
+        catch (UnsupportedOperationException ex)
+        {
+            serviceFile.setExecutable(true, false);
+        }
     }
 
     private void copy(File source, File destination) throws IOException {