init: Don't abort on empty directory
The following sequence should work: mkdir testgit java -jar gerrit.war init -d testgit Since testgit is empty, it should be acceptable for us to populate the directory with our files. Bug: issue 358 Change-Id: Ia85f31802066f8d39b042d3d057d33950a5035fd Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -87,6 +87,7 @@ public class Init extends SiteProgram {
|
|||||||
@Inject
|
@Inject
|
||||||
private SchemaFactory<ReviewDb> schema;
|
private SchemaFactory<ReviewDb> schema;
|
||||||
|
|
||||||
|
private boolean isNew;
|
||||||
private boolean deleteOnFailure;
|
private boolean deleteOnFailure;
|
||||||
private ConsoleUI ui;
|
private ConsoleUI ui;
|
||||||
private Injector dbInjector;
|
private Injector dbInjector;
|
||||||
@@ -113,7 +114,18 @@ public class Init extends SiteProgram {
|
|||||||
ui = ConsoleUI.getInstance(batchMode);
|
ui = ConsoleUI.getInstance(batchMode);
|
||||||
initPathLocations();
|
initPathLocations();
|
||||||
|
|
||||||
final boolean isNew = !site_path.exists();
|
if (site_path.exists()) {
|
||||||
|
final String[] contents = site_path.list();
|
||||||
|
if (contents != null)
|
||||||
|
isNew = contents.length == 0;
|
||||||
|
else if (site_path.isDirectory())
|
||||||
|
throw die("Cannot access " + site_path);
|
||||||
|
else
|
||||||
|
throw die("Not a directory: " + site_path);
|
||||||
|
} else {
|
||||||
|
isNew = true;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
upgradeFrom2_0();
|
upgradeFrom2_0();
|
||||||
|
|
||||||
@@ -188,9 +200,7 @@ public class Init extends SiteProgram {
|
|||||||
throw die("aborted by user");
|
throw die("aborted by user");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!etc_dir.exists() && !etc_dir.mkdirs()) {
|
mkdir(etc_dir);
|
||||||
throw die("Cannot create directory " + etc_dir);
|
|
||||||
}
|
|
||||||
for (String name : etcFiles) {
|
for (String name : etcFiles) {
|
||||||
final File src = new File(site_path, name);
|
final File src = new File(site_path, name);
|
||||||
final File dst = new File(etc_dir, name);
|
final File dst = new File(etc_dir, name);
|
||||||
@@ -210,24 +220,21 @@ public class Init extends SiteProgram {
|
|||||||
ConfigInvalidException {
|
ConfigInvalidException {
|
||||||
ui.header("Gerrit Code Review %s", version());
|
ui.header("Gerrit Code Review %s", version());
|
||||||
|
|
||||||
if (!gerrit_config.exists()) {
|
if (isNew) {
|
||||||
if (!ui.yesno(true, "Create '%s'", site_path.getCanonicalPath())) {
|
if (!ui.yesno(true, "Create '%s'", site_path.getCanonicalPath())) {
|
||||||
throw die("aborted by user");
|
throw die("aborted by user");
|
||||||
}
|
}
|
||||||
if (!site_path.mkdirs()) {
|
if (!site_path.isDirectory() && !site_path.mkdirs()) {
|
||||||
throw die("Cannot make directory " + site_path);
|
throw die("Cannot make directory " + site_path);
|
||||||
}
|
}
|
||||||
if (!etc_dir.mkdir()) {
|
|
||||||
throw die("Cannot make directory " + etc_dir);
|
|
||||||
}
|
|
||||||
deleteOnFailure = true;
|
deleteOnFailure = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bin_dir.mkdir();
|
mkdir(bin_dir);
|
||||||
etc_dir.mkdir();
|
mkdir(etc_dir);
|
||||||
lib_dir.mkdir();
|
mkdir(lib_dir);
|
||||||
logs_dir.mkdir();
|
mkdir(logs_dir);
|
||||||
static_dir.mkdir();
|
mkdir(static_dir);
|
||||||
|
|
||||||
cfg.load();
|
cfg.load();
|
||||||
sec.load();
|
sec.load();
|
||||||
@@ -338,6 +345,12 @@ public class Init extends SiteProgram {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void mkdir(final File path) {
|
||||||
|
if (!path.isDirectory() && !path.mkdir()) {
|
||||||
|
throw die("Cannot make directory " + path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void chmod(final int mode, final File path) throws IOException {
|
private static void chmod(final int mode, final File path) throws IOException {
|
||||||
if (!path.exists() && !path.createNewFile()) {
|
if (!path.exists() && !path.createNewFile()) {
|
||||||
throw new IOException("Cannot create " + path);
|
throw new IOException("Cannot create " + path);
|
||||||
|
|||||||
Reference in New Issue
Block a user