Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Install into /data/data/com.app.namespace & fix potential bug (couch
Browse files Browse the repository at this point in the history
removed before checking to see whether requested version is
installed).  Also remove erlang directory.
  • Loading branch information
mattadams committed Jul 7, 2011
1 parent 3ae75e7 commit f63fb72
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/com/couchbase/libcouch/CouchInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CouchInstaller {
final static String TAG = "CouchDB";

public static String dataPath() {
return "/data/data/" + appNamespace + "/cache";
return "/data/data/" + appNamespace;
}
public static String externalPath() {
return Environment.getExternalStorageDirectory() + "/Android/data/" + appNamespace;
Expand All @@ -46,17 +46,28 @@ public static String indexFile() {
public static void doInstall(String url, String pkg, Handler handler, CouchService service)
throws IOException {

// WARNING: This deleted any previously installed couchdb data
// and binaries stored on the sdcard to keep in line with usual
// android app behaviour. However there doesnt look to be a way to protect
// ourselves from wiping the entire sdcard with a typo, so just be
// careful
File couchDir = new File(dataPath() + "/couchdb");
if (couchDir.exists()) {
deleteDirectory(couchDir);
}

if(!(new File(dataPath() + "/" + pkg + ".installedfiles")).exists()) {
if(!checkInstalled(pkg)) {
/*
* WARNING: the following two stanzas delete any previously installed
* CouchDB and Erlang binaries stored in the app data space. It isn't
* usually possible (in a non-rooted or emulated environment) to hurt
* other data directories but one must be especially careful when carrying
* out this sort of operation on external storage where there are no ways
* of protecting ourselves from wiping the entire SD card with a typo.
*/

File couchDir = new File(dataPath() + "/couchdb");

if (couchDir.exists()) {
deleteDirectory(couchDir);
}

File erlangDir = new File(dataPath() + "/erlang");

if (erlangDir.exists()) {
deleteDirectory(erlangDir);
}

installPackage(url, pkg, handler, service);
}

Expand Down Expand Up @@ -189,7 +200,10 @@ private static void installPackage(String baseUrl, String pkg, Handler handler,
}
iLOWriter.close();

// Write out full list of all installed files + file modes
/*
* Write out full list of all installed files + file modes (the data in this file
* only represents the most recently installed release)
*/
iLOWriter = new FileWriter(indexFile());

for (String file : allInstalledFiles) {
Expand Down Expand Up @@ -220,8 +234,8 @@ private static void installPackage(String baseUrl, String pkg, Handler handler,
}

/*
* Verifies that CouchDB is installed by checking the package files we
* write on installation + the data directory on the sd card
* Verifies that requested version of CouchDB is installed by checking for the presence of
* the package files we write upon installation in the data directory of the app.
*/
public static boolean checkInstalled(String pkg) {

Expand All @@ -230,7 +244,7 @@ public static boolean checkInstalled(String pkg) {
return false;
}

return true;//new File(couchPath()).exists();
return true;
}

/*
Expand Down

0 comments on commit f63fb72

Please sign in to comment.