/// <inheritdoc /> public void Copy(string fileNameFrom, string fileNameTo) { var sourceFileDescriptor = _entryDescriptorRepository.Find(fileNameFrom).Value; var sourceDataCursor = new Cursor(sourceFileDescriptor.DataOffset, SeekOrigin.Begin); var destinationParentName = fileNameTo.GetParentFullName(); var destinationParentDescriptor = _entryDescriptorRepository.Find(destinationParentName).Value; var destinationPlaceholder = new PlaceholderFileEntry(fileNameTo, destinationParentDescriptor.Id, sourceFileDescriptor.DataLength); // Create empty file of given size with no data CreateInternal(destinationPlaceholder, destinationDataCursor => { // Copy data from source file data origin to destination _connection.PerformCopy(sourceDataCursor, destinationDataCursor, sourceFileDescriptor.DataLength); }); }
/// <inheritdoc/> public DirectoryEntry Find(string fullPath) { var descriptor = _entryDescriptorRepository.Find(fullPath); return(new DirectoryEntry( descriptor.Value.Id, descriptor.Value.Name, descriptor.Value.ParentId)); }
/// <inheritdoc /> public void Delete(string entryName) { // 1. Find last descriptor var filesystemDescriptor = _filesystemDescriptorAccessor.Value; var lastDescriptorCursor = new Cursor( -FilesystemDescriptor.BytesTotal - (filesystemDescriptor.EntryDescriptorsCount * filesystemDescriptor.EntryDescriptorLength), SeekOrigin.End); var lastDescriptor = _entryDescriptorRepository.Read(lastDescriptorCursor).Value; // 2. Find current descriptor var descriptorItem = _entryDescriptorRepository.Find(entryName); var cursor = descriptorItem.Cursor; // 3. Save last descriptor in new empty space (perform swap with last) _entryDescriptorRepository.Write(new StorageItem <EntryDescriptor>(lastDescriptor, cursor)); // 4. Decrease count of descriptors IncreaseEntriesCount(-1); }