v.io/jiri: switch to writing the new profiles dir by default.

Change-Id: Ie1e813738753040b81dd60b81230b119390d18ea
diff --git a/profiles/profilescmdline/manager_cmdline.go b/profiles/profilescmdline/manager_cmdline.go
index 9a25383..436b4ea 100644
--- a/profiles/profilescmdline/manager_cmdline.go
+++ b/profiles/profilescmdline/manager_cmdline.go
@@ -29,7 +29,6 @@
 	"flag"
 	"fmt"
 	"os"
-	"path/filepath"
 	"strings"
 
 	"v.io/jiri"
@@ -338,12 +337,8 @@
 	if !runSubcommands {
 		return nil
 	}
-	fi, err := os.Stat(filepath.Join(jirix.Root, jiri.ProfilesDBDir))
-	if err == nil && fi.IsDir() {
-		cmds, _ := lookpath.LookPrefix(jirix.Env(), "jiri-profile-", nil)
-		return cmds
-	}
-	return nil
+	cmds, _ := lookpath.LookPrefix(jirix.Env(), "jiri-profile-", nil)
+	return cmds
 }
 
 func allAvailableManagers(jirix *jiri.X) ([]string, error) {
@@ -421,34 +416,27 @@
 }
 
 func writeDB(jirix *jiri.X, db *profiles.DB, installer, path string) error {
-	// If path is a directory and installer is empty, then do nothing,
-	// otherwise write out the file.
-	isdir := false
+	// Do nothing if the installer is not supplied. This will generally
+	// happen when/if writeDB is called from the top-level profile driver
+	// command rather than from a subcommand.
+	if installer == "" {
+		return nil
+	}
 	fi, err := os.Stat(path)
 	if err != nil {
 		if !os.IsNotExist(err) {
 			return err
 		}
+		// New setup, but the directory doesn't exist yet.
+		if err := os.MkdirAll(path, os.FileMode(0755)); err != nil {
+			return err
+		}
 	} else {
-		isdir = fi.IsDir()
-	}
-	if isdir {
-		if installer != "" {
-			// New setup with installers writing their own file in a directory
-			return db.Write(jirix, installer, path)
-		} else {
-			// New setup, no installer, so don't write out the file.
-			return nil
+		if !fi.IsDir() {
+			return fmt.Errorf("%s exists but is not a directory", path)
 		}
 	}
-	if installer == "" {
-		// Old setup with no installers and writing to a file.
-		return db.Write(jirix, installer, path)
-	}
-	// New setup, but the directory doesn't exist yet.
-	if err := os.MkdirAll(path, os.FileMode(0755)); err != nil {
-		return err
-	}
+	// New setup with installers writing their own file in a directory
 	return db.Write(jirix, installer, path)
 }
 
diff --git a/profiles/profilescmdline/manager_test.go b/profiles/profilescmdline/manager_test.go
index 621bc39..a81385e 100644
--- a/profiles/profilescmdline/manager_test.go
+++ b/profiles/profilescmdline/manager_test.go
@@ -135,11 +135,6 @@
 			t.Errorf("%v does not contain %v\n", got, want)
 		}
 	}
-	os.RemoveAll(filepath.Join(fake.X.Root, jiri.ProfilesDBDir))
-	stdout = run(sh, dir, "jiri", "profile", "available", "-v")
-	if got, want := strings.TrimSpace(stdout), "Available Subcommands:"; got != want {
-		t.Errorf("got %v, want %v", got, want)
-	}
 }
 
 func loc() string {