Logo Search packages:      
Sourcecode: partitionmanager version File versions  Download package

bool OperationStack::mergeNewOperation ( Operation *&  currentOp,
Operation *&  pushedOp 
) [protected]

Tries to merge an existing NewOperation with a new Operation pushed on the OperationStack

There are several cases what might need to be done:

  1. An existing operation created a Partition that is now being deleted: In this case, just remove the corresponding NewOperation from the OperationStack.

  2. An existing Operation created a Partition that is now being moved or resized. In this case, remove the original NewOperation and create a new NewOperation with updated start and end sectors. This new NewOperation is appended to the OperationStack.

  3. An existing NewOperation created a Partition that is now being copied. We're not copying but instead creating another new Partition in its place.

  4. The label for a new Partition's FileSystem is modified: Modify in NewOperation and forget it.

  5. File system is changed for a new Partition: Modify in NewOperation and forget it.

Parameters:
currentOp the Operation already on the stack to try to merge with
pushedOp the newly pushed Operation
Returns:
true if the OperationStack has been modified in a way that requires merging to stop

Definition at line 84 of file operationstack.cpp.

References FileSystemFactory::cloneWithNewType(), CopyOperation::copiedPartition(), DeleteOperation::deletedPartition(), Partition::fileSystem(), FileSystem::firstSector(), Partition::firstSector(), SetFileSystemLabelOperation::labeledPartition(), FileSystem::lastSector(), Partition::lastSector(), CreateFileSystemOperation::newFileSystem(), ResizeOperation::newFirstSector(), SetFileSystemLabelOperation::newLabel(), ResizeOperation::newLastSector(), NewOperation::newPartition(), operations(), CreateFileSystemOperation::partition(), ResizeOperation::partition(), Partition::setFileSystem(), FileSystem::setFirstSector(), Partition::setFirstSector(), FileSystem::setLabel(), SetFileSystemLabelJob::setLabel(), NewOperation::setLabelJob(), FileSystem::setLastSector(), Partition::setLastSector(), CopyOperation::sourcePartition(), CopyOperation::targetDevice(), NewOperation::targetDevice(), FileSystem::type(), and NewOperation::undo().

Referenced by push().

{
      NewOperation* newOp = dynamic_cast<NewOperation*>(currentOp);

      if (newOp == NULL)
            return false;

      DeleteOperation* pushedDeleteOp = dynamic_cast<DeleteOperation*>(pushedOp);
      ResizeOperation* pushedResizeOp = dynamic_cast<ResizeOperation*>(pushedOp);
      CopyOperation* pushedCopyOp = dynamic_cast<CopyOperation*>(pushedOp);
      SetFileSystemLabelOperation* pushedLabelOp = dynamic_cast<SetFileSystemLabelOperation*>(pushedOp);
      CreateFileSystemOperation* pushedCreateFileSystemOp = dynamic_cast<CreateFileSystemOperation*>(pushedOp);

      // -- 1 --
      if (pushedDeleteOp && &newOp->newPartition() == &pushedDeleteOp->deletedPartition())
      {
            log() << i18nc("@info/plain", "Deleting a partition just created: Undoing the operation to create the partition.");

            delete pushedOp;
            pushedOp = NULL;

            newOp->undo();
            delete operations().takeAt(operations().indexOf(newOp));

            return true;
      }

      // -- 2 --
      if (pushedResizeOp && &newOp->newPartition() == &pushedResizeOp->partition())
      {
            log() << i18nc("@info/plain", "Resizing a partition just created: Updating start and end in existing operation.");

            Partition* newPartition = new Partition(newOp->newPartition());
            newPartition->setFirstSector(pushedResizeOp->newFirstSector());
            newPartition->fileSystem().setFirstSector(pushedResizeOp->newFirstSector());
            newPartition->setLastSector(pushedResizeOp->newLastSector());
            newPartition->fileSystem().setLastSector(pushedResizeOp->newLastSector());

            NewOperation* revisedNewOp = new NewOperation(newOp->targetDevice(), newPartition);
            delete pushedOp;
            pushedOp = revisedNewOp;

            newOp->undo();
            delete operations().takeAt(operations().indexOf(newOp));

            return true;
      }

      // -- 3 --
      if (pushedCopyOp && &newOp->newPartition() == &pushedCopyOp->sourcePartition())
      {
            log() << i18nc("@info/plain", "Copying a new partition: Creating a new partition instead.");

            Partition* newPartition = new Partition(newOp->newPartition());
            newPartition->setFirstSector(pushedCopyOp->copiedPartition().firstSector());
            newPartition->fileSystem().setFirstSector(pushedCopyOp->copiedPartition().fileSystem().firstSector());
            newPartition->setLastSector(pushedCopyOp->copiedPartition().lastSector());
            newPartition->fileSystem().setLastSector(pushedCopyOp->copiedPartition().fileSystem().lastSector());

            NewOperation* revisedNewOp = new NewOperation(pushedCopyOp->targetDevice(), newPartition);
            delete pushedOp;
            pushedOp = revisedNewOp;

            return true;
      }

      // -- 4 --
      if (pushedLabelOp && &newOp->newPartition() == &pushedLabelOp->labeledPartition())
      {
            log() << i18nc("@info/plain", "Changing label for a new partition: No new operation required.");

            newOp->setLabelJob()->setLabel(pushedLabelOp->newLabel());
            newOp->newPartition().fileSystem().setLabel(pushedLabelOp->newLabel());

            delete pushedOp;
            pushedOp = NULL;

            return true;
      }

      // -- 5 --
      if (pushedCreateFileSystemOp && &newOp->newPartition() == &pushedCreateFileSystemOp->partition())
      {
            log() << i18nc("@info/plain", "Changing file system for a new partition: No new operation required.");

            FileSystem* oldFs = &newOp->newPartition().fileSystem();

            newOp->newPartition().setFileSystem(FileSystemFactory::cloneWithNewType(pushedCreateFileSystemOp->newFileSystem()->type(), *oldFs));

            delete oldFs;
            oldFs = NULL;

            delete pushedOp;
            pushedOp = NULL;

            return true;
      }

      return false;
}


Generated by  Doxygen 1.6.0   Back to index