db: replace basename(3) with last_path_segment
POSIX specifies that basename(3) may change the string it is passed. Since fn is still used later it needs to be kept as-is. Replacing basename with last_path_segment which is sufficient for the use case and never changes fn.
Edited by Sertonix