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:
Jérôme Duval
2007-05-12 13:37:02 +00:00
parent 140334f858
commit 9f3d8cb64f
14 changed files with 315 additions and 282 deletions
+59 -26
View File
@@ -16,11 +16,15 @@
#include <String.h> #include <String.h>
#include <VolumeRoster.h> #include <VolumeRoster.h>
//#define COPY_TRACE #define COPY_TRACE
#ifdef COPY_TRACE #ifdef COPY_TRACE
#define CALLED() printf("CALLED %s\n",__PRETTY_FUNCTION__) #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 #else
#define CALLED() #define CALLED()
#define ERR(x)
#define ERR2(x, y...)
#endif #endif
const char BOOT_PATH[] = "/boot"; const char BOOT_PATH[] = "/boot";
@@ -67,7 +71,9 @@ CopyEngine::MessageReceived(BMessage*msg)
CALLED(); CALLED();
switch (msg->what) { switch (msg->what) {
case ENGINE_START: case ENGINE_START:
Start(fWindow->GetSourceMenu(), fWindow->GetTargetMenu()); status_t err = Start(fWindow->GetSourceMenu(), fWindow->GetTargetMenu());
if (err != B_OK)
ERR("Start failed");
break; break;
} }
} }
@@ -110,15 +116,16 @@ CopyEngine::LaunchFinishScript(BPath &path)
} }
void status_t
CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu) CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
{ {
CALLED(); CALLED();
status_t err = B_OK;
PartitionMenuItem *targetItem = (PartitionMenuItem *)targetMenu->FindMarked(); PartitionMenuItem *targetItem = (PartitionMenuItem *)targetMenu->FindMarked();
PartitionMenuItem *srcItem = (PartitionMenuItem *)srcMenu->FindMarked(); PartitionMenuItem *srcItem = (PartitionMenuItem *)srcMenu->FindMarked();
if (!srcItem || !targetItem) { if (!srcItem || !targetItem) {
fprintf(stderr, "bad menu items\n"); ERR("bad menu items\n");
return; return B_BAD_VALUE;
} }
// check if target is initialized // check if target is initialized
@@ -130,40 +137,66 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
BVolume targetVolume; BVolume targetVolume;
if (fDDRoster.GetPartitionWithID(targetItem->ID(), &device, &partition) == B_OK) { if (fDDRoster.GetPartitionWithID(targetItem->ID(), &device, &partition) == B_OK) {
if (partition->GetVolume(&targetVolume)!=B_OK) if (!partition->IsMounted()) {
return; if ((err = partition->Mount()) < B_OK) {
if (partition->GetMountPoint(&targetDirectory)!=B_OK) SetStatusMessage("The disk can't be mounted. Please choose a different disk.");
return; 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) { } else if (fDDRoster.GetDeviceWithID(targetItem->ID(), &device) == B_OK) {
if (device.GetVolume(&targetVolume)!=B_OK) if (!device.IsMounted()) {
return; if ((err = device.Mount()) < B_OK) {
if (device.GetMountPoint(&targetDirectory)!=B_OK) SetStatusMessage("The disk can't be mounted. Please choose a different disk.");
return; 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 } else
return; // shouldn't happen return B_ERROR; // shouldn't happen
// check if target has enough space // check if target has enough space
if ((fSpaceRequired > 0 && targetVolume.FreeBytes() < fSpaceRequired) if ((fSpaceRequired > 0 && targetVolume.FreeBytes() < fSpaceRequired)
&& ((new BAlert("", "The destination disk may not have enough space. Try choosing a different disk or \ && ((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, choose to not install optional items.", "Try installing anyway", "Cancel", 0,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) {
return; return B_OK;
} }
BPath srcDirectory; BPath srcDirectory;
if (fDDRoster.GetPartitionWithID(srcItem->ID(), &device, &partition) == B_OK) { if (fDDRoster.GetPartitionWithID(srcItem->ID(), &device, &partition) == B_OK) {
if (partition->GetMountPoint(&srcDirectory)!=B_OK) if ((err = partition->GetMountPoint(&srcDirectory)) != B_OK) {
return; ERR("BPartition::GetMountPoint");
return err;
}
} else if (fDDRoster.GetDeviceWithID(srcItem->ID(), &device) == B_OK) { } else if (fDDRoster.GetDeviceWithID(srcItem->ID(), &device) == B_OK) {
if (device.GetMountPoint(&srcDirectory)!=B_OK) if ((err = device.GetMountPoint(&srcDirectory)) != B_OK) {
return; ERR("BDiskDevice::GetMountPoint");
return err;
}
} else } else
return; // shouldn't happen return B_ERROR; // shouldn't happen
// check not installing on itself // check not installing on itself
if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) { if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) {
SetStatusMessage("You can't install the contents of a disk onto itself. Please choose a different disk."); 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 // 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, The installer will have to reboot your machine if you proceed.", "OK", "Cancel", 0,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) {
SetStatusMessage("Installation stopped."); SetStatusMessage("Installation stopped.");
return; return B_OK;
} }
LaunchInitScript(targetDirectory); LaunchInitScript(targetDirectory);
@@ -206,7 +239,7 @@ void
CopyEngine::CopyFolder(BDirectory &srcDir, BDirectory &targetDir) CopyEngine::CopyFolder(BDirectory &srcDir, BDirectory &targetDir)
{ {
BEntry entry; BEntry entry;
status_t status; status_t err;
while (srcDir.GetNextEntry(&entry) == B_OK) { while (srcDir.GetNextEntry(&entry) == B_OK) {
char name[B_FILE_NAME_LENGTH]; char name[B_FILE_NAME_LENGTH];
entry.GetName(name); entry.GetName(name);
@@ -214,11 +247,11 @@ CopyEngine::CopyFolder(BDirectory &srcDir, BDirectory &targetDir)
continue; continue;
Undo undo; Undo undo;
status = FSCopyFolder(&entry, &targetDir, fControl, NULL, false, undo); err = FSCopyFolder(&entry, &targetDir, fControl, NULL, false, undo);
if (status != B_OK) { if (err != B_OK) {
BPath path; BPath path;
entry.GetPath(&path); entry.GetPath(&path);
fprintf(stderr, "error while copying %s : %s\n", path.Path(), strerror(status)); ERR2("error while copying %s", path.Path());
} }
} }
} }
+1 -1
View File
@@ -24,7 +24,7 @@ public:
CopyEngine(InstallerWindow *window); CopyEngine(InstallerWindow *window);
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
void SetStatusMessage(char *status); void SetStatusMessage(char *status);
void Start(BMenu *srcMenu, BMenu *targetMenu); status_t Start(BMenu *srcMenu, BMenu *targetMenu);
void ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu); void ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu);
void SetPackagesList(BList *list); void SetPackagesList(BList *list);
void SetSpaceRequired(off_t bytes) { fSpaceRequired = bytes; }; void SetSpaceRequired(off_t bytes) { fSpaceRequired = bytes; };