Add checkDB to upgrade the DB

This commit is contained in:
Winston Li 2016-08-25 00:47:18 +01:00 committed by Michael Mazour
parent 52e5d2921f
commit eb77d166e2
3 changed files with 30 additions and 1 deletions

View file

@ -22,7 +22,7 @@ public class GitBridgeApp implements Runnable {
public static final int EXIT_CODE_FAILED = 1;
private static final String USAGE_MESSAGE =
"usage: writelatex-git-bridge config_file";
"usage: writelatex-git-bridge [config_file]";
private String configFilePath;
Config config;

View file

@ -31,6 +31,7 @@ import uk.ac.ic.wlgitbridge.snapshot.push.PushResult;
import uk.ac.ic.wlgitbridge.snapshot.push.exception.*;
import uk.ac.ic.wlgitbridge.util.Log;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
@ -114,6 +115,33 @@ public class Bridge {
swapJob.start();
}
public void checkDB() {
Log.info("Checking DB");
File rootDir = repoStore.getRootDirectory();
for (File f : rootDir.listFiles()) {
if (f.getName().equals(".wlgb")) {
continue;
}
String projName = f.getName();
try (LockGuard __ = lock.lockGuard(projName)) {
File dotGit = new File(f, ".git");
if (!dotGit.exists()) {
Log.warn("Project: {} has no .git", projName);
continue;
}
ProjectState state = dbStore.getProjectState(projName);
if (state != ProjectState.NOT_PRESENT) {
continue;
}
Log.warn("Project: {} not in swap_store, adding", projName);
dbStore.setLastAccessedTime(
projName,
new Timestamp(dotGit.lastModified())
);
}
}
}
public boolean projectExists(
Credential oauth2,
String projectName

View file

@ -82,6 +82,7 @@ public class GitBridgeServer {
*/
public void start() {
try {
bridge.checkDB();
jettyServer.start();
bridge.startSwapJob();
Log.info(Util.getServiceName() + "-Git Bridge server started");