Update of /var/cvs/src/org/mmbase/module/core
In directory james.mmbase.org:/tmp/cvs-serv6763

Modified Files:
        MMBase.java MMBaseContext.java 
Log Message:
rationalized data dir stuff a bit


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/module/core


Index: MMBase.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/module/core/MMBase.java,v
retrieving revision 1.237
retrieving revision 1.238
diff -u -b -r1.237 -r1.238
--- MMBase.java 19 Mar 2008 11:43:30 -0000      1.237
+++ MMBase.java 21 Mar 2008 13:42:59 -0000      1.238
@@ -44,7 +44,7 @@
  * @author Pierre van Rooden
  * @author Johannes Verelst
  * @author Ernst Bunders
- * @version $Id: MMBase.java,v 1.237 2008/03/19 11:43:30 pierre Exp $
+ * @version $Id: MMBase.java,v 1.238 2008/03/21 13:42:59 michiel Exp $
  */
 public class MMBase extends ProcessorModule {
 
@@ -1302,4 +1302,55 @@
         }
     }
 
+
+    /**
+     * @since MMBase-1.9
+     */
+    public File getDataDir() {
+        String dataDirString = getInitParameter("datadir");
+
+        javax.servlet.ServletContext sc = MMBaseContext.getServletContext();
+        if (dataDirString == null || dataDirString.equals("")) {
+            if (sc == null) {
+                dataDirString = "data";
+            } else {
+                dataDirString = "WEB-INF/data";
+            }
+        }
+        File dataDir = new File(dataDirString);
+
+        if (! dataDir.isAbsolute()) {
+            if (sc != null) {
+                dataDir = new File(sc.getRealPath("/" + dataDirString));
+            } else {
+                dataDir = new File(System.getProperty("user.dir"), 
dataDirString);
+            }
+        }
+
+        if (! dataDir.exists()) {
+            try {
+                if (dataDir.mkdirs()) {
+                    log.info("Created " + dataDir);
+                }
+            } catch (SecurityException  se) {
+                log.warn(se);
+            }
+        }
+
+        if (! dataDir.isDirectory()) {
+            log.warn("Datadir " + dataDir + " is not a directory");
+        }
+        if (! dataDir.canRead()) {
+            log.warn("Datadir " + dataDir + " is not readable");
+        }
+        if (! dataDir.canWrite()) {
+            log.warn("Datadir " + dataDir + " is not writable");
+        }
+
+        log.info("MMBase data dir: " + dataDir);
+        return dataDir;
+
+    }
+
+
 }


Index: MMBaseContext.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/module/core/MMBaseContext.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- MMBaseContext.java  17 Mar 2008 13:20:18 -0000      1.57
+++ MMBaseContext.java  21 Mar 2008 13:42:59 -0000      1.58
@@ -27,7 +27,7 @@
  * @author Daniel Ockeloen
  * @author David van Zeventer
  * @author Jaco de Groot
- * @version $Id: MMBaseContext.java,v 1.57 2008/03/17 13:20:18 michiel Exp $
+ * @version $Id: MMBaseContext.java,v 1.58 2008/03/21 13:42:59 michiel Exp $
  */
 public class MMBaseContext {
     private static final Logger log = 
Logging.getLoggerInstance(MMBaseContext.class);
@@ -385,13 +385,6 @@
         return htmlRootUrlPath;
     }
 
-    /**
-     * @since MMBase-1.8.4
-     */
-    public static File getDataDir() {
-        return null;
-    }
-
 
     /**
      * Returns whether this class has been initialized.
_______________________________________________
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to