Ejemplo n.º 1
0
        public VFSFileStream(VFSFile file, BlockParser blockParser, FileSystemOptions options, BlockAllocation blockAllocation, BlockManipulator blockManipulator, Persistence.Persistence persistence)
        {
            _file = file;
            _blockParser = blockParser;
            _options = options;
            _blockAllocation = blockAllocation;
            _blockManipulator = blockManipulator;
            _persistence = persistence;

            _writeBuffer = new byte[_options.BlockSize];
        }
Ejemplo n.º 2
0
 public void TestNameTooLong()
 {
     var f = new VFSFile("0123456789");
     try
     {
         var o1 = TestHelper.CreateFileSystemOptions("");
         o1.NameLength = f.Name.Length;
         var p1 = new BlockParser(o1);
         p1.NodeToBytes(f);
     }
     catch (VFSException)
     {
         Assert.Fail("Exception unexpected yet");
     }
     var o2 = TestHelper.CreateFileSystemOptions("");
     o2.NameLength = f.Name.Length - 1;
     var p2 = new BlockParser(o2);
     p2.NodeToBytes(f);
 }
Ejemplo n.º 3
0
        public void TestWriteFileBlock()
        {
            var options = TestHelper.CreateFileSystemOptions("");
            var b = new BlockParser(options);

            var f = new VFSFile("αaαaαaαablubα");

            var bb = b.NodeToBytes(f);

            Assert.AreEqual(0x2, bb[0]);
        }
Ejemplo n.º 4
0
        private void ExportFile(VFSFile file, string destination, CallbacksBase exportCallbacks)
        {
            if (exportCallbacks.ShouldAbort()) return;

            EnsureParentDirectoryExists(destination);
            using (var stream = File.OpenWrite(destination))
            {
                using (var reader = DecorateToHostStream(
                    new VFSFileStream(file, _blockParser, _options, _blockAllocation, _blockManipulator, _persistence)))
                {
                    var buffer = new byte[_options.BlockSize];
                    int read;
                    while ((read = reader.Read(buffer, 0, _options.BlockSize)) > 0)
                    {
                        stream.Write(buffer, 0, read);
                    }
                }
            }
            exportCallbacks.CurrentlyProcessed++;
        }
Ejemplo n.º 5
0
        private VFSFile CreateFile(string source, Folder destination, string name)
        {
            var file = new VFSFile(name) { Parent = destination, BlockNumber = _blockAllocation.Allocate() };

            using (var b = new BinaryReader(File.OpenRead(source)))
            using (var w = DecorateToVFSStream(new VFSFileStream(file, _blockParser, _options, _blockAllocation, _blockManipulator, _persistence)))
            {
                byte[] block;
                while ((block = b.ReadBytes(_options.BlockSize)).Length > 0)
                {
                    w.Write(block, 0, block.Length);
                }
            }

            //Note: we could save some metadata too..
            return file;
        }
Ejemplo n.º 6
0
        private void CopyFile(VFSFile fileToCopy, Folder destination, string name, CallbacksBase copyCallbacks)
        {
            if (copyCallbacks.ShouldAbort()) return;

            CheckName(name);

            var newFile = new VFSFile(name)
                           {
                               Parent = destination,
                               BlockNumber = _blockAllocation.Allocate(),
                               LastBlockSize = fileToCopy.LastBlockSize,
                               IndirectNodeNumber = fileToCopy.IndirectNodeNumber,
                               BlocksCount = fileToCopy.BlocksCount,
                               PredecessorBlockNr = fileToCopy.BlockNumber,
                               Version = NextVersion
                           };

            _persistence.Persist(newFile);
            copyCallbacks.CurrentlyProcessed++;

            ArchiveAndReplaceRoot(destination, null, newFile);
        }