Esempio n. 1
0
        private static void DumpContents(string outPath, Zpl.ZfsItem item)
        {
            Console.WriteLine(item.FullPath);
            var dir  = item as Zpl.ZfsDirectory;
            var file = item as Zpl.ZfsFile;

            var dest = Path.Combine(outPath, item.FullPath.Substring(1));

            if (file != null)
            {
                File.WriteAllBytes(dest, file.GetContents());
            }

            if (dir == null)
            {
                return;
            }
            if (!Directory.Exists(dest))
            {
                Directory.CreateDirectory(dest);
            }
            foreach (var d in dir.GetChildren())
            {
                DumpContents(outPath, d);
            }
        }
Esempio n. 2
0
        void loadItems(Zpl.ZfsItem root)
        {
            var path = root.FullPath.Replace('/', '\\');

            if (mItems.ContainsKey(path))
            {
                return;
            }

            if (!FilterItem(root))
            {
                return;
            }

            mItems.Add(path, root);
            mRevItems.Add(root, path);

            if (root is Zpl.ZfsDirectory)
            {
                foreach (var f in ((Zpl.ZfsDirectory)root).GetChildren())
                {
                    loadItems(f);
                }
            }
        }
Esempio n. 3
0
        static void printContent(string namePrefix, Zpl.ZfsItem item)
        {
            //Console.WriteLine(namePrefix + item.FullPath);
            var dir  = item as Zpl.ZfsDirectory;
            var file = item as Zpl.ZfsFile;

            if (file != null)
            {
                int    length = (int)file.Length;
                byte[] bytes  = ArrayPool <byte> .Shared.Rent(length);

                file.GetContents(new Span <byte>(bytes, 0, length), 0);
                ArrayPool <byte> .Shared.Return(bytes);
            }

            if (dir == null)
            {
                return;
            }
            foreach (var d in dir.GetChildren())
            {
                printContent(namePrefix, d);
            }
        }
Esempio n. 4
0
        private static void SetAttributes(Zpl.ZfsItem item, FileInformation finfo)
        {
            if (item is Zpl.ZfsDirectory)
            {
                finfo.Attributes = FileAttributes.Directory;
            }
            else if (item is Zpl.ZfsFile)
            {
                finfo.Attributes = FileAttributes.Normal;
            }
            else
            {
                throw new NotSupportedException();
            }

            finfo.LastAccessTime = item.ATIME;
            finfo.LastWriteTime  = item.MTIME;
            finfo.CreationTime   = item.CTIME;
            if (item is Zpl.ZfsFile)
            {
                var zplFile = (Zpl.ZfsFile)item;
                finfo.Length = zplFile.Length;
            }
        }
Esempio n. 5
0
 static bool FilterItem(Zpl.ZfsItem item)
 {
     return(item is Zpl.ZfsDirectory || (item is Zpl.ZfsFile && ((Zpl.ZfsFile)item).Type == ZfsItemType.S_IFREG));
 }