private async Task<Errorable<Ref>> persistRef(Ref rf)
        {
            FileInfo tmpFile = system.getTemporaryFile();

            // Write the ref's contents to the temporary file:
            using (var fs = new FileStream(tmpFile.FullName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 16384, true))
                await fs.WriteRawAsync(rf.WriteTo(new StringBuilder()).ToString());

            lock (FileSystem.SystemLock)
            {
                // TODO: would love to see FileInfo.DeleteAsync, DirectoryInfo.CreateAsync, etc.
                FileInfo fi = system.getRefPathByRefName(rf.Name);
                if (fi.Exists) fi.Delete();
                else
                    // Create directory if it doesn't exist:
                    if (!fi.Directory.Exists)
                    {
                        Debug.WriteLine(String.Format("New DIR '{0}'", fi.Directory.FullName));
                        fi.Directory.Create();
                    }

                // Move the temp file to the real file:
                Debug.WriteLine(String.Format("New REF '{0}'", fi.FullName));
                File.Move(tmpFile.FullName, fi.FullName);
            }

            return rf;
        }
 public Task<Errorable<Ref>> PersistRef(Ref rf)
 {
     return persistRef(rf);
     //return Task.FromResult((Errorable<Ref>)rf);
 }
 public Builder(Ref imm)
 {
     this.Name = imm.Name;
     this.CommitID = imm.CommitID;
 }