* Only except BFS partitions as target volumes. Installer does not initialize

partitions by itself. When it does, this check can be removed again... for
  now DriveSetup is to be used and so there is no code duplication.
* Check if the target volume is non-empty and present an appropriate warning.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30382 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2009-04-24 16:28:38 +00:00
parent c2c3d40c7b
commit 3bbb00b48d
2 changed files with 68 additions and 7 deletions

View File

@ -128,7 +128,9 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
BPartition *partition;
BVolume targetVolume;
status_t err = B_OK;
int32 entries = 0;
entry_ref testRef;
fControl->Reset();
PartitionMenuItem *targetItem = (PartitionMenuItem *)targetMenu->FindMarked();
@ -210,17 +212,69 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
// check not installing on boot volume
if ((strncmp(BOOT_PATH, targetDirectory.Path(), strlen(BOOT_PATH)) == 0)
&& ((new BAlert("", "Are you sure you want to install onto the "
"current boot disk? The installer will have to reboot your "
"current boot disk? The Installer will have to reboot your "
"machine if you proceed.", "OK", "Cancel", 0,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) {
SetStatusMessage("Installation stopped.");
goto error;
}
targetDir.SetTo(targetDirectory.Path());
// check target volume not empty
// NOTE: It's ok if exactly this path exists: home/Desktop/Trash
// and nothing else.
while (targetDir.GetNextRef(&testRef) == B_OK) {
if (strcmp(testRef.name, "home") == 0) {
BDirectory homeDir(&testRef);
while (homeDir.GetNextRef(&testRef) == B_OK) {
if (strcmp(testRef.name, "Desktop") == 0) {
BDirectory desktopDir(&testRef);
while (desktopDir.GetNextRef(&testRef) == B_OK) {
if (strcmp(testRef.name, "Trash") == 0) {
BDirectory trashDir(&testRef);
while (trashDir.GetNextRef(&testRef) == B_OK) {
// Something in the Trash
entries++;
break;
}
} else {
// Something besides Trash
entries++;
}
if (entries > 0)
break;
}
} else {
// Something besides Desktop
entries++;
}
if (entries > 0)
break;
}
} else {
// Something besides home
entries++;
}
if (entries > 0)
break;
}
if (entries != 0
&& ((new BAlert("", "The target volume is not empty. Are you sure you "
"want to install anyways?", "Install Anyways", "Cancel", 0,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) {
err = B_CANCELED;
goto error;
}
LaunchInitScript(targetDirectory);
// copy source volume
targetDir.SetTo(targetDirectory.Path());
targetDir.Rewind();
srcDir.SetTo(srcDirectory.Path());
err = CopyFolder(srcDir, targetDir);
@ -296,11 +350,11 @@ CopyEngine::ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu)
BDiskDevice device;
BPartition *partition = NULL;
printf("ScanDisksPartitions partitions begin\n");
printf("\nScanDisksPartitions source partitions begin\n");
SourceVisitor srcVisitor(srcMenu);
fDDRoster.VisitEachMountedPartition(&srcVisitor, &device, &partition);
printf("ScanDisksPartitions partitions begin\n");
printf("\nScanDisksPartitions target partitions begin\n");
TargetVisitor targetVisitor(targetMenu);
fDDRoster.VisitEachPartition(&targetVisitor, &device, &partition);
}
@ -344,7 +398,7 @@ SourceVisitor::Visit(BPartition *partition, int32 level)
printf("SourceVisitor::Visit(BPartition *) : %s\n", path.Path());
printf("SourceVisitor::Visit(BPartition *) : %s\n", partition->ContentName());
if (!partition->ContentType())
if (partition->ContentType() == NULL)
return false;
bool isBootPartition = false;
@ -401,6 +455,13 @@ TargetVisitor::Visit(BPartition *partition, int32 level)
printf("TargetVisitor::Visit(BPartition *) : %s\n", path.Path());
printf("TargetVisitor::Visit(BPartition *) : %s\n", partition->ContentName());
if (partition->ContentType() == NULL
|| strcmp(partition->ContentType(), kPartitionTypeBFS) != 0) {
// Except only valid BFS partitions
printf(" not BFS\n");
return false;
}
if (partition->ContentSize() < 20 * 1024 * 1024) {
// reject partitions which are too small anyways
// TODO: Could depend on the source size

View File

@ -447,8 +447,8 @@ InstallerWindow::QuitRequested()
"Installer window.", "OK"))->Go();
return false;
}
be_app->PostMessage(B_QUIT_REQUESTED);
fCopyEngine->PostMessage(B_QUIT_REQUESTED);
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
}