public SparkleFetcherRsync(string server, string remote_folder, string target_folder) : base(server, remote_folder, target_folder) { if (server.EndsWith ("/")) server = server.Substring (0, server.Length - 1); if (!remote_folder.StartsWith ("/")) remote_folder = "/" + remote_folder; remote_folder = remote_folder.Substring (0, (remote_folder.Length - 6)); Uri uri; try { uri = new Uri (server + remote_folder); } catch (UriFormatException) { uri = new Uri ("rsync://" + server + remote_folder); } if (string.IsNullOrEmpty (uri.UserInfo)) { uri = new Uri (uri.Scheme + "://rsync@" + uri.Host + ":" + uri.Port + uri.AbsolutePath); uri = new Uri (uri.ToString ().Replace (":-1", "")); } base.target_folder = target_folder; base.remote_url = uri.ToString(); string tmpPort = uri.Port.ToString(); string tmpRsyncRemoteUrl = uri.UserInfo + "@" + uri.Host + ":" + uri.AbsolutePath; this.rsync = new SparkleRsync(SparkleConfig.DefaultConfig.TmpPath,"--version") { port = tmpPort, rsync_remote_url = tmpRsyncRemoteUrl }; }
public override bool Fetch() { SparkleRsync rsync = new SparkleRsync (SparkleConfig.DefaultConfig.TmpPath, "-e \"ssh -p " + this.rsync.port + "\" " + "-azviP \"" + this.rsync.rsync_remote_url + "\" " + "\"" + base.target_folder + "\""); rsync.Start (); rsync.WaitForExit (); SparkleHelpers.DebugInfo ("Rsync", "Exit code " + rsync.ExitCode.ToString ()); if (rsync.ExitCode != 0) { return false; } else { InstallConfiguration (); InstallExcludeRules (); return true; } }
private string RemoteChanges() { // TODO: Check if there is an equivalent for --itemize which has been // removed because of not being detected SparkleRsync rsync = new SparkleRsync (LocalPath, "--archive --compress --dry-run --partial --delete --exclude-from=.sparkleshare \"" + Url + "\" " + "."); rsync.Start (); rsync.WaitForExit (); string remote_revision = rsync.StandardOutput.ReadToEnd ().TrimEnd (); return remote_revision ; }
private void ResolveConflict() { //some conflict resolution code in python: http://sujitpal.blogspot.com/2009/12/unison-replacement-with-rsync.htm //local changes // TODO: Check if there is an equivalent for --itemize which has been // removed because of not being detected SparkleRsync rsync = new SparkleRsync (LocalPath, "--archive --compress --dry-run --partial --delete --exclude-from=.sparkleshare " + "\"" + Url + "\""); rsync.Start (); rsync.WaitForExit (); string local_changes = rsync.StandardOutput.ReadToEnd ().TrimEnd (); //remote changes // TODO: Check if there is an equivalent for --itemize which has been // removed because of not being detected rsync = new SparkleRsync (LocalPath, "--archive --compress --dry-run --partial --delete --exclude-from=.sparkleshare \"" + Url + "\" " + "."); rsync.Start (); rsync.WaitForExit (); string remote_changes = rsync.StandardOutput.ReadToEnd ().TrimEnd (); //need to compare local_changes with remote_changes to check for overlapping files //look at each overlap and see if they are both modified or: //it the local version has been modified, but the server version was removed //and the opposite, where the local version was deleted and the server version was modified //for simple conflicts where the local and server version were both modified //(need to look at timestamps and rsync log since rsync doesn't have a record of modifications) //just apply a suffix (usernames + timestamps) and keep both files //**DELETED FILES** //there is a complexity that arrises when a file is locally modified by one person after being deleted on the server by someone else //since there is no record of if the file was actually locally modified other than the timestamp //might need to compare the modification-timestamp of the local files to the time of last sync (from the log) //for files that are deleted on the server, then if they were modified copy them to the server with a suffix //otherwise delete them locally... //the rsync dry run will report which files are scheduled for deletion in the upcoming sync //the output from the rsync command can inform if the file was deleted //see: http://samba.anu.edu.au/ftp/rsync/rsync.html section on itemize changes // Append a timestamp to local version string timestamp = DateTime.Now.ToString ("HH:mm MMM d"); }
//the option --inplace is good if your server uses block level snapshots (ex. ZFS) but it increases network throughput //maybe make a config file option? //Windows<->Solaris will want to use -A to preserve ACLs //--delete will delete files on the server that were deleted locally (need to make sure that the server copy wasnt modified...) public override bool SyncUp() { //delete can cause problems -- see comments in the conflict code // TODO: Check if there is an equivalent for --itemize which has been // removed because of not being detected SparkleRsync rsync = new SparkleRsync (LocalPath, "--archive --compress --partial --delete --delete-during --exclude-from=.sparkleshare --log-file=.rsynclog . " + "\"" + Url + "\""); rsync.Start (); rsync.WaitForExit (); if (rsync.ExitCode == 0) return true; else return false; }