make restoring of files work
This commit is contained in:
parent
da0f3d53a5
commit
ef44b2ccfb
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
using SparkleLib;
|
using SparkleLib;
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
private bool user_is_set;
|
private bool user_is_set;
|
||||||
private bool use_git_bin;
|
private bool use_git_bin;
|
||||||
|
private bool is_encrypted;
|
||||||
|
|
||||||
|
|
||||||
public SparkleRepo (string path, SparkleConfig config) : base (path, config)
|
public SparkleRepo (string path, SparkleConfig config) : base (path, config)
|
||||||
|
@ -50,6 +52,11 @@ namespace SparkleLib.Git {
|
||||||
git = new SparkleGit (LocalPath, "rebase --abort");
|
git = new SparkleGit (LocalPath, "rebase --abort");
|
||||||
git.StartAndWaitForExit ();
|
git.StartAndWaitForExit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string password_file_path = Path.Combine (LocalPath, ".git", "password");
|
||||||
|
|
||||||
|
if (File.Exists (password_file_path))
|
||||||
|
this.is_encrypted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -548,14 +555,46 @@ namespace SparkleLib.Git {
|
||||||
throw new ArgumentNullException ("revision");
|
throw new ArgumentNullException ("revision");
|
||||||
|
|
||||||
path = path.Replace ("\\", "/");
|
path = path.Replace ("\\", "/");
|
||||||
|
SparkleLogger.LogInfo ("Git", Name + " | Restoring \"" + path + "\" (revision " + revision + ")");
|
||||||
|
|
||||||
SparkleGit git = new SparkleGit (LocalPath, "checkout " + revision + " \"" + path + "\"");
|
// FIXME: git-show doesn't decrypt objects, so we can't use it to retrieve
|
||||||
git.StartAndWaitForExit ();
|
// files from the index. This is a suboptimal workaround but it does the job
|
||||||
|
if (this.is_encrypted) {
|
||||||
|
// Restore the older file...
|
||||||
|
SparkleGit git = new SparkleGit (LocalPath, "checkout " + revision + " \"" + path + "\"");
|
||||||
|
git.StartAndWaitForExit ();
|
||||||
|
|
||||||
if (git.ExitCode == 0)
|
string local_file_path = Path.Combine (LocalPath, path);
|
||||||
SparkleLogger.LogInfo ("Git", Name + " | Checked out \"" + path + "\" (" + revision + ")");
|
|
||||||
else
|
// ...move it...
|
||||||
SparkleLogger.LogInfo ("Git", Name + " | Failed to check out \"" + path + "\" (" + revision + ")");
|
try {
|
||||||
|
File.Move (local_file_path, target_file_path);
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
SparkleLogger.LogInfo ("Git",
|
||||||
|
Name + " | Could not move \"" + local_file_path + "\" to \"" + target_file_path + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ...and restore the most recent revision
|
||||||
|
git = new SparkleGit (LocalPath, "checkout " + CurrentRevision + " \"" + path + "\"");
|
||||||
|
git.StartAndWaitForExit ();
|
||||||
|
|
||||||
|
// The correct way
|
||||||
|
} else {
|
||||||
|
path = path.Replace (" ", "\\ ");
|
||||||
|
|
||||||
|
SparkleGit git = new SparkleGit (LocalPath, "show " + revision + ":" + path + "");
|
||||||
|
git.Start ();
|
||||||
|
|
||||||
|
FileStream stream = File.OpenWrite (target_file_path);
|
||||||
|
git.StandardOutput.BaseStream.CopyTo (stream);
|
||||||
|
stream.Close ();
|
||||||
|
|
||||||
|
git.WaitForExit ();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target_file_path.StartsWith (LocalPath))
|
||||||
|
new Thread (() => OnFileActivity (null)).Start ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -218,9 +218,11 @@ namespace SparkleLib {
|
||||||
if (IsBuffering)
|
if (IsBuffering)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (string exclude_path in ExcludePaths) {
|
if (args != null) {
|
||||||
if (args.FullPath.Contains (exclude_path))
|
foreach (string exclude_path in ExcludePaths) {
|
||||||
return;
|
if (args.FullPath.Contains (exclude_path))
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (this.buffer_lock) {
|
lock (this.buffer_lock) {
|
||||||
|
|
|
@ -252,10 +252,13 @@ namespace SparkleShare {
|
||||||
PreventsApplicationTerminationWhenModal = false
|
PreventsApplicationTerminationWhenModal = false
|
||||||
};
|
};
|
||||||
|
|
||||||
if ((NSPanelButtonType) panel.RunModal ()== NSPanelButtonType.Ok)
|
if ((NSPanelButtonType) panel.RunModal ()== NSPanelButtonType.Ok) {
|
||||||
Controller.SaveDialogCompleted ("f");
|
string target_file_path = Path.Combine (panel.DirectoryUrl.RelativePath, panel.NameFieldStringValue);
|
||||||
else
|
Controller.SaveDialogCompleted (target_file_path);
|
||||||
|
|
||||||
|
} else {
|
||||||
Controller.SaveDialogCancelled ();
|
Controller.SaveDialogCancelled ();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -253,6 +253,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
|
|
||||||
} else if (url.StartsWith ("history://")) {
|
} else if (url.StartsWith ("history://")) {
|
||||||
|
UpdateSizeInfoEvent ("…", "…");
|
||||||
|
|
||||||
string html = "";
|
string html = "";
|
||||||
string folder = url.Replace ("history://", "").Split ("/".ToCharArray ()) [0];
|
string folder = url.Replace ("history://", "").Split ("/".ToCharArray ()) [0];
|
||||||
string path = url.Replace ("history://" + folder + "/", "");
|
string path = url.Replace ("history://" + folder + "/", "");
|
||||||
|
@ -305,7 +307,6 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UpdateContentEvent (Program.Controller.EventLogHTML.Replace ("<!-- $event-log-content -->", html));
|
UpdateContentEvent (Program.Controller.EventLogHTML.Replace ("<!-- $event-log-content -->", html));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,6 +324,7 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.restore_revision_info = null;
|
this.restore_revision_info = null;
|
||||||
|
Program.Controller.OpenFolder (Path.GetDirectoryName (target_file_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue