Try to download file if it's not in the git tree

This commit is contained in:
Marc Egea i Sala
2015-11-20 15:15:42 +00:00
parent dcaf2d0fa6
commit 229ed1c09d
7 changed files with 230 additions and 63 deletions

View File

@@ -10,6 +10,7 @@ import uk.ac.ic.wlgitbridge.data.filestore.GitDirectoryContents;
import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory;
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
import uk.ac.ic.wlgitbridge.data.model.db.PersistentStore;
import uk.ac.ic.wlgitbridge.data.model.db.SqlitePersistentStore;
import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException;
import uk.ac.ic.wlgitbridge.snapshot.getforversion.SnapshotAttachment;
import uk.ac.ic.wlgitbridge.snapshot.push.exception.SnapshotPostException;
@@ -31,7 +32,7 @@ public class DataStore {
public DataStore(String rootGitDirectoryPath) {
rootGitDirectory = initRootGitDirectory(rootGitDirectoryPath);
persistentStore = new PersistentStore(rootGitDirectory);
persistentStore = new SqlitePersistentStore(rootGitDirectory);
List<String> excludedFromDeletion = persistentStore.getProjectNames();
excludedFromDeletion.add(".wlgb");
Util.deleteInDirectoryApartFrom(rootGitDirectory, excludedFromDeletion.toArray(new String[] {}));

View File

@@ -42,9 +42,15 @@ public class ResourceFetcher {
if (contents == null) {
RawFile rawFile = new RepositoryObjectTreeWalker(repository).getDirectoryContents().getFileTable().get(path);
if (rawFile == null) {
throw new IllegalStateException("file was not in the current commit, or the git tree, yet path was not null");
Util.sout(
"WARNING: " +
"File " + path + " was not in the current commit, or the git tree, yet path was not null. " +
"File url is: " + url
);
contents = fetch(projectName, url, path);
} else {
contents = rawFile.getContents();
}
contents = rawFile.getContents();
}
}
return new RepositoryFile(newPath, contents);

View File

@@ -1,72 +1,20 @@
package uk.ac.ic.wlgitbridge.data.model.db;
import uk.ac.ic.wlgitbridge.data.model.db.sql.SQLiteWLDatabase;
import java.io.File;
import java.sql.SQLException;
import java.util.List;
/**
* Created by Winston on 19/11/14.
* Created by m on 20/11/15.
*/
public class PersistentStore {
public interface PersistentStore {
List<String> getProjectNames();
private final SQLiteWLDatabase database;
void setLatestVersionForProject(String project, int versionID);
public PersistentStore(File rootGitDirectory) {
try {
database = new SQLiteWLDatabase(rootGitDirectory);
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
int getLatestVersionForProject(String project);
public List<String> getProjectNames() {
try {
return database.getProjectNames();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void setLatestVersionForProject(String project, int versionID) {
try {
database.setVersionIDForProject(project, versionID);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
void addURLIndexForProject(String projectName, String url, String path);
public int getLatestVersionForProject(String project) {
try {
return database.getVersionIDForProjectName(project);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void addURLIndexForProject(String projectName, String url, String path) {
try {
database.addURLIndex(projectName, url, path);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void deleteFilesForProject(String project, String... files) {
try {
database.deleteFilesForProject(project, files);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public String getPathForURLInProject(String projectName, String url) {
try {
return database.getPathForURLInProject(projectName, url);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
void deleteFilesForProject(String project, String... files);
String getPathForURLInProject(String projectName, String url);
}

View File

@@ -0,0 +1,78 @@
package uk.ac.ic.wlgitbridge.data.model.db;
import uk.ac.ic.wlgitbridge.data.model.db.sql.SQLiteWLDatabase;
import java.io.File;
import java.sql.SQLException;
import java.util.List;
/**
* Created by Winston on 19/11/14.
*/
public class SqlitePersistentStore implements PersistentStore {
private final SQLiteWLDatabase database;
public SqlitePersistentStore(File rootGitDirectory) {
try {
database = new SQLiteWLDatabase(rootGitDirectory);
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@Override
public List<String> getProjectNames() {
try {
return database.getProjectNames();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public void setLatestVersionForProject(String project, int versionID) {
try {
database.setVersionIDForProject(project, versionID);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public int getLatestVersionForProject(String project) {
try {
return database.getVersionIDForProjectName(project);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public void addURLIndexForProject(String projectName, String url, String path) {
try {
database.addURLIndex(projectName, url, path);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public void deleteFilesForProject(String project, String... files) {
try {
database.deleteFilesForProject(project, files);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public String getPathForURLInProject(String projectName, String url) {
try {
return database.getPathForURLInProject(projectName, url);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}