From 8a7d617e81db8324c0158a9fcba3d2da53d5637b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Fri, 12 Mar 2021 16:18:40 +0100
Subject: [PATCH] ENH: treat case of removed files

---
 misc/move_files/move_files.py | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/misc/move_files/move_files.py b/misc/move_files/move_files.py
index 44cc3f4f..10c9bd00 100755
--- a/misc/move_files/move_files.py
+++ b/misc/move_files/move_files.py
@@ -62,15 +62,28 @@ def rename(changes, chunksize=10):
             continue
         cont = db.Container()
 
-        for _, (old, new) in chunk.iterrows():
-            cont.append(db.File(path=old))
-
-        cont.retrieve()
-
-        for fi, (_, (old, new)) in zip(cont, chunk.iterrows()):
-            assert fi.path == old
-            fi.path = new
-        cont.update()
+        cmap = {}
+
+        for ii, (old, new) in chunk.iterrows():
+            try:
+                fi = db.File(path=old)
+                fi.retrieve()
+
+                if not fi.is_valid():
+                    continue
+                cont.append(fi)
+                cmap[ii] = len(cont)-1
+            except Exception as e:
+                print(e)
+
+        for ii, (old, new) in chunk.iterrows():
+            if ii not in cmap:
+                continue
+            assert cont[cmap[ii]].path == old
+            cont[cmap[ii]].path = new
+
+        if len(cont) > 0:
+            cont.update(unique=False)
         i += 1
 
 
-- 
GitLab