Exemplo n.º 1
0
        public static MetadataNode Load(BlobStore blobs, byte[] hash, MetadataNode?parent = null)
        {
            var curmn = new MetadataNode();

            Dictionary <string, byte[]> savedobjects = BinaryEncoding.dict_decode(blobs.RetrieveData(hash));
            FileMetadata dirmetadata = FileMetadata.deserialize(savedobjects["DirMetadata-v1"]);

            curmn.DirMetadata = dirmetadata;
            ConcurrentDictionary <string, FileMetadata> files = new ConcurrentDictionary <string, FileMetadata>();
            var encodedFiles = BinaryEncoding.enum_decode(savedobjects["Files-v1"]) ?? new List <byte[]?>();

            foreach (var binfm in encodedFiles)
            {
                if (binfm == null)
                {
                    throw new NullReferenceException("Encoded file metadatas cannot be null");
                }
                FileMetadata newfm = FileMetadata.deserialize(binfm);
                files[newfm.FileName] = newfm;
            }
            curmn.Files = files;
            ConcurrentDictionary <string, MetadataNode> directories = new ConcurrentDictionary <string, MetadataNode>();
            var dirs = BinaryEncoding.enum_decode(savedobjects["Directories-v2"]) ?? new List <byte[]?>();

            for (int i = 0; i < dirs.Count; i++)
            {
                var          dir   = dirs[i] ?? throw new NullReferenceException("Encoded directory cannot be null");
                MetadataNode newmn = Load(blobs, dir, curmn);
                directories[newmn.DirMetadata.FileName] = newmn;
            }
            curmn.Parent      = parent;
            curmn.Directories = directories;
            return(curmn);
        }
Exemplo n.º 2
0
        public static MetadataNode Load(BlobStore blobs, byte[] hash, MetadataNode parent = null)
        {
            var curmn = new MetadataNode();

            Dictionary <string, byte[]> savedobjects = BinaryEncoding.dict_decode(blobs.RetrieveData(hash));
            FileMetadata dirmetadata = FileMetadata.deserialize(savedobjects["DirMetadata-v1"]);

            curmn.DirMetadata = dirmetadata;
            ConcurrentDictionary <string, FileMetadata> files = new ConcurrentDictionary <string, FileMetadata>();

            foreach (var binfm in BinaryEncoding.enum_decode(savedobjects["Files-v1"]))
            {
                FileMetadata newfm = FileMetadata.deserialize(binfm);
                files[newfm.FileName] = newfm;
            }
            curmn.Files = files;
            ConcurrentDictionary <string, MetadataNode> directories = new ConcurrentDictionary <string, MetadataNode>();
            var dirs = BinaryEncoding.enum_decode(savedobjects["Directories-v2"]);

            for (int i = 0; i < dirs.Count; i++)
            {
                MetadataNode newmn = Load(blobs, dirs[i], curmn);
                directories[newmn.DirMetadata.FileName] = newmn;
            }
            curmn.Parent      = parent;
            curmn.Directories = directories;
            return(curmn);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Non recursive equality check
 /// </summary>
 public bool NodeEquals(MetadataNode node)
 {
     return(EqualityComparer <FileMetadata> .Default.Equals(DirMetadata, node.DirMetadata) &&
            Directories.Keys.ToHashSet().SetEquals(node.Directories.Keys) &&
            Files.Select(kv => (kv.Key, kv.Value)).ToHashSet().SetEquals(node.Files.Select(kv => (kv.Key, kv.Value))) &&
            Path == node.Path);
 }
Exemplo n.º 4
0
 public MetadataNode(FileMetadata metadata, MetadataNode parent)
 {
     Parent      = parent;
     DirMetadata = metadata;
     Directories = new ConcurrentDictionary <string, MetadataNode>();
     Files       = new ConcurrentDictionary <string, FileMetadata>();
 }
Exemplo n.º 5
0
        public static IDstFSInterop LoadDst(MetadataNode filesystem, BPlusTree <byte[]> datastore, string dstRoot, string password = null)
        {
            VirtualFSInterop virtualFSInterop = new VirtualFSInterop(filesystem, datastore);

            virtualFSInterop.DstRoot = dstRoot;
            if (password != null)
            {
                byte[]    keyfile   = virtualFSInterop.LoadIndexFileAsync(null, IndexFileType.EncryptorKeyFile).Result;
                AesHelper encryptor = AesHelper.CreateFromKeyFile(keyfile, password);
                virtualFSInterop.Encryptor = encryptor;
            }
            return(virtualFSInterop);
        }
Exemplo n.º 6
0
        public static IDstFSInterop InitializeNewDst(MetadataNode filesystem, BPlusTree <byte[]> datastore, string dstRoot, string password = null)
        {
            VirtualFSInterop virtualFSInterop = new VirtualFSInterop(filesystem, datastore);

            virtualFSInterop.DstRoot = dstRoot;
            if (password != null)
            {
                AesHelper encryptor = AesHelper.CreateFromPassword(password);
                byte[]    keyfile   = encryptor.CreateKeyFile();
                virtualFSInterop.StoreIndexFileAsync(null, IndexFileType.EncryptorKeyFile, keyfile).Wait();
                virtualFSInterop.Encryptor = encryptor;
            }
            return(virtualFSInterop);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets a directory relative to this directory, returns null if does not exist.
        /// </summary>
        /// <param name="relpath"></param>
        /// <returns></returns>
        public MetadataNode GetDirectory(string relpath)
        {
            if (relpath.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
            {
                relpath = relpath.Substring(0, relpath.Length - 1);
            }
            if (relpath.StartsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
            {
                relpath = relpath.Substring(1);
            }
            if (relpath == "")
            {
                return(this);
            }
            if (relpath == ".")
            {
                return(this);
            }
            if (relpath == "..")
            {
                return(Parent);
            }
            int slash = relpath.IndexOf(System.IO.Path.DirectorySeparatorChar);

            if (slash != -1)
            {
                string       nextdirname = relpath.Substring(0, slash);
                string       nextpath    = relpath.Substring(slash + 1, relpath.Length - slash - 1);
                MetadataNode nextdir     = GetDirectory(nextdirname);
                if (nextpath == "")
                {
                    return(nextdir);
                }
                if (nextdir == null)
                {
                    return(null);
                }
                return(nextdir.GetDirectory(nextpath));
            }
            else
            {
                if (Directories != null && Directories.ContainsKey(relpath))
                {
                    return(Directories[relpath]);
                }
            }
            return(null);
        }
Exemplo n.º 8
0
        public FileMetadata GetFile(string relpath)
        {
            int slash = relpath.LastIndexOf(System.IO.Path.DirectorySeparatorChar);

            if (slash == -1) // file must exist in "root" assume '\\' before path
            {
                relpath = System.IO.Path.DirectorySeparatorChar + relpath;
                slash   = 0;
            }
            MetadataNode parent = GetDirectory(relpath.Substring(0, slash));

            if (parent != null)
            {
                string name = relpath.Substring(slash + 1, relpath.Length - slash - 1);
                if (parent.Files != null && parent.Files.ContainsKey(name))
                {
                    return(parent.Files[name]);
                }
            }
            return(null);
        }
Exemplo n.º 9
0
 public VirtualFSInterop(MetadataNode filesystem, BPlusTree <byte[]> datastore)
 {
     VirtualFS = filesystem;
     DataStore = datastore;
 }
Exemplo n.º 10
0
 public VirtualFSInterop(MetadataNode filesystem, BPlusTree <byte[]> datastore)
 {
     VirtualFS = filesystem;
     DataStore = datastore;
     DstRoot   = "<<Non dest VFS interop>>";
 }