db_scan_tree() and db_scan_tree_link() are confused

Create issue
Issue #165 new
dd1 created an issue

The annotation for db_scan_tree() says "Scan a subtree recursively and call 'callback' for each key" and that is what it seems to do, the best I can tell. Symlinks are not followed, they are passed to the callback function as symlinks.

The annotation for db_scan_tree_link() says "Similar to db_scan_tree but without following links". This is not what it seems to do, for symlinks, the callback function is called with the hkey of the symlink (returned by db_enum_link()) and the key of whatever the symlink points to (returned by db_get_key(), which follows symlinks).

There are two problems:

a) db_scan_tree_link() calls the callback function with inconsistent data - hkey of one odb entry (the symlink) and key of another entry (symlink target).

b) the annotations for the two functions are wrong or misleading: db_scan_tree() does not follow symlinks (at all), db_scan_tree_link() follows them (partially).

This confusion causes anomalies in functions like odbedit "sor" (via db_get_open_records()), see https://bitbucket.org/tmidas/midas/issues/136/odb-error-with-link-to-open-record

K.O.

Comments (4)

  1. dd1 reporter

    db_scan_tree_link() replacement is db_scan_tree_locked(), which does not follow symlinks. the only place that calls db_scan_tree_link() is db_create_record(), with database locked. K.O.

  2. dd1 reporter

    db_scan_tree() follows links, is called from:

    • odbedit “ls” command, looks right
    • db_get_open_records(), probably should be db_scan_tree_locked()
    • db_show_mem(), probably should be db_scan_tree_locked().
    • mhttpd “odb find” page, looks right.

    K.O.

  3. dd1 reporter

    looks like db_scan_tree_link() can be removed after all uses are converted to db_scan_tree_locked(). K.O.

  4. Log in to comment