From d006068ca7553fb100247e343cfad3010b734bd9 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 27 Jul 2024 10:10:01 -0500 Subject: Convert rel paths to abs paths, update paths after move, insert dir to DB before recursion so DB is always a tree --- client.py | 2 +- server.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client.py b/client.py index 2d7ea97..180335f 100644 --- a/client.py +++ b/client.py @@ -2,4 +2,4 @@ import sys import xmlrpc.client proxy = xmlrpc.client.ServerProxy("http://localhost:8000") -print('\n'.join(proxy.search(sys.argv[1], sys.argv[2]))) +print("\n".join(proxy.search(sys.argv[1], sys.argv[2]))) diff --git a/server.py b/server.py index 4c3046e..6b7981d 100644 --- a/server.py +++ b/server.py @@ -49,6 +49,7 @@ class EventHandler(FileSystemEventHandler): "INSERT OR REPLACE INTO idx VALUES (?, ?, ?, ?)", (s.st_ino, get_parent(event.dest_path), s.st_mtime, event.dest_path), ) + cur.execute("UPDATE idx SET path = replace(path, ?, ?)", (event.src_path, event.dest_path)) con.commit() @@ -83,7 +84,12 @@ def index(path, parent): return cur.execute("INSERT OR REPLACE INTO emb VALUES (?, ?)", (s.st_ino, emb.numpy())) - else: + cur.execute( + "INSERT OR REPLACE INTO idx VALUES (?, ?, ?, ?)", + (s.st_ino, parent, s.st_mtime, path), + ) + con.commit() + if os.path.isdir(path): if parent: children = os.listdir(path) else: @@ -105,12 +111,6 @@ def index(path, parent): observer.schedule(event_handler, child, recursive=True) index(os.path.join(path, child), s.st_ino) - cur.execute( - "INSERT OR REPLACE INTO idx VALUES (?, ?, ?, ?)", - (s.st_ino, parent, s.st_mtime, path), - ) - con.commit() - def unindex(id): print("Unindexing", id) @@ -133,7 +133,7 @@ def search(text, limit): print("Indexing files") -watchdirs = set(sys.argv[1:]) +watchdirs = set(map(os.path.abspath, sys.argv[1:])) observer = Observer() event_handler = EventHandler() # Pretend that / is the parent of all indexed dirs -- cgit v1.2.3-70-g09d2