BFilePanel: reset to home dir if volume unmounted

* Fix bug reported by humdinger: when the volume which is
  currently shown in the file panel is unmounted, the file
  panel's window was closed and even deleted. This is not only
  inconvenient but also a use-after-free bug waiting to happen:
  an application which keeps the BFilePanel around to show it
  again later (as recommended in the BeBook) cannot know that
  it has become invalid while it was hidden (the destruction of
  the window happens even when it's not shown).

* When receiving an unmount event for the currently shown volume,
  we now reset the view to the home directory.
This commit is contained in:
Julian Harnath 2017-10-30 15:15:18 +01:00
parent a9c1157a2a
commit 615417e5ba

View File

@ -1740,12 +1740,12 @@ BFilePanelPoseView::StopWatching()
bool bool
BFilePanelPoseView::FSNotification(const BMessage* message) BFilePanelPoseView::FSNotification(const BMessage* message)
{ {
if (IsDesktopView()) {
// Pretty much copied straight from DesktopPoseView.
// Would be better if the code could be shared somehow.
switch (message->FindInt32("opcode")) { switch (message->FindInt32("opcode")) {
case B_DEVICE_MOUNTED: case B_DEVICE_MOUNTED:
{ {
if (IsDesktopView()) {
// Pretty much copied straight from DesktopPoseView.
// Would be better if the code could be shared somehow.
dev_t device; dev_t device;
if (message->FindInt32("new device", &device) != B_OK) if (message->FindInt32("new device", &device) != B_OK)
break; break;
@ -1766,6 +1766,21 @@ BFilePanelPoseView::FSNotification(const BMessage* message)
} }
break; break;
} }
case B_DEVICE_UNMOUNTED:
{
dev_t device;
if (message->FindInt32("device", &device) == B_OK) {
if (TargetModel() != NULL
&& TargetModel()->NodeRef()->device == device) {
// Volume currently shown in this file panel
// disappeared, reset location to home directory
BMessage message(kSwitchToHome);
MessageReceived(&message);
}
}
break;
}
} }
return _inherited::FSNotification(message); return _inherited::FSNotification(message);
} }