fetcher git: fixes for crypto setup

This commit is contained in:
Hylke Bons 2012-10-20 23:22:41 +01:00
parent 94143df2e6
commit c274e87019
2 changed files with 45 additions and 37 deletions

View file

@ -42,12 +42,14 @@ namespace SparkleLib.Git {
SparkleGit git = new SparkleGit (TargetFolder, "branch -a"); SparkleGit git = new SparkleGit (TargetFolder, "branch -a");
git.StartAndWaitForExit (); git.StartAndWaitForExit ();
string [] branches = git.StartAndReadStandardOutput ().Split (Environment.NewLine.ToCharArray ()); string [] branches = git.StartAndReadStandardOutput ().Split ("\n".ToCharArray ());
// TODO double check env.newline ^ Regex salt_regex = new Regex ("remotes/origin/salt-(.+)");
foreach (string branch in branches) { foreach (string branch in branches) {
if (branch.StartsWith (" remotes/origin/salt-")) { Match salt_match = salt_regex.Match (branch);
this.cached_salt = branch.Substring (22);
if (salt_match.Success) {
this.cached_salt = salt_match.Groups [1].Value;
break; break;
} }
} }
@ -57,7 +59,7 @@ namespace SparkleLib.Git {
this.cached_salt = GenerateCryptoSalt (); this.cached_salt = GenerateCryptoSalt ();
string salt_file_path = new string [] { TargetFolder, ".git", "salt" }.Combine (); string salt_file_path = new string [] { TargetFolder, ".git", "salt" }.Combine ();
// Temporarily store the salt in a file, so the Repo can // Temporarily store the salt in a file, so the Repo object can
// push it to a branch on the host later // push it to a branch on the host later
File.WriteAllText (salt_file_path, this.cached_salt); File.WriteAllText (salt_file_path, this.cached_salt);
} }
@ -180,6 +182,9 @@ namespace SparkleLib.Git {
this.git.WaitForExit (); this.git.WaitForExit ();
if (this.git.ExitCode == 0) { if (this.git.ExitCode == 0) {
SparkleGit git_fetch = new SparkleGit (TargetFolder, "fetch --all");
git_fetch.StartAndWaitForExit ();
while (percentage < 100) { while (percentage < 100) {
percentage += 25; percentage += 25;
@ -231,9 +236,11 @@ namespace SparkleLib.Git {
string n = Environment.NewLine; string n = Environment.NewLine;
string salt = this.crypto_salt;
config += "[filter \"crypto\"]" + n + config += "[filter \"crypto\"]" + n +
"\tsmudge = openssl enc -d -aes-256-cbc -base64 -S " + this.crypto_salt + " -pass file:.git/password" + n + "\tsmudge = openssl enc -d -aes-256-cbc -base64 -S " + salt + " -pass file:.git/password" + n +
"\tclean = openssl enc -e -aes-256-cbc -base64 -S " + this.crypto_salt + " -pass file:.git/password" + n; "\tclean = openssl enc -e -aes-256-cbc -base64 -S " + salt + " -pass file:.git/password" + n;
File.WriteAllText (repo_config_file_path, config); File.WriteAllText (repo_config_file_path, config);

View file

@ -28,7 +28,7 @@ namespace SparkleLib.Git {
public class SparkleRepo : SparkleRepoBase { public class SparkleRepo : SparkleRepoBase {
private bool user_is_set; private bool user_is_set;
private bool use_git_bin; private bool use_git_bin;
private bool is_encrypted; private bool is_encrypted;
@ -185,22 +185,6 @@ namespace SparkleLib.Git {
string message = FormatCommitMessage (); string message = FormatCommitMessage ();
Commit (message); Commit (message);
string salt_file_path = new string [] { LocalPath, ".git", "salt" }.Combine ();
// If the repo is encrypted, create a branch to
// store the in and push it to the host
if (File.Exists (salt_file_path)) {
string salt = File.ReadAllText (salt_file_path).Trim ();
SparkleGit git_salt = new SparkleGit (LocalPath, "branch salt-" + salt);
git_salt.StartAndWaitForExit ();
git_salt = new SparkleGit (LocalPath, "push origin salt-" + salt);
git_salt.StartAndWaitForExit ();
File.Delete (salt_file_path);
}
} }
SparkleGit git; SparkleGit git;
@ -268,6 +252,23 @@ namespace SparkleLib.Git {
if (git.ExitCode == 0) { if (git.ExitCode == 0) {
ClearCache (); ClearCache ();
string salt_file_path = new string [] { LocalPath, ".git", "salt" }.Combine ();
// If the repo is encrypted, create a branch to
// store the in and push it to the host
if (File.Exists (salt_file_path)) {
string salt = File.ReadAllText (salt_file_path).Trim ();
SparkleGit git_salt = new SparkleGit (LocalPath, "branch salt-" + salt);
git_salt.StartAndWaitForExit ();
git_salt = new SparkleGit (LocalPath, "push origin salt-" + salt);
git_salt.StartAndWaitForExit ();
File.Delete (salt_file_path);
}
return true; return true;
} else { } else {
@ -337,11 +338,11 @@ namespace SparkleLib.Git {
Rebase (); Rebase ();
string identifier_file_path = Path.Combine (LocalPath, ".sparkleshare"); string identifier_file_path = Path.Combine (LocalPath, ".sparkleshare");
File.SetAttributes (identifier_file_path, FileAttributes.Hidden); File.SetAttributes (identifier_file_path, FileAttributes.Hidden);
ClearCache (); ClearCache ();
return true; return true;
} else { } else {
Error = ErrorStatus.HostUnreachable; Error = ErrorStatus.HostUnreachable;
@ -391,18 +392,18 @@ namespace SparkleLib.Git {
// Commits the made changes // Commits the made changes
private void Commit (string message) private void Commit (string message)
{ {
SparkleGit git; SparkleGit git;
if (!this.user_is_set) { if (!this.user_is_set) {
git = new SparkleGit (LocalPath, "config user.name \"" + base.local_config.User.Name + "\""); git = new SparkleGit (LocalPath, "config user.name \"" + base.local_config.User.Name + "\"");
git.StartAndWaitForExit (); git.StartAndWaitForExit ();
git = new SparkleGit (LocalPath, "config user.email \"" + base.local_config.User.Email + "\""); git = new SparkleGit (LocalPath, "config user.email \"" + base.local_config.User.Email + "\"");
git.StartAndWaitForExit (); git.StartAndWaitForExit ();
this.user_is_set = true; this.user_is_set = true;
} }
git = new SparkleGit (LocalPath, "commit --all --message=\"" + message + "\" " + git = new SparkleGit (LocalPath, "commit --all --message=\"" + message + "\" " +
"--author=\"" + base.local_config.User.Name + " <" + base.local_config.User.Email + ">\""); "--author=\"" + base.local_config.User.Name + " <" + base.local_config.User.Email + ">\"");