Prefs: create XConfiguration.xml file only when SCIHOME exists and is writable (https... 01/14201/2
Calixte DENIZET [Fri, 28 Mar 2014 10:23:35 +0000 (11:23 +0100)]
Change-Id: If295af948d3c98f7f897977ad26c9542cda10272

scilab/modules/preferences/macros/createXConfiguration.sci
scilab/modules/preferences/macros/getPreferencesValue.sci
scilab/modules/preferences/macros/setPreferencesValue.sci

index 208fdf9..99a366f 100644 (file)
@@ -18,6 +18,18 @@ function createXConfiguration()
         return
     end;
 
+    if isdir(SCIHOME) then
+        try
+            fd = mopen(SCIHOME + "/test", "wb");
+            mclose(fd);
+            mdelete(SCIHOME + "/test")
+        catch
+            return
+        end
+    else
+        return
+    end
+
     doc = xmlRead(SCI + "/modules/preferences/etc/XConfiguration.xml");
     modules = ls(SCI + "/modules/*");
     xmls = [];
index 8f3ba12..ac73486 100644 (file)
@@ -28,7 +28,11 @@ function values = getPreferencesValue(xpath, attributes, doc)
     end
 
     if rhs == 2 then
-        doc = xmlRead(SCIHOME + "/XConfiguration.xml");
+        try
+            doc = xmlRead(SCIHOME + "/XConfiguration.xml");
+        catch
+            error(msprintf(gettext("%s: Invalid XConfiguration.xml file.\n"), "getPreferencesValue"));
+        end
     elseif typeof(doc) ~= "XMLDoc" then
         error(msprintf(gettext("%s: Wrong type for input argument #%d: A XMLDoc expected.\n"), "getPreferencesValue", 3));
     end
index a9797fb..ebbc4fb 100644 (file)
@@ -34,7 +34,11 @@ function setPreferencesValue(xpath, kv, doc)
     end
 
     if rhs == 2 then
-        doc = xmlRead(SCIHOME + "/XConfiguration.xml");
+        try
+            doc = xmlRead(SCIHOME + "/XConfiguration.xml");
+        catch
+            error(msprintf(gettext("%s: Invalid XConfiguration.xml file.\n"), "setPreferencesValue"));
+        end
     elseif typeof(doc) ~= "XMLDoc" then
         error(msprintf(gettext("%s: Wrong type for input argument #%d: A XMLDoc expected.\n"), "setPreferencesValue", 3));
     end