[haiku-bugs] Re: [Haiku] #12105: [Tracker][Add-On API] process_refs gets wrong directory entry_ref

  • From: "ahwayakchih" <trac@xxxxxxxxxxxx>
  • Date: Tue, 02 Jun 2015 06:35:09 -0000

#12105: [Tracker][Add-On API] process_refs gets wrong directory entry_ref
------------------------------------+----------------------------
Reporter: ahwayakchih | Owner: waddlesplash
Type: bug | Status: assigned
Priority: normal | Milestone: Unscheduled
Component: Applications/Tracker | Version: R1/Development
Resolution: | Keywords: process_refs
Blocked By: | Blocking:
Has a Patch: 0 | Platform: All
------------------------------------+----------------------------

Comment (by ahwayakchih):

I think the bug is in here:


https://github.com/haiku/haiku/blob/master/src/kits/tracker/ContainerWindow.cpp#L3228

For easier reading, section of code (lines 3226-3232):

{{{
#!cpp
const entry_ref* modelRef = TargetModel()->IsContainer()
&& selectionList->ItemAt(0) != NULL
? selectionList->ItemAt(0)->TargetModel()->EntryRef()
: TargetModel()->EntryRef();

LaunchInNewThread("Add-on", B_NORMAL_PRIORITY, &AddOnThread, refs,
addonRef, *modelRef);
}}}

On line 3228, it gets entry_ref of the first item, instead of entry_ref of
first item's directory.

I may be wrong, but i think that whole ternary condition is incorrect.
shouldn't it be more like:

{{{
#!cpp
const entry_ref* modelRef = !TargetModel()->IsContainer()
&& selectionList->ItemAt(0) == NULL
? selectionList->ItemAt(0)->TargetModel()->EntryRef()
: TargetModel()->EntryRef();

LaunchInNewThread("Add-on", B_NORMAL_PRIORITY, &AddOnThread, refs,
addonRef, *modelRef);
}}}

(notice the first condition). That would be much better, but still not
ideal: don't know if that may happen in practice, but if TargetModel was
not container and there would be no item selected, we would still get
entry_ref to that weird TargetModel, in which case it probably would be
better to ignore whole action and return earlier (and/or show some error
message?).

--
Ticket URL: <https://dev.haiku-os.org/ticket/12105#comment:3>
Haiku <https://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: