示例#1
0
        private void AddDirectory(string dirName)
        {
            dirName = dirName.TrimVolume();

            if (!dirName.EndsWith("/"))
            {
                dirName += "/";
            }

            if (TarOptions.StatusWriter != null)
            {
                TarOptions.StatusWriter.WriteLine("{0}", dirName);
            }

            HeaderBlock hb = HeaderBlock.CreateOne();

            hb.InsertName(dirName);
            hb.typeflag = 5 + (byte)'0';
            hb.SetSize(0);
            hb.SetChksum();
            byte[] block = serializer.RawSerialize(hb);
            _outfs.Write(block, 0, block.Length);

            String[] filenames = Directory.GetFiles(dirName);
            foreach (String filename in filenames)
            {
                AddFile(filename);
            }

            String[] dirnames = Directory.GetDirectories(dirName);
            foreach (String d in dirnames)
            {
                var a = System.IO.File.GetAttributes(d);
                if ((a & FileAttributes.ReparsePoint) == 0)
                {
                    AddDirectory(d);
                }
                else if (this.TarOptions.FollowSymLinks)
                {
                    AddDirectory(d);
                }
                else
                {
                    AddSymlink(d);
                }
            }
        }
示例#2
0
        private void AddSymlink(string name)
        {
            if (TarOptions.StatusWriter != null)
            {
                TarOptions.StatusWriter.WriteLine("{0}", name);
            }

            HeaderBlock hb = HeaderBlock.CreateOne();

            hb.InsertName(name);
            hb.InsertLinkName(name);
            hb.typeflag = (byte)TarEntryType.SymbolicLink;
            hb.SetSize(0);
            hb.SetChksum();
            byte[] block = serializer.RawSerialize(hb);
            _outfs.Write(block, 0, block.Length);
        }
示例#3
0
        private void AddFile(string fileName)
        {
            var a = System.IO.File.GetAttributes(fileName);

            if ((a & FileAttributes.ReparsePoint) != 0)
            {
                AddSymlink(fileName);
                return;
            }
            if (TarOptions.StatusWriter != null)
            {
                TarOptions.StatusWriter.WriteLine("{0}", fileName);
            }

            HeaderBlock hb = HeaderBlock.CreateOne();

            hb.InsertName(fileName);
            hb.typeflag = (byte)TarEntryType.File;
            FileInfo fi = new FileInfo(fileName);

            hb.SetSize((int)fi.Length);

            hb.SetChksum();
            byte[] block = serializer.RawSerialize(hb);
            _outfs.Write(block, 0, block.Length);

            using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read))
            {
                int n = 0;
                Array.Clear(block, 0, block.Length);
                while ((n = fs.Read(block, 0, block.Length)) > 0)
                {
                    _outfs.Write(block, 0, block.Length);
                    Array.Clear(block, 0, block.Length);
                }
            }
        }