code style update
now mount the target partition before copying git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21113 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -16,11 +16,15 @@
|
||||
#include <String.h>
|
||||
#include <VolumeRoster.h>
|
||||
|
||||
//#define COPY_TRACE
|
||||
#define COPY_TRACE
|
||||
#ifdef COPY_TRACE
|
||||
#define CALLED() printf("CALLED %s\n",__PRETTY_FUNCTION__)
|
||||
#define ERR2(x, y...) fprintf(stderr, "CopyEngine: "x" %s\n", y, strerror(err))
|
||||
#define ERR(x) fprintf(stderr, "CopyEngine: "x" %s\n", strerror(err))
|
||||
#else
|
||||
#define CALLED()
|
||||
#define ERR(x)
|
||||
#define ERR2(x, y...)
|
||||
#endif
|
||||
|
||||
const char BOOT_PATH[] = "/boot";
|
||||
@@ -67,7 +71,9 @@ CopyEngine::MessageReceived(BMessage*msg)
|
||||
CALLED();
|
||||
switch (msg->what) {
|
||||
case ENGINE_START:
|
||||
Start(fWindow->GetSourceMenu(), fWindow->GetTargetMenu());
|
||||
status_t err = Start(fWindow->GetSourceMenu(), fWindow->GetTargetMenu());
|
||||
if (err != B_OK)
|
||||
ERR("Start failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -110,15 +116,16 @@ CopyEngine::LaunchFinishScript(BPath &path)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
status_t
|
||||
CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
|
||||
{
|
||||
CALLED();
|
||||
status_t err = B_OK;
|
||||
PartitionMenuItem *targetItem = (PartitionMenuItem *)targetMenu->FindMarked();
|
||||
PartitionMenuItem *srcItem = (PartitionMenuItem *)srcMenu->FindMarked();
|
||||
if (!srcItem || !targetItem) {
|
||||
fprintf(stderr, "bad menu items\n");
|
||||
return;
|
||||
ERR("bad menu items\n");
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
// check if target is initialized
|
||||
@@ -130,40 +137,66 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
|
||||
BVolume targetVolume;
|
||||
|
||||
if (fDDRoster.GetPartitionWithID(targetItem->ID(), &device, &partition) == B_OK) {
|
||||
if (partition->GetVolume(&targetVolume)!=B_OK)
|
||||
return;
|
||||
if (partition->GetMountPoint(&targetDirectory)!=B_OK)
|
||||
return;
|
||||
if (!partition->IsMounted()) {
|
||||
if ((err = partition->Mount()) < B_OK) {
|
||||
SetStatusMessage("The disk can't be mounted. Please choose a different disk.");
|
||||
ERR("BPartition::Mount");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
if ((err = partition->GetVolume(&targetVolume)) != B_OK) {
|
||||
ERR("BPartition::GetVolume");
|
||||
return err;
|
||||
}
|
||||
if ((err = partition->GetMountPoint(&targetDirectory)) != B_OK) {
|
||||
ERR("BPartition::GetMountPoint");
|
||||
return err;
|
||||
}
|
||||
} else if (fDDRoster.GetDeviceWithID(targetItem->ID(), &device) == B_OK) {
|
||||
if (device.GetVolume(&targetVolume)!=B_OK)
|
||||
return;
|
||||
if (device.GetMountPoint(&targetDirectory)!=B_OK)
|
||||
return;
|
||||
if (!device.IsMounted()) {
|
||||
if ((err = device.Mount()) < B_OK) {
|
||||
SetStatusMessage("The disk can't be mounted. Please choose a different disk.");
|
||||
ERR("BDiskDevice::Mount");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
if ((err = device.GetVolume(&targetVolume)) != B_OK) {
|
||||
ERR("BDiskDevice::GetVolume");
|
||||
return err;
|
||||
}
|
||||
if ((err = device.GetMountPoint(&targetDirectory)) != B_OK) {
|
||||
ERR("BDiskDevice::GetMountPoint");
|
||||
return err;
|
||||
}
|
||||
} else
|
||||
return; // shouldn't happen
|
||||
return B_ERROR; // shouldn't happen
|
||||
|
||||
// check if target has enough space
|
||||
if ((fSpaceRequired > 0 && targetVolume.FreeBytes() < fSpaceRequired)
|
||||
&& ((new BAlert("", "The destination disk may not have enough space. Try choosing a different disk or \
|
||||
choose to not install optional items.", "Try installing anyway", "Cancel", 0,
|
||||
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) {
|
||||
return;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
BPath srcDirectory;
|
||||
if (fDDRoster.GetPartitionWithID(srcItem->ID(), &device, &partition) == B_OK) {
|
||||
if (partition->GetMountPoint(&srcDirectory)!=B_OK)
|
||||
return;
|
||||
if ((err = partition->GetMountPoint(&srcDirectory)) != B_OK) {
|
||||
ERR("BPartition::GetMountPoint");
|
||||
return err;
|
||||
}
|
||||
} else if (fDDRoster.GetDeviceWithID(srcItem->ID(), &device) == B_OK) {
|
||||
if (device.GetMountPoint(&srcDirectory)!=B_OK)
|
||||
return;
|
||||
if ((err = device.GetMountPoint(&srcDirectory)) != B_OK) {
|
||||
ERR("BDiskDevice::GetMountPoint");
|
||||
return err;
|
||||
}
|
||||
} else
|
||||
return; // shouldn't happen
|
||||
return B_ERROR; // shouldn't happen
|
||||
|
||||
// check not installing on itself
|
||||
if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) {
|
||||
SetStatusMessage("You can't install the contents of a disk onto itself. Please choose a different disk.");
|
||||
return;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// check not installing on boot volume
|
||||
@@ -172,7 +205,7 @@ choose to not install optional items.", "Try installing anyway", "Cancel", 0,
|
||||
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.");
|
||||
return;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
LaunchInitScript(targetDirectory);
|
||||
@@ -206,7 +239,7 @@ void
|
||||
CopyEngine::CopyFolder(BDirectory &srcDir, BDirectory &targetDir)
|
||||
{
|
||||
BEntry entry;
|
||||
status_t status;
|
||||
status_t err;
|
||||
while (srcDir.GetNextEntry(&entry) == B_OK) {
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
entry.GetName(name);
|
||||
@@ -214,11 +247,11 @@ CopyEngine::CopyFolder(BDirectory &srcDir, BDirectory &targetDir)
|
||||
continue;
|
||||
|
||||
Undo undo;
|
||||
status = FSCopyFolder(&entry, &targetDir, fControl, NULL, false, undo);
|
||||
if (status != B_OK) {
|
||||
err = FSCopyFolder(&entry, &targetDir, fControl, NULL, false, undo);
|
||||
if (err != B_OK) {
|
||||
BPath path;
|
||||
entry.GetPath(&path);
|
||||
fprintf(stderr, "error while copying %s : %s\n", path.Path(), strerror(status));
|
||||
ERR2("error while copying %s", path.Path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
CopyEngine(InstallerWindow *window);
|
||||
void MessageReceived(BMessage *msg);
|
||||
void SetStatusMessage(char *status);
|
||||
void Start(BMenu *srcMenu, BMenu *targetMenu);
|
||||
status_t Start(BMenu *srcMenu, BMenu *targetMenu);
|
||||
void ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu);
|
||||
void SetPackagesList(BList *list);
|
||||
void SetSpaceRequired(off_t bytes) { fSpaceRequired = bytes; };
|
||||
|
||||
Reference in New Issue
Block a user