From a406a0964ddb160368b981f7c73cfd491e3aa6ab Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 5 Oct 2012 21:55:57 +0200 Subject: [PATCH] fetcher: fix support for http(s) repos. closes #1000 --- SparkleLib/Git/SparkleFetcherGit.cs | 19 ++++----- SparkleLib/SparkleFetcherBase.cs | 55 +++++++++++++------------ SparkleShare/Common/HTML/event-log.html | 8 ++-- SparkleShare/SparkleControllerBase.cs | 14 +++---- SparkleShare/SparkleKeys.cs | 6 +-- 5 files changed, 49 insertions(+), 53 deletions(-) diff --git a/SparkleLib/Git/SparkleFetcherGit.cs b/SparkleLib/Git/SparkleFetcherGit.cs index 69bb8d7c..914ab654 100755 --- a/SparkleLib/Git/SparkleFetcherGit.cs +++ b/SparkleLib/Git/SparkleFetcherGit.cs @@ -77,7 +77,7 @@ namespace SparkleLib.Git { uri = new Uri ("ssh://" + uri); } - if (uri.Host.Equals ("gitorious.org")) { + if (uri.Host.Equals ("gitorious.org") && !uri.Scheme.StartsWith ("http")) { if (!uri.AbsolutePath.Equals ("/") && !uri.AbsolutePath.EndsWith (".git")) { @@ -87,20 +87,17 @@ namespace SparkleLib.Git { uri = new Uri ("ssh://git@gitorious.org" + uri.AbsolutePath); } - } else if (uri.Host.Equals ("github.com")) { + } else if (uri.Host.Equals ("github.com") && !uri.Scheme.StartsWith ("http")) { uri = new Uri ("ssh://git@github.com" + uri.AbsolutePath); - } else if (uri.Host.Equals ("bitbucket.org")) { + } else if (uri.Host.Equals ("bitbucket.org") && !uri.Scheme.StartsWith ("http")) { // Nothing really } else if (uri.Host.Equals ("gnome.org")) { uri = new Uri ("ssh://git@gnome.org/git" + uri.AbsolutePath); } else { - if (string.IsNullOrEmpty (uri.UserInfo) && - !uri.Scheme.Equals ("https") && - !uri.Scheme.Equals ("http")) { - + if (string.IsNullOrEmpty (uri.UserInfo) && !uri.Scheme.StartsWith ("http")) { if (uri.Port == -1) uri = new Uri (uri.Scheme + "://storage@" + uri.Host + uri.AbsolutePath); else @@ -296,9 +293,11 @@ namespace SparkleLib.Git { public override void Stop () { try { - this.git.Close (); - this.git.Kill (); - this.git.Dispose (); + if (this.git != null) { + this.git.Close (); + this.git.Kill (); + this.git.Dispose (); + } } catch (Exception e) { SparkleLogger.LogInfo ("Fetcher", "Failed to dispose properly: " + e.Message); diff --git a/SparkleLib/SparkleFetcherBase.cs b/SparkleLib/SparkleFetcherBase.cs index 6d5be714..b906c122 100755 --- a/SparkleLib/SparkleFetcherBase.cs +++ b/SparkleLib/SparkleFetcherBase.cs @@ -122,36 +122,39 @@ namespace SparkleLib { if (Directory.Exists (TargetFolder)) Directory.Delete (TargetFolder, true); - string host = RemoteUrl.Host; - string host_key = GetHostKey (); + string host_key = ""; - if (string.IsNullOrEmpty (host) || host_key == null) { - Failed (); - return; - } - - bool warn = true; - if (RequiredFingerprint != null) { - string host_fingerprint = GetFingerprint (host_key); - - if (host_fingerprint == null || !RequiredFingerprint.Equals (host_fingerprint)) { - SparkleLogger.LogInfo ("Auth", "Fingerprint doesn't match"); - - this.errors.Add ("error: Host fingerprint doesn't match"); + if (!RemoteUrl.Scheme.StartsWith ("http")) { + host_key = FetchHostKey (); + + if (string.IsNullOrEmpty (RemoteUrl.Host) || host_key == null) { Failed (); - return; } + + bool warn = true; + if (RequiredFingerprint != null) { + string host_fingerprint = GetFingerprint (host_key); - warn = false; - SparkleLogger.LogInfo ("Auth", "Fingerprint matches"); + if (host_fingerprint == null || !RequiredFingerprint.Equals (host_fingerprint)) { + SparkleLogger.LogInfo ("Auth", "Fingerprint doesn't match"); - } else { - SparkleLogger.LogInfo ("Auth", "Skipping fingerprint check"); + this.errors.Add ("error: Host fingerprint doesn't match"); + Failed (); + + return; + } + + warn = false; + SparkleLogger.LogInfo ("Auth", "Fingerprint matches"); + + } else { + SparkleLogger.LogInfo ("Auth", "Skipping fingerprint check"); + } + + AcceptHostKey (host_key, warn); } - AcceptHostKey (host_key, warn); - this.thread = new Thread (() => { if (Fetch ()) { Thread.Sleep (500); @@ -159,8 +162,7 @@ namespace SparkleLib { IsActive = false; - // TODO: Find better way to determine if folder should have crypto setup - bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("-crypto"); + bool repo_is_encrypted = RemoteUrl.AbsolutePath.Contains ("-crypto"); Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings); } else { @@ -206,7 +208,7 @@ namespace SparkleLib { uri_builder.Password = ""; } - bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("-crypto"); + bool repo_is_encrypted = RemoteUrl.AbsolutePath.Contains ("-crypto"); string text; if (repo_is_encrypted) { @@ -235,6 +237,7 @@ namespace SparkleLib { return random.SHA1 (); } + public void Dispose () { if (this.thread != null) @@ -254,7 +257,7 @@ namespace SparkleLib { } - private string GetHostKey () + private string FetchHostKey () { string host = RemoteUrl.Host; int port = RemoteUrl.Port; diff --git a/SparkleShare/Common/HTML/event-log.html b/SparkleShare/Common/HTML/event-log.html index f3a5e4b1..9a98cde9 100755 --- a/SparkleShare/Common/HTML/event-log.html +++ b/SparkleShare/Common/HTML/event-log.html @@ -30,12 +30,10 @@ $('.show').each (function () { var entry_count = $(this).parent ().find ('dl').children ().length; - if (entry_count <= 10) { - $(this).hide (); - } else { - // Append the number of entries + if (entry_count > 10) $(this).html ('Show all ' + entry_count + '…'); - } + else + $(this).hide (); }); // When 'Show all' is clicked, show all collapsed events diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index e8656ae9..656adbd6 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -432,7 +432,7 @@ namespace SparkleShare { } else { if (Directory.Exists (args.FullPath) && args.ChangeType == WatcherChangeTypes.Created) return; - + CheckRepositories (); } } @@ -540,19 +540,20 @@ namespace SparkleShare { } catch (Exception e) { SparkleLogger.LogInfo ("Controller", - "Failed to delete " + this.fetcher.TargetFolder + ": " + e.Message); + "Failed to delete '" + this.fetcher.TargetFolder + "': " + e.Message); } } this.fetcher.Dispose (); this.fetcher = null; + + this.watcher.EnableRaisingEvents = true; } public void FinishFetcher (string password) { this.fetcher.EnableFetchedRepoCrypto (password); - FinishFetcher (); } @@ -590,6 +591,7 @@ namespace SparkleShare { } catch (Exception e) { SparkleLogger.LogInfo ("Controller", "Error moving directory: " + e.Message); + this.watcher.EnableRaisingEvents = true; return; } @@ -600,12 +602,6 @@ namespace SparkleShare { FolderFetched (this.fetcher.RemoteUrl.ToString (), this.fetcher.Warnings.ToArray ()); - /* TODO - if (!string.IsNullOrEmpty (announcements_url)) { - this.config.SetFolderOptionalAttribute ( - target_folder_name, "announcements_url", announcements_url); - */ - AddRepository (target_folder_path); FolderListChanged (); diff --git a/SparkleShare/SparkleKeys.cs b/SparkleShare/SparkleKeys.cs index 4997e54e..292fd636 100644 --- a/SparkleShare/SparkleKeys.cs +++ b/SparkleShare/SparkleKeys.cs @@ -52,9 +52,9 @@ namespace SparkleShare { computer_name = computer_name.Substring (0, computer_name.Length - 6); process.StartInfo.Arguments = "-t rsa " + // crypto type - "-P \"\"" /* password (none) */ + " " + - "-C \"" + computer_name + "\"" /* key comment */ + " " + - "-f \"" + key_name + "\"" /* file name */; + "-P \"\" " + // empty password + "-C \"" + computer_name + "\" " + // key comment + "-f \"" + key_name + "\""; // file name process.Start (); process.WaitForExit ();