fetcher: fix support for http(s) repos. closes #1000

This commit is contained in:
Hylke Bons 2012-10-05 21:55:57 +02:00
parent 786deb4f05
commit a406a0964d
5 changed files with 49 additions and 53 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -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 ();

View file

@ -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 ();