Beispiel #1
0
        public void ReuseDeletedFileSpace()
        {
            IntArrayList handles = new IntArrayList();

            for (int i = 0; i < 10; ++i)
            {
                int handle;
                using (BinaryWriter file = _bfs.AllocFile(out handle))
                {
                    handles.Add(handle);
                    for (int j = 0; j < 50; ++j)
                    {
                        file.Write(handle.ToString());
                    }
                }
                using (BinaryWriter file = _bfs.AllocFile(out handle))
                {
                    handles.Add(handle);
                    for (int j = 0; j < 200; ++j)
                    {
                        file.Write(handle.ToString());
                    }
                }
            }
            for (int i = 0; i < 10; ++i)
            {
                _bfs.DeleteFile(handles[(i * 2) + 1]);
            }
            _bfs.Dispose();

            long bsfLength = new FileInfo(_bfsFile).Length;

            SetUp();

            // file handles are reused in back order
            for (int i = 10; i > 0; --i)
            {
                int handle;
                using (BinaryWriter file = _bfs.AllocFile(out handle))
                {
                    Assertion.AssertEquals(handles[(i * 2) - 1], handle);
                    for (int j = 0; j < 200; ++j)
                    {
                        file.Write(handle.ToString());
                    }
                }
            }
            _bfs.Dispose();

            Assert.AreEqual(bsfLength, new FileInfo(_bfsFile).Length);
        }
Beispiel #2
0
        public void Delete()
        {
            int handle = Handle;

            if (handle > 0)
            {
                _bfs.Lock();
                try
                {
                    _bfs.DeleteFile(handle);
                }
                finally
                {
                    _bfs.UnLock();
                }
            }
            else
            {
                IOTools.DeleteFile(GetFileName());
            }
        }