Add initial support for different storage types

This commit is contained in:
Hylke Bons 2016-05-31 10:59:35 -07:00 committed by Hylke Bons
parent 556220ffa0
commit b79c3ea3d0
10 changed files with 147 additions and 36 deletions

View file

@ -582,6 +582,13 @@ namespace SparkleShare {
}
this.fetcher.Finished += delegate (bool repo_is_encrypted, bool repo_is_empty, string [] warnings) {
if (repo_is_empty) {
ShowSetupWindow (PageType.StorageSetup);
}
return; // TODO
if (repo_is_encrypted && repo_is_empty) {
ShowSetupWindowEvent (PageType.CryptoSetup);
@ -620,10 +627,24 @@ namespace SparkleShare {
{
return this.fetcher.IsFetchedRepoPasswordCorrect (password);
}
public void FinishFetcher (string password)
public void FinishFetcher (StorageType storage_type)
{
if (storage_type == StorageType.Media) {
FinishFetcher (); // TODO: enable large files
return;
}
FinishFetcher ();
}
public void FinishFetcher (StorageType storage_type, string password)
{
if (storage_type != StorageType.Encrypted)
return;
this.fetcher.EnableFetchedRepoCrypto (password);
FinishFetcher ();
}

View file

@ -6,6 +6,7 @@
<description>The biggest collection of Open Source projects</description>
<icon>github.png</icon>
<backend>Git</backend>
<storage_type>LargeFiles</storage_type>
<fingerprint>9d:38:5b:83:a9:17:52:92:56:1a:5e:c4:d4:81:8e:0a:ca:51:a2:64:f1:74:20:11:2e:f8:8a:c3:a1:39:49:8f</fingerprint>
</info>
<address>

View file

@ -34,6 +34,7 @@ namespace SparkleShare {
Error,
Finished,
Tutorial,
StorageSetup,
CryptoSetup,
CryptoPassword
}
@ -500,6 +501,24 @@ namespace SparkleShare {
}
public void StoragePageCompleted (StorageType storage_type)
{
if (storage_type == StorageType.Encrypted) {
ChangePageEvent (PageType.CryptoSetup, null);
return;
}
ProgressBarPercentage = 100.0;
ChangePageEvent (PageType.Syncing, null);
new Thread (() => {
Thread.Sleep (1000);
SparkleShare.Controller.FinishFetcher (); // TODO:
}).Start ();
}
public void CheckCryptoSetupPage (string password)
{
new Thread (() => {
@ -535,7 +554,7 @@ namespace SparkleShare {
new Thread (() => {
Thread.Sleep (1000);
SparkleShare.Controller.FinishFetcher (password);
SparkleShare.Controller.FinishFetcher (StorageType.Encrypted, password);
}).Start ();
}

View file

@ -314,7 +314,7 @@ namespace SparkleShare {
public void AddHostedProjectClicked ()
{
new Thread (() => SparkleShare.Controller.ShowSetupWindow (PageType.Add)).Start ();
new Thread (() => SparkleShare.Controller.ShowSetupWindow (PageType.StorageSetup)).Start ();
}
public void CopyToClipboardClicked ()

View file

@ -468,6 +468,62 @@ namespace SparkleShare {
Add (points);
}
if (type == PageType.StorageSetup) {
Header = "Set up storage type";
Description = "What type of storage would you like to use?";
VBox layout_vertical = new VBox (false, 0);
var css_provider = new CssProvider ();
css_provider.LoadFromData ("GtkRadioButton {" +
"font-weight: bold;" +
"}");
RadioButton radio_plain = new RadioButton (null, "Plain Storage") { Active = true };
Label label_plain = new Label ("Nothing fancy.") { Xalign = 0 };
RadioButton radio_large_files = new RadioButton (radio_plain, "Media Storage");
Label label_large_files = new Label ("Trade off versioning for space; don't keep a history locally.") { Xalign = 0 };
RadioButton radio_encrypted = new RadioButton (radio_plain, "Encrypted Storage");
Label label_encrypted = new Label ("Trade off efficiency for privacy; encrypt files before storing them.") { Xalign = 0 };
radio_plain.StyleContext.AddProvider (css_provider, 800);
radio_large_files.StyleContext.AddProvider (css_provider, 800);
radio_encrypted.StyleContext.AddProvider (css_provider, 800);
layout_vertical.PackStart (radio_plain, false, false, 6);
layout_vertical.PackStart (label_plain, false, false, 0);
layout_vertical.PackStart (radio_large_files, false, false, 6);
layout_vertical.PackStart (label_large_files, false, false, 0);
layout_vertical.PackStart (radio_encrypted, false, false, 6);
layout_vertical.PackStart (label_encrypted, false, false, 0);
Add (layout_vertical);
Button cancel_button = new Button ("Cancel");
Button continue_button = new Button ("Continue");
continue_button.Clicked += delegate {
if (radio_large_files.Active) {
Controller.StoragePageCompleted (StorageType.Media);
return;
}
if (radio_encrypted.Active) {
Controller.StoragePageCompleted (StorageType.Media);
return;
}
Controller.StoragePageCompleted (StorageType.Plain);
};
AddButton (cancel_button);
AddButton (continue_button);
}
if (type == PageType.CryptoSetup || type == PageType.CryptoPassword) {
if (type == PageType.CryptoSetup) {
Header = "Set up file encryption";

View file

@ -51,6 +51,8 @@ namespace Sparkles {
public abstract bool IsFetchedRepoPasswordCorrect (string password);
public abstract void EnableFetchedRepoCrypto (string password);
protected readonly List<StorageTypeInfo> AvailableStorageTypes = new List<StorageTypeInfo> ();
public double ProgressPercentage { get; private set; }
public double ProgressSpeed { get; private set; }
@ -109,6 +111,9 @@ namespace Sparkles {
protected BaseFetcher (SparkleFetcherInfo info)
{
AvailableStorageTypes.Add (
new StorageTypeInfo (StorageType.Plain, "Plain Storage", "Nothing fancy."));
OriginalFetcherInfo = info;
RequiredFingerprint = info.Fingerprint;
FetchPriorHistory = info.FetchPriorHistory;

View file

@ -24,11 +24,29 @@ using Timers = System.Timers;
namespace Sparkles {
public enum RepositoryStorageType {
public enum StorageType {
Unknown,
Plain,
Encrypted,
LargeFiles,
LargeFilesEncrypted
Media,
Encrypted
}
public class StorageTypeInfo {
public readonly StorageType Type;
public readonly string Name;
public readonly string Description;
public StorageTypeInfo (StorageType storage_type, string name, string description)
{
Type = storage_type;
Name = name;
Description = description;
}
}
public enum SyncStatus {
@ -69,7 +87,7 @@ namespace Sparkles {
public abstract List<ChangeSet> GetChangeSets ();
public abstract List<ChangeSet> GetChangeSets (string path);
protected RepositoryStorageType StorageType = RepositoryStorageType.Plain;
protected StorageType StorageType = StorageType.Plain;
public static bool UseCustomWatcher = false;

View file

@ -25,7 +25,6 @@ namespace Sparkles.Git {
static string git_path;
static string git_lfs_path;
public static string GitPath {
get {
@ -40,19 +39,6 @@ namespace Sparkles.Git {
}
}
public static string GitLFSPath {
get {
if (git_lfs_path == null)
git_lfs_path = LocateCommand ("git-lfs");
return git_lfs_path;
}
set {
git_lfs_path = value;
}
}
public static string GitVersion {
get {
@ -64,12 +50,13 @@ namespace Sparkles.Git {
}
}
public static string GitLFSVersion {
get {
if (GitLFSPath == null)
GitLFSPath = LocateCommand ("git-lfs");
if (GitPath == null)
GitPath = LocateCommand ("git");
string git_lfs_version = new Command (GitLFSPath, "version").StartAndReadStandardOutput ();
string git_lfs_version = new Command (GitPath, "lfs version").StartAndReadStandardOutput ();
return git_lfs_version.Replace ("git-lfs/", "").Split (' ') [0];
}
}
@ -95,8 +82,6 @@ namespace Sparkles.Git {
if (ExecPath == null)
SetEnvironmentVariable ("GIT_EXEC_PATH", ExecPath);
Console.WriteLine (GIT_SSH_COMMAND);
SetEnvironmentVariable ("GIT_SSH_COMMAND", GIT_SSH_COMMAND);
SetEnvironmentVariable ("GIT_TERMINAL_PROMPT", "0");
SetEnvironmentVariable ("LANG", "en_US");
@ -108,8 +93,9 @@ namespace Sparkles.Git {
return SSHPath + " " +
"-i " + auth_info.PrivateKeyFilePath.Replace (" ", "\\ ") + " " +
"-o UserKnownHostsFile=" + auth_info.KnownHostsFilePath.Replace (" ", "\\ ") + " " +
"-o PasswordAuthentication=no " +
"-F /dev/null"; // Ignore the environment's SSH config file
"-o IdentitiesOnly=yes" + " " + // Don't fall back to other keys on the system
"-o PasswordAuthentication=no" + " " + // Don't hang on possible password prompts
"-F /dev/null"; // Ignore the system's SSH config file
}

View file

@ -46,6 +46,10 @@ namespace Sparkles.Git {
public GitFetcher (SparkleFetcherInfo fetcher_info, SSHAuthenticationInfo auth_info) : base (fetcher_info)
{
AvailableStorageTypes.Add (
new StorageTypeInfo (StorageType.Encrypted, "Encrypted Storage",
"Trade off efficiency for privacy; encrypt files before storing them."));
this.auth_info = auth_info;
var uri_builder = new UriBuilder (RemoteUrl);
@ -55,6 +59,10 @@ namespace Sparkles.Git {
if (RemoteUrl.Host.Equals ("github.com") ||
RemoteUrl.Host.Equals ("gitlab.com")) {
AvailableStorageTypes.Add (
new StorageTypeInfo (StorageType.Media, "Media Storage",
"Trade off versioning for space; don't keep a history locally."));
uri_builder.Scheme = "ssh";
uri_builder.UserName = "git";

View file

@ -89,9 +89,6 @@ namespace Sparkles.Git {
{
this.auth_info = auth_info;
if (RemoteUrl.Host == "github.com") // TODO
StorageType = RepositoryStorageType.LargeFiles;
var git_config = new GitCommand (LocalPath, "config core.ignorecase false");
git_config.StartAndWaitForExit ();
@ -231,7 +228,7 @@ namespace Sparkles.Git {
if (File.Exists (pre_push_hook_path))
File.Delete (pre_push_hook_path);
if (StorageType == RepositoryStorageType.LargeFiles) {
if (StorageType == StorageType.Media) {
// TODO: Progress reporting, error handling
var git_lfs_push = new GitCommand (LocalPath, "lfs push origin " + branch, auth_info);
git_lfs_push.StartAndWaitForExit ();
@ -308,7 +305,7 @@ namespace Sparkles.Git {
public override bool SyncDown ()
{
if (StorageType == RepositoryStorageType.LargeFiles) {
if (StorageType == StorageType.Media) {
var git_lfs_pull = new GitCommand (LocalPath, "lfs pull", auth_info);
git_lfs_pull.StartAndWaitForExit ();
}