From b845606cc48599a30f4f164959124349ae6650aa Mon Sep 17 00:00:00 2001 From: karim hamidou Date: Sun, 29 Jul 2012 17:34:14 +0200 Subject: [PATCH] fixed at last the infinite loop bug --- cagibi/cagibi.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cagibi/cagibi.py b/cagibi/cagibi.py index d19c40c..f788c9b 100644 --- a/cagibi/cagibi.py +++ b/cagibi/cagibi.py @@ -31,6 +31,12 @@ mqueue["added"] = Queue() mqueue["modified"] = Queue() mqueue["removed"] = Queue() +# The list of modified files is used when a file has been +# modified by the client itself, so that it doesn't try to +# upload it again to the server in a never-ending loop. +# No need for a mutex as it's thread-local +mqueue["client_modified"] = [] + def setup_filewatcher_thread(): fw = FileWatcher(path=cagibi_folder) @@ -52,6 +58,10 @@ def upload_local_changes(): while not mqueue["modified"].empty(): file = mqueue["modified"].get() + + if file in mqueue["client_modified"]: + continue + print "Detect %s modified" % file url = "%s/files/%s/hashes" % (server_url, file) @@ -85,7 +95,7 @@ def upload_local_changes(): local_files = load_config("files.json") local_files[file]["rev"] = results["rev"] - save_config("files.json") + save_config(local_files, filename="files.json") print "%f" % os.path.getmtime(secure_path(cagibi_folder, file)) opener = urllib2.build_opener(urllib2.HTTPHandler) @@ -173,6 +183,7 @@ def checkout_upstream_changes(): file_copy.close() local_files[file]["rev"] = server_files[file]["rev"] modified = True + mqueue["client_modified"].append(file) except IOError: continue @@ -185,6 +196,7 @@ def checkout_upstream_changes(): def sync_changes(): while True: checkout_upstream_changes() + mqueue["client_modified"] = [] time.sleep(10) upload_local_changes() -- 2.43.0