public Builder(Tag imm) { this.Name = imm.Name; this.CommitID = imm.CommitID; this.Tagger = imm.Tagger; this.DateTagged = imm.DateTagged; this.Message = imm.Message; }
public async Task<Errorable<Tag>> PersistTag(Tag tg) { await persistTag(tg).ConfigureAwait(continueOnCapturedContext: false); return tg; }
private async Task<Errorable<Tag>> persistTag(Tag tg) { // Write the commit contents to the file: FileInfo tmpFile = system.getTemporaryFile(); using (var fs = new FileStream(tmpFile.FullName, FileMode.CreateNew, FileAccess.Write, FileShare.None)) { await fs.WriteRawAsync(tg.WriteTo(new StringBuilder()).ToString()); } lock (FileSystem.SystemLock) { FileInfo fi = system.getPathByID(tg.ID); // NOTE: if the record already exists we can either error out or overwrite the existing file with contents known to be good in the case the existing file got corrupt. // Let's stick with the self-repair scenario since erroring out doesn't help anyone. if (fi.Exists) { Debug.WriteLine(String.Format("Self-repair scenario: overwriting old TagID {0} with new contents", tg.ID)); fi.Delete(); } // Create directory if it doesn't exist: if (!fi.Directory.Exists) { Debug.WriteLine(String.Format("New DIR '{0}'", fi.Directory.FullName)); fi.Directory.Create(); } Debug.WriteLine(String.Format("New TAG '{0}'", fi.FullName)); File.Move(tmpFile.FullName, fi.FullName); } // Now keep track of the tag by its name: tmpFile = system.getTemporaryFile(); using (var fs = new FileStream(tmpFile.FullName, FileMode.CreateNew, FileAccess.Write, FileShare.None)) { await fs.WriteRawAsync(tg.ID.ToString()); } lock (FileSystem.SystemLock) { FileInfo fiTracker = system.getTagPathByTagName(tg.Name); // Does this tag name exist already? if (fiTracker.Exists) { tmpFile.Delete(); return new TagNameAlreadyExistsError(tg.Name); } // Create directory if it doesn't exist: if (!fiTracker.Directory.Exists) { Debug.WriteLine(String.Format("New DIR '{0}'", fiTracker.Directory.FullName)); fiTracker.Directory.Create(); } Debug.WriteLine(String.Format("New TAG '{0}'", fiTracker.FullName)); File.Move(tmpFile.FullName, fiTracker.FullName); } return tg; }
private void deleteTag(Tag tg) { FileInfo fi = system.getPathByID(tg.ID); lock (FileSystem.SystemLock) { if (fi.Exists) fi.Delete(); } FileInfo fiTracker = system.getTagPathByTagName(tg.Name); lock (FileSystem.SystemLock) { if (fiTracker.Exists) fiTracker.Delete(); } }