Exemplo n.º 1
0
 public Core(ICoreSrcDependencies src, List <ICoreDstDependencies> destinations, ICoreDstDependencies?cache = null)
 {
     SrcDependencies = src;
     if (destinations == null || destinations.Count == 0)
     {
         DestinationAvailable = false;
         if (cache != null)
         {
             DefaultDstDependencies = new List <ICoreDstDependencies>(1)
             {
                 cache
             };
         }
         else
         {
             throw new ArgumentNullException(nameof(cache), "Dst and cache are null, cannot initialize");
         }
     }
     else
     {
         DestinationAvailable   = true;
         DefaultDstDependencies = destinations;
     }
     CacheDependencies = cache;
 }
Exemplo n.º 2
0
        public static void InitializeNew(bool cache, int nonencrypteddsts, int encrypteddsts)
        {
            MetadataNode       vfsroot   = CreateBasicVirtualFS(nonencrypteddsts + encrypteddsts);
            BPlusTree <byte[]> datastore = new(10);
            var vfsisrc = new VirtualFSInterop(vfsroot, datastore);

            List <ICoreDstDependencies> destinations = new();

            for (int i = 0; i < nonencrypteddsts + encrypteddsts; i++)
            {
                IDstFSInterop vfsidst;
                if (i < nonencrypteddsts)
                {
                    vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, Path.Combine("dst", i.ToString()));
                }
                else
                {
                    vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, Path.Combine("dst", i.ToString()), "password");
                }
                destinations.Add(CoreDstDependencies.InitializeNew("test", false, vfsidst, true));
            }

            var vfsicache = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, "cache");
            ICoreSrcDependencies srcdeps = FSCoreSrcDependencies.InitializeNew("test", "src", vfsisrc);

            if (cache)
            {
                ICoreDstDependencies cachedeps = CoreDstDependencies.InitializeNew("test", true, vfsicache, false);
                _ = new Core(srcdeps, destinations, cachedeps);
            }
            else
            {
                _ = new Core(srcdeps, destinations);
            }
        }
Exemplo n.º 3
0
        public static void LoadCore_NewlyInitialized(bool encrypted, bool cache)
        {
            MetadataNode       vfsroot   = CreateBasicVirtualFS(1);
            BPlusTree <byte[]> datastore = new(10);
            var           vfsisrc        = new VirtualFSInterop(vfsroot, datastore);
            IDstFSInterop vfsidst;

            if (encrypted)
            {
                vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, Path.Combine("dst", "1"), "password");
            }
            else
            {
                vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, Path.Combine("dst", "1"));
            }
            var vfsicache = VirtualFSInterop.InitializeNewDst(vfsroot, datastore, "cache");
            ICoreSrcDependencies srcdeps   = FSCoreSrcDependencies.InitializeNew("test", "src", vfsisrc, "cache");
            ICoreDstDependencies dstdeps   = CoreDstDependencies.InitializeNew("test", false, vfsidst, true);
            ICoreDstDependencies?cachedeps = null;

            if (cache)
            {
                cachedeps = CoreDstDependencies.InitializeNew("test", true, vfsicache, false);
            }
            Core core = new(srcdeps, new List <ICoreDstDependencies>()
            {
                dstdeps
            }, cachedeps);

            Assert.IsTrue(core.DefaultDstDependencies.Count == 1);

            vfsisrc = new VirtualFSInterop(vfsroot, datastore);
            if (encrypted)
            {
                vfsidst = VirtualFSInterop.LoadDst(vfsroot, datastore, Path.Combine("dst", "1"), "password");
            }
            else
            {
                vfsidst = VirtualFSInterop.LoadDst(vfsroot, datastore, Path.Combine("dst", "1"));
            }
            vfsicache = VirtualFSInterop.LoadDst(vfsroot, datastore, "cache");
            srcdeps   = FSCoreSrcDependencies.Load("src", vfsisrc);
            dstdeps   = CoreDstDependencies.Load(vfsidst, true);
            cachedeps = null;
            if (cache)
            {
                cachedeps = CoreDstDependencies.Load(vfsicache, false);
            }
            _ = new Core(srcdeps, new List <ICoreDstDependencies>()
            {
                dstdeps
            }, cachedeps);
        }
Exemplo n.º 4
0
 public static string GetBackupSetName(string?bsname, ICoreSrcDependencies srcDependencies)
 {
     if (bsname == null)
     {
         bsname = ReadSetting(srcDependencies, BackupCore.BackupSetting.name);
         if (bsname == null)
         {
             Console.WriteLine("A backup store name must be specified with \"set name <name>\"");
             Console.WriteLine("or the store name must be specified with the -n flag.");
             throw new Exception(); // TODO: more specific exceptions
         }
     }
     return(bsname);
 }
Exemplo n.º 5
0
        /*
         * int Main(string[] args)
         * {
         *  return CommandLine.Parser.Default.ParseArguments<AddOptions, CommitOptions, CloneOptions>(args)
         *    .MapResult(
         *      (AddOptions opts) => RunAddAndReturnExitCode(opts),
         *      (CommitOptions opts) => RunCommitAndReturnExitCode(opts),
         *      (CloneOptions opts) => RunCloneAndReturnExitCode(opts),
         *      errs => 1);
         * }*/

        private static void Initialize(InitOptions opts)
        {
            try
            {
                ICoreSrcDependencies srcdep = FSCoreSrcDependencies.InitializeNew(opts.BSName, cwd, new DiskFSInterop(), opts.Cache);

                if (opts.Cache != null)
                {
                    var cachedep = CoreDstDependencies.InitializeNew(opts.BSName, true, DiskDstFSInterop.InitializeNew(opts.Cache), false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 6
0
                       MetadataNode vfsroot, BPlusTree <byte[]> vfsdatastore) InitializeNewCoreWithStandardFiles(
            int nonencrypteddsts, int encrypteddsts, Random?random = null, bool cache = true, int regFileCount = 100)
        {
            MetadataNode       vfsroot      = CreateBasicVirtualFS(nonencrypteddsts + encrypteddsts);
            BPlusTree <byte[]> vfsdatastore = new(10);
            MetadataNode?      vfsDirectory = vfsroot.GetDirectory("src");

            if (vfsDirectory == null)
            {
                throw new NullReferenceException();
            }

            Dictionary <string, byte[]> verifyfilepaths = AddStandardVFSFiles(vfsDirectory, vfsdatastore, random, regFileCount);
            var vfsisrc = new VirtualFSInterop(vfsroot, vfsdatastore);

            List <ICoreDstDependencies> destinations = new();

            for (int i = 0; i < nonencrypteddsts + encrypteddsts; i++)
            {
                IDstFSInterop vfsidst;
                if (i < nonencrypteddsts)
                {
                    vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, vfsdatastore, Path.Combine("dst", i.ToString()));
                }
                else
                {
                    vfsidst = VirtualFSInterop.InitializeNewDst(vfsroot, vfsdatastore, Path.Combine("dst", i.ToString()), "password");
                }
                ICoreDstDependencies dstdeps = CoreDstDependencies.InitializeNew("test", false, vfsidst, cache);
                destinations.Add(dstdeps);
            }

            var vfsicache = VirtualFSInterop.InitializeNewDst(vfsroot, vfsdatastore, "cache");
            ICoreSrcDependencies srcdeps   = FSCoreSrcDependencies.InitializeNew("test", "src", vfsisrc, "cache");
            ICoreDstDependencies?cachedeps = null;

            if (cache)
            {
                cachedeps = CoreDstDependencies.InitializeNew("test", true, vfsicache, false);
            }
            Core core = new(srcdeps, destinations, cachedeps);

            return(core, verifyfilepaths, vfsroot, vfsdatastore);
        }