Inheritance: SparkleProcess
Example #1
0
        private void ClearCache()
        {
            if (!this.use_git_bin)
            {
                return;
            }

            SparkleGitBin git_bin = new SparkleGitBin(LocalPath, "clear -f");

            git_bin.StartAndWaitForExit();
        }
Example #2
0
        private void ClearCache()
        {
            if (!this.use_git_bin)
                return;

            SparkleGitBin git_bin = new SparkleGitBin (LocalPath, "clear -f");
            git_bin.StartAndWaitForExit ();
        }
Example #3
0
        public override bool SyncUp()
        {
            if (HasLocalChanges) {
                Add ();

                string message = FormatCommitMessage ();
                Commit (message);
            }

            SparkleGit git;

            if (this.use_git_bin) {
                SparkleGitBin git_bin = new SparkleGitBin (LocalPath, "push");
                git_bin.StartAndWaitForExit ();

                // TODO: Progress
            }

            git = new SparkleGit (LocalPath, "push --progress \"" + RemoteUrl + "\" " + this.branch);

            git.StartInfo.RedirectStandardError = true;
            git.Start ();

            double percentage = 1.0;

            while (!git.StandardError.EndOfStream) {
                string line   = git.StandardError.ReadLine ();
                Match match   = this.progress_regex.Match (line);
                double speed  = 0.0;
                double number = 0.0;

                if (match.Success) {
                    number = double.Parse (match.Groups [1].Value);

                    // The pushing progress consists of two stages: the "Compressing
                    // objects" stage which we count as 20% of the total progress, and
                    // the "Writing objects" stage which we count as the last 80%
                    if (line.StartsWith ("Compressing")) {
                        // "Compressing objects" stage
                        number = (number / 100 * 20);

                    } else {
                        // "Writing objects" stage
                        number = (number / 100 * 80 + 20);
                        Match speed_match = this.speed_regex.Match (line);

                        if (speed_match.Success) {
                            speed = double.Parse (speed_match.Groups [1].Value) * 1024;

                            if (speed_match.Groups [2].Value.Equals ("M"))
                                speed = speed * 1024;
                        }
                    }

                } else {
                    SparkleLogger.LogInfo ("Git", Name + " | " + line);

                    if (FindError (line))
                        return false;
                }

                if (number >= percentage) {
                    percentage = number;
                    base.OnProgressChanged (percentage, speed);
                }
            }

            git.WaitForExit ();
            UpdateSizes ();

            if (git.ExitCode == 0) {
                ClearCache ();

                string salt_file_path = new string [] { LocalPath, ".git", "salt" }.Combine ();

                // If the repo is encrypted, create a branch to
                // store the salt 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;

            } else {
                Error = ErrorStatus.HostUnreachable;
                return false;
            }
        }
Example #4
0
        public override bool SyncUp()
        {
            if (HasLocalChanges)
            {
                Add();

                string message = FormatCommitMessage();
                Commit(message);
            }

            SparkleGit git;

            if (this.use_git_bin)
            {
                SparkleGitBin git_bin = new SparkleGitBin(LocalPath, "push");
                git_bin.StartAndWaitForExit();

                // TODO: Progress
            }

            git = new SparkleGit(LocalPath, "push --progress \"" + RemoteUrl + "\" " + this.branch);

            git.StartInfo.RedirectStandardError = true;
            git.Start();

            double percentage = 1.0;

            while (!git.StandardError.EndOfStream)
            {
                string line   = git.StandardError.ReadLine();
                Match  match  = this.progress_regex.Match(line);
                double speed  = 0.0;
                double number = 0.0;

                if (match.Success)
                {
                    number = double.Parse(match.Groups [1].Value);

                    // The pushing progress consists of two stages: the "Compressing
                    // objects" stage which we count as 20% of the total progress, and
                    // the "Writing objects" stage which we count as the last 80%
                    if (line.StartsWith("Compressing"))
                    {
                        // "Compressing objects" stage
                        number = (number / 100 * 20);
                    }
                    else
                    {
                        // "Writing objects" stage
                        number = (number / 100 * 80 + 20);
                        Match speed_match = this.speed_regex.Match(line);

                        if (speed_match.Success)
                        {
                            speed = double.Parse(speed_match.Groups [1].Value) * 1024;

                            if (speed_match.Groups [2].Value.Equals("M"))
                            {
                                speed = speed * 1024;
                            }
                        }
                    }
                }
                else
                {
                    SparkleLogger.LogInfo("Git", Name + " | " + line);

                    if (FindError(line))
                    {
                        return(false);
                    }
                }

                if (number >= percentage)
                {
                    percentage = number;
                    base.OnProgressChanged(percentage, speed);
                }
            }

            git.WaitForExit();
            UpdateSizes();

            if (git.ExitCode == 0)
            {
                ClearCache();

                string salt_file_path = new string [] { LocalPath, ".git", "salt" }.Combine();

                // If the repo is encrypted, create a branch to
                // store the salt 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);
            }
            else
            {
                Error = ErrorStatus.HostUnreachable;
                return(false);
            }
        }
        public override bool SyncUp()
        {
            if (HasLocalChanges) {
                Add ();

                string message = FormatCommitMessage ();
                Commit (message);
            }

            SparkleGit git;

            if (this.use_git_bin) {
                if (this.remote_url_is_set) {
                    git = new SparkleGit (LocalPath, "config remote.origin.url \"" + RemoteUrl + "\"");
                    git.Start ();
                    git.WaitForExit ();

                    this.remote_url_is_set = true;
                }

                SparkleGitBin git_bin = new SparkleGitBin (LocalPath, "push");
                git_bin.Start ();
                git_bin.WaitForExit ();

                // TODO: Progress
            }

            git = new SparkleGit (LocalPath,
                "push --progress " + // Redirects progress stats to standarderror
                "\"" + RemoteUrl + "\" master");

            git.StartInfo.RedirectStandardError = true;
            git.Start ();

            double percentage = 1.0;
            Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);

            while (!git.StandardError.EndOfStream) {
                string line   = git.StandardError.ReadLine ();
                Match match   = progress_regex.Match (line);
                string speed  = "";
                double number = 0.0;

                if (match.Success) {
                    number = double.Parse (match.Groups [1].Value);

                    // The pushing progress consists of two stages: the "Compressing
                    // objects" stage which we count as 20% of the total progress, and
                    // the "Writing objects" stage which we count as the last 80%
                    if (line.StartsWith ("Compressing")) {
                        // "Compressing objects" stage
                        number = (number / 100 * 20);

                    } else {
                        if (line.StartsWith ("ERROR: QUOTA EXCEEDED")) {
                            int quota_limit = int.Parse (line.Substring (21).Trim ());
                            throw new QuotaExceededException ("Quota exceeded", quota_limit);
                        }

                        // "Writing objects" stage
                        number = (number / 100 * 80 + 20);

                        if (line.Contains ("|")) {
                            speed = line.Substring (line.IndexOf ("|") + 1).Trim ();
                            speed = speed.Replace (", done.", "").Trim ();
                            speed = speed.Replace ("i", "");
                            speed = speed.Replace ("KB/s", "ᴋʙ/s");
                            speed = speed.Replace ("MB/s", "ᴍʙ/s");
                        }
                    }

                } else {
                    SparkleHelpers.DebugInfo ("Git", Name + " | " + line);
                }

                if (number >= percentage) {
                    percentage = number;
                    base.OnProgressChanged (percentage, speed);
                }
            }

            git.WaitForExit ();

            UpdateSizes ();
            ChangeSets = GetChangeSets ();

            if (git.ExitCode == 0) {
                ClearCache ();
                return true;

            } else {
                return false;
            }
        }
Example #6
0
        public override bool SyncUp()
        {
            if (HasLocalChanges)
            {
                Add();

                string message = FormatCommitMessage();
                Commit(message);
            }

            SparkleGit git;

            if (this.use_git_bin)
            {
                if (this.remote_url_is_set)
                {
                    git = new SparkleGit(LocalPath, "config remote.origin.url \"" + RemoteUrl + "\"");
                    git.StartAndWaitForExit();

                    this.remote_url_is_set = true;
                }

                SparkleGitBin git_bin = new SparkleGitBin(LocalPath, "push");
                git_bin.StartAndWaitForExit();

                // TODO: Progress
            }

            git = new SparkleGit(LocalPath,
                                 "push --progress " + // Redirects progress stats to standarderror
                                 "\"" + RemoteUrl + "\" master");

            git.StartInfo.RedirectStandardError = true;
            git.Start();

            double percentage     = 1.0;
            Regex  progress_regex = new Regex(@"([0-9]+)%", RegexOptions.Compiled);

            while (!git.StandardError.EndOfStream)
            {
                string line   = git.StandardError.ReadLine();
                Match  match  = progress_regex.Match(line);
                string speed  = "";
                double number = 0.0;

                if (match.Success)
                {
                    number = double.Parse(match.Groups [1].Value);

                    // The pushing progress consists of two stages: the "Compressing
                    // objects" stage which we count as 20% of the total progress, and
                    // the "Writing objects" stage which we count as the last 80%
                    if (line.StartsWith("Compressing"))
                    {
                        // "Compressing objects" stage
                        number = (number / 100 * 20);
                    }
                    else
                    {
                        if (line.StartsWith("ERROR: QUOTA EXCEEDED"))
                        {
                            int quota_limit = int.Parse(line.Substring(21).Trim());
                            throw new QuotaExceededException("Quota exceeded", quota_limit);
                        }

                        // "Writing objects" stage
                        number = (number / 100 * 80 + 20);

                        if (line.Contains("|"))
                        {
                            speed = line.Substring(line.IndexOf("|") + 1).Trim();
                            speed = speed.Replace(", done.", "").Trim();
                            speed = speed.Replace("i", "");
                            speed = speed.Replace("KB/s", "ᴋʙ/s");
                            speed = speed.Replace("MB/s", "ᴍʙ/s");
                        }
                    }
                }
                else
                {
                    SparkleLogger.LogInfo("Git", Name + " | " + line);
                }

                if (number >= percentage)
                {
                    percentage = number;
                    base.OnProgressChanged(percentage, speed);
                }
            }

            git.WaitForExit();
            UpdateSizes();

            if (git.ExitCode == 0)
            {
                ClearCache();
                return(true);
            }
            else
            {
                return(false);
            }
        }