azuline/nnn

scratchpad

Closed this issue · 0 comments

sorting debugging

notes on variables:

  • sorting is controlled by cfg.* globals, which is used in entrycmp to sort entries. the cfg.* globals are per-context.
  • cfgsort controls the sort config across multiple contexts
  • the cd variable is true whenever the directory changes? something like that... it's set to false in special cases prior to goto begin:

notes on special mechanics of cfgsort:

  • control flow: we go to savecurctx, which does some magic on cfgsort, and then we go to begin:, which does additional magic on cfgsort
  • cfgsort[CTX_MAX] is a carrier that sometimes transports the new context's state to begin: for that logic to act on it. when cfgsort[curctx] == '0', that means we want to use the carried sort and ignore any other logic. this occurs when we switch to a pre-existing context in an order != null environment.
    • note that \0 is also a default value for each cfgsort. so we hit this when a new session is created.
  • when cfgsort[curctx] == 'z', that means:
    1. we've switched to a new context, and the current context has no sort. z converts to c in begin:
    2. we've cd'ed into a directory that's in the order kv. the sort flags have been set, and the cfgsort is nullified (aka set to z) so that it isn't persistent.

bugged scenario:

  1. NNN_ORDER must be set.
    • cfgsort[0] = '0', cfg0.reverse = 0, entrycmpfn = &entrycmp
  2. set context 1 to r
    • cfgsort[0] = 'r', cfg0.reverse = 1, entrycmpfn = &reventrycmp
  3. create context 2. context 2 should also be r.
    • cfgsort[0] = 'r', cfgsort[1] = 'r', cfg0.reverse = 1, cfg1.reverse = 1, entrycmpfn = &reventrycmp
  4. unset r in context 2.
    • cfgsort[0] = 'r', cfgsort[1] = 'c', cfg0.reverse = 1, cfg1.reverse = 0, entrycmpfn = &entrycmp
  5. switch back to context 1. context 1 should not be r.
    • we hit the "skip ordering on open context carry logic". so we do not change anything
    • cfgsort[0] = 'r', cfgsort[1] = 'c', cfg0.reverse = 1, cfg1.reverse = 0, entrycmpfn = &entrycmp
  6. try to set r again. no-ops when it should op.
    • cfgsort[0] = 'r', cfgsort[1] = 'c', cfg0.reverse = 0, cfg1.reverse = 0, entrycmpfn = &entrycmp

root cause: &entrycmpfn is out of sync with cfg/cfgsort

soln: restore fn pointers when restoring cfg