Adapt to MS Windows
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / runtime / CmsStateImpl.java
index b76ca5792deeb20ade7a6f4167b7909de2ee3590..c1f92deb40b3ea7743098bcb0c8e4bbdacc028af 100644 (file)
@@ -38,7 +38,8 @@ import org.argeo.api.cms.CmsState;
 import org.argeo.api.uuid.UuidFactory;
 import org.argeo.cms.CmsDeployProperty;
 import org.argeo.cms.auth.ident.IdentClient;
-import org.argeo.util.FsUtils;
+import org.argeo.cms.util.FsUtils;
+import org.argeo.cms.util.OS;
 
 /**
  * Implementation of a {@link CmsState}, initialising the required services.
@@ -91,19 +92,21 @@ public class CmsStateImpl implements CmsState {
        }
 
        public void start() {
-//             Runtime.getRuntime().addShutdownHook(new CmsShutdown());
-
                try {
+                       // First init check
+                       Path privateBase = getDataPath(KernelConstants.DIR_PRIVATE);
+                       if (privateBase != null && !Files.exists(privateBase)) {// first init
+                               firstInit();
+                               Files.createDirectories(privateBase);
+                       }
+
                        initSecurity();
 //                     initArgeoLogger();
 
                        if (log.isTraceEnabled())
                                log.trace("CMS State started");
 
-//                     String stateUuidStr = KernelUtils.getFrameworkProp(Constants.FRAMEWORK_UUID);
-//                     this.uuid = UUID.fromString(stateUuidStr);
                        this.uuid = uuidFactory.timeUUID();
-//             this.cleanState = stateUuid.equals(frameworkUuid);
 
                        // hostname
                        this.hostname = getDeployProperty(CmsDeployProperty.HOST);
@@ -149,11 +152,6 @@ public class CmsStateImpl implements CmsState {
                                log.debug("## CMS starting... (" + uuid + ")\n" + sb + "\n");
                        }
 
-                       Path nodeBase = getDataPath(KernelConstants.DIR_PRIVATE);
-                       if (nodeBase != null && !Files.exists(nodeBase)) {// first init
-                               firstInit();
-                       }
-
                } catch (RuntimeException | IOException e) {
                        log.error("## FATAL: CMS state failed", e);
                }
@@ -161,7 +159,7 @@ public class CmsStateImpl implements CmsState {
 
        private void initSecurity() {
                // private directory permissions
-               Path privateDir = KernelUtils.getOsgiInstancePath(KernelConstants.DIR_PRIVATE);
+               Path privateDir = getDataPath(KernelConstants.DIR_PRIVATE);
                if (privateDir != null) {
                        // TODO rather check whether we can read and write
                        Set<PosixFilePermission> posixPermissions = new HashSet<>();
@@ -169,9 +167,12 @@ public class CmsStateImpl implements CmsState {
                        posixPermissions.add(PosixFilePermission.OWNER_WRITE);
                        posixPermissions.add(PosixFilePermission.OWNER_EXECUTE);
                        try {
-                               Files.setPosixFilePermissions(privateDir, posixPermissions);
+                               if (!Files.exists(privateDir))
+                                       Files.createDirectories(privateDir);
+                               if (!OS.LOCAL.isMSWindows())
+                                       Files.setPosixFilePermissions(privateDir, posixPermissions);
                        } catch (IOException e) {
-                               log.error("Cannot set permissions on " + privateDir);
+                               log.error("Cannot set permissions on " + privateDir, e);
                        }
                }