DataBaseSourceCodeManagementSettingsAppl.st
changeset 14666 28321a5ff34f
parent 14395 1361c2036f88
child 15566 184cea584be5
child 16154 5939931ac858
--- a/DataBaseSourceCodeManagementSettingsAppl.st	Mon Jul 21 13:26:59 2014 +0200
+++ b/DataBaseSourceCodeManagementSettingsAppl.st	Mon Jul 21 13:27:51 2014 +0200
@@ -347,16 +347,18 @@
 !
 
 addPerModuleDB
-    |module path|
+    |module db path|
 
     acceptChannel value:true.    
 
     module := self perModuleDatabaseModule value.
-    path := self perModuleDB value.
-
-    path size > 0 ifTrue:[
-        self validateDirectoryExistsAndIsWritable:path.
-        self addModule:module withData:(Array with:FileBasedSourceCodeManager with:path).
+    db := self perModuleDB value.
+    db size > 0 ifTrue:[
+        (db startsWith:'sqlite:') ifTrue:[
+            path := db copyFrom:'sqlite:' size + 1.        
+            self validateDatabaseExistsAndIsWritable:db.
+        ].
+        self addModule:module withData:{ DataBaseSourceCodeManager . db }.
     ].
 
     "Created: / 25-12-2011 / 13:18:30 / cg"
@@ -392,9 +394,7 @@
     modules := dbPerModule select:[:entry | entry first == DataBaseSourceCodeManager].
     infoPerModule := Dictionary new.
     modules keysAndValuesDo:[:module :entry | 
-        entry first == DataBaseSourceCodeManager ifTrue:[
-            infoPerModule at:module put:(entry second).
-        ].
+        infoPerModule at:module put:(entry second).
     ].
     DataBaseSourceCodeManager repositoryInfoPerModule:infoPerModule.
     DataBaseSourceCodeManager shownInBrowserMenus:self shownInBrowserMenusHolder value. 
@@ -541,6 +541,65 @@
     "Modified: / 26-12-2011 / 01:11:59 / cg"
 !
 
+validateDatabaseExistsAndIsWritable:dbPath
+    |nm fn|
+
+    (dbPath startsWith:'sqlite:') ifFalse:[
+        (DataBaseSourceCodeManager openDB:dbPath) close.
+        ^ true
+    ].
+
+    fn := dbPath asFilename.
+    nm := fn baseName.
+
+    fn exists ifFalse:[
+        (self confirm:(resources 
+                            stringWithCRs:'Database "%1" does not exist.\Create ?'
+                            with:nm)
+        ) ifFalse:[
+            ^ false.
+        ].
+        fn directory exists ifFalse:[
+            fn directory
+                recursiveMakeDirectory; 
+                makeReadableForAll;
+                makeWritableForAll;
+                makeExecutableForAll.
+        ].
+        (DataBaseSourceCodeManager openDB:dbPath) close.
+        ^ true.
+    ].
+
+    (fn isDirectory) ifTrue:[
+        self warn:(resources 
+                            stringWithCRs:'"%1" exists but is a directory'
+                            with:nm).
+        ^ false.
+    ].
+
+    (fn isWritable and:[fn isReadable]) ifFalse:[
+        (self confirm:(resources 
+                            stringWithCRs:'"%1" is not both readable and writable.\Change ?'
+                            with:nm)
+        ) ifFalse:[
+            ^ false.
+        ].
+        fn
+            makeReadable;
+            makeWritable.
+        (fn isWritable and:[fn isReadable]) ifFalse:[
+            self warn:(resources 
+                                stringWithCRs:'"%1" cannot be made both readable and writable.'
+                                with:nm).
+            ^ false.
+        ].
+    ].
+
+    ^ true
+
+    "Created: / 21-12-2011 / 14:43:11 / cg"
+!
+
 validateDirectoryExistsAndIsWritable:aDirectory
     |nm fn|
 
@@ -669,10 +728,10 @@
 !DataBaseSourceCodeManagementSettingsAppl class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/DataBaseSourceCodeManagementSettingsAppl.st,v 1.20 2014-05-23 08:15:23 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/DataBaseSourceCodeManagementSettingsAppl.st,v 1.21 2014-07-21 11:27:51 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/DataBaseSourceCodeManagementSettingsAppl.st,v 1.20 2014-05-23 08:15:23 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/DataBaseSourceCodeManagementSettingsAppl.st,v 1.21 2014-07-21 11:27:51 cg Exp $'
 ! !