]> hydra-www.ietfng.org Git - csdb/commitdiff
Add 'duplicates' command
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Tue, 27 Dec 2022 02:59:58 +0000 (02:59 +0000)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Tue, 27 Dec 2022 03:09:33 +0000 (03:09 +0000)
cdb

diff --git a/cdb b/cdb
index 25ca782e4d68616041883b596434d5ba6d69f471..1eabc1f8a65c3a89839fff32d63ba50539ba7448 100755 (executable)
--- a/cdb
+++ b/cdb
@@ -670,6 +670,45 @@ mksubcmd(function(c)
   end
  end)
 
+----------------------------------------------------------------- }}}
+--------------------------------------- Command: duplicates dupes {{{
+
+mksubcmd(function(c)
+  c:name("duplicates dupes")
+   :description("List hashes with multiple associated files")
+  c:option("--glob"):default("*")
+  c:flag("--verbose")
+   :description("Be chatty on stderr about the generated comand stream")
+  local f = argparse_for_render(c)
+  f:default("$u$z")
+  argp_group("Query", c)
+ end,
+ function(args, dbh)
+  local render = renderer_for(args)
+
+  local sth = assert(sql_do(dbh,
+    [[SELECT hash, path, pairid, timestamp FROM v_path_hash NATURAL JOIN
+       (SELECT hashid, hcount FROM
+        (SELECT hashid, COUNT(pairid) AS hcount FROM path_hash GROUP BY hashid)
+        WHERE hcount > 1)
+       NATURAL JOIN (SELECT hashid FROM v_path_hash WHERE path NOT GLOB ?1)
+       WHERE path GLOB ?1 ORDER BY hashid]], args.glob))
+  local lasthash = nil
+  for row in sth:rows() do
+    local h, p, pairid, ts = table.unpack(row)
+    if h ~= lasthash then
+      lasthash = h
+      if args.verbose then io.stderr:write(("HASH %s\n"):format(h)) end
+    end
+    if args.verbose then
+      -- TODO: this is probably not the right thing to print
+      io.stderr:write((" observed path %s with id %d at %s\n")
+            :format(cdblib.posix_shell_escape(p), pairid, ts))
+    end
+    io.write(render("-", p))
+  end
+ end)
+
 ----------------------------------------------------------------- }}}
 ---------------------------------------- Command: filterhash filh {{{