public void Smudge() { var args = Parse( minArgs: 0, maxArgs: 1, switchInfo: new[] { GitCmdSwitchInfo.Blank } ); var pointerStream = Console.OpenStandardInput(); if (args.Length == 1) { pointerStream = File.OpenRead(args[0]); } using (var sr = new StreamReader(pointerStream)) { var pointer = LfxPointer.Parse(sr); var cache = LfxBlobCache.Create(); var blob = cache.Load(pointer); using (var contentStream = blob.OpenRead()) contentStream.CopyTo(Console.OpenStandardOutput()); } }
public void Cache() { var cache = LfxBlobCache.Create(); foreach (var blob in cache) { Console.WriteLine($"{blob.Hash}"); } }
public void Reset() { var args = Parse( minArgs: 0, maxArgs: 1, switchInfo: GitCmdSwitchInfo.Create( LfxCmdSwitches.List, LfxCmdSwitches.L, LfxCmdSwitches.Cached, LfxCmdSwitches.C, LfxCmdSwitches.Others, LfxCmdSwitches.O, LfxCmdSwitches.Quite, LfxCmdSwitches.Q, LfxCmdSwitches.Force, LfxCmdSwitches.F ) ); var lfxFiles = GetFiles(args, content: true); var listOnly = args.IsSet(LfxCmdSwitches.L, LfxCmdSwitches.List); if (listOnly) { foreach (var file in lfxFiles) { Log($"{file}"); } return; } var force = args.IsSet(LfxCmdSwitches.F, LfxCmdSwitches.Force); var cache = LfxBlobCache.Create(); Batch(args, lfxFiles, file => { var path = file.Path; if (force) { var mask = ~(FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System); File.SetAttributes( path: path, fileAttributes: File.GetAttributes(path) & mask ); } if (!LfxPointer.CanLoad(path)) { var blob = cache.Save(path); var pointer = LfxPointer.Create(path, blob.Hash); pointer.Save(path); } }); }
public void Clear() { ParseNoArgsAndNoSwitches(); var cache = LfxBlobCache.Create(); while (cache != null) { var store = cache.Store; Console.WriteLine($"Removing {store.Directory}"); store.Clear(); cache = cache.Parent; } }
public void Env() { ParseNoArgsAndNoSwitches(); var config = LfxConfig.Load(); var gitConfig = config.GitConfig; Log($"Enlistment={gitConfig.EnlistmentDirectory}"); Log($"GitDirectory={gitConfig.GitDirectory}"); Log(); var cache = LfxBlobCache.Create(); var level = 1; Log("BlobCache:"); while (cache != null) { var store = cache.Store; Log($" L{level++}={store.Directory} (count={store.Count}, size={store.Size.ToString("N0")})"); cache = cache.Parent; } Log(); Log("Config:"); Log($" {LfxConfigFile.CleanFilterId}={gitConfig[LfxConfigFile.CleanFilterId]}"); Log($" {LfxConfigFile.SmudgeFilterId}={gitConfig[LfxConfigFile.SmudgeFilterId]}"); Log($" {LfxConfigFile.TypeId}={gitConfig[LfxConfigFile.TypeId]}"); Log($" {LfxConfigFile.UrlId}={gitConfig[LfxConfigFile.UrlId]}"); Log($" {LfxConfigFile.PatternId}={gitConfig[LfxConfigFile.PatternId]}"); Log($" {LfxConfigFile.HintId}={gitConfig[LfxConfigFile.HintId]}"); Log(); Log("Config Files:"); var configLevel = config; while (configLevel != null) { var configFile = configLevel.ConfigFile; Log($" {configFile}"); foreach (var value in configFile) { Log($" {value}"); } configLevel = configLevel.Parent; } Log(); }
public void Checkout() { var args = Parse( minArgs: 0, maxArgs: 1, switchInfo: GitCmdSwitchInfo.Create( LfxCmdSwitches.List, LfxCmdSwitches.L, LfxCmdSwitches.Cached, LfxCmdSwitches.C, LfxCmdSwitches.Others, LfxCmdSwitches.O, LfxCmdSwitches.Quite, LfxCmdSwitches.Q ) ); var lfxFiles = GetFiles(args, pointer: true); var listOnly = args.IsSet(LfxCmdSwitches.L, LfxCmdSwitches.List); if (listOnly) { foreach (var file in lfxFiles) { Log($"{file}"); } return; } var cache = LfxBlobCache.Create(); Batch(args, lfxFiles, async file => { LfxPointer pointer; if (!LfxPointer.TryLoad(file.Path, out pointer)) { return; } var blob = await cache.LoadAsync(pointer); blob.Save(file.Path); }); }
public static void DownloadTest(LfxPointer pointer, LfxPointer altPointer) { using (var storeDir = new TempDir()) { // create cache with storeDir var cache = new LfxBlobCache(storeDir); using (var file = new TempFile()) { // create file File.WriteAllText(file, LfxHashTest.Content); // add file to cache var blob = cache.Load(pointer); var count = cache.Store.Count; Assert.IsTrue(count > 0); var hash = blob.Hash; Assert.IsTrue(cache.Contains(blob)); // get file from cache LfxBlob rtBlob; Assert.IsTrue(cache.TryGet(hash, out rtBlob)); Assert.AreEqual(blob, rtBlob); using (var altDir = new TempDir()) { // create alternate cache, promote file var altCache = new LfxBlobCache(altDir, cache); Assert.AreEqual(cache, altCache.Parent); // promote LfxBlob altBlob; Assert.IsTrue(altCache.TryGet(hash, out altBlob)); Assert.AreNotEqual(altBlob, blob); Assert.AreEqual(blob.Hash, altBlob.Hash); } using (var altDir = new TempDir()) { // create alternate cache, promote file var altCache = new LfxBlobCache(altDir, cache); // promote Assert.IsTrue(altCache.Promote(hash)); } using (var altDir = new TempDir()) { // create alternate cache, promote file var altCache = new LfxBlobCache(altDir, cache); // promote all files; altCache.ToArray(); // promote LfxBlob altBlob; Assert.IsTrue(altCache.TryGet(hash, out altBlob)); Assert.IsTrue(altCache.Contains(altBlob)); Assert.IsFalse(altCache.Contains(blob)); } using (var altDir = new TempDir()) { // create alternate cache, promote file var altCache = new LfxBlobCache(altDir, cache); // ask child cache to download same file as parent var altBlob = altCache.Load(pointer); // child should contain one blob promoted from parent Assert.AreNotEqual(blob, altBlob); Assert.AreEqual(blob.Hash, altBlob.Hash); Assert.AreEqual(count, cache.Store.Count); Assert.AreEqual(1, altCache.Store.Count); // load altPointer; child cache is subset of parent altBlob = altCache.Load(altPointer); Assert.IsTrue(altCache.Store.Count > 1); var altHashes = altCache.Store.Select(o => o.Hash); var parentHashes = cache.Store.Select(o => o.Hash); Assert.IsTrue(!altHashes.Except(parentHashes).Any()); } } } }