summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar simon.parzer@f837bbade0d93f560dc574b04e835b7875c4026f <simonparzer@web>2016-05-05 11:58:31 +0000
committerGravatar admin <admin@branchable.com>2016-05-05 11:58:31 +0000
commit21cd455268f206d32bfbc85450a0689dca0b0c09 (patch)
treeebcb3a45de9bdc49b2de14843e8f18a647cd6158
parent7138686b80f9eb31944c25a7c56e5353fd5e685f (diff)
Added a comment: Python script to recover git annex' lost files
-rw-r--r--doc/forum/files_got_replaced_by_broken_symblinks__44___how_to_get_them_back__63__/comment_7_37eaed2d7afa0c064e1b30a6f1e4dc01._comment49
1 files changed, 49 insertions, 0 deletions
diff --git a/doc/forum/files_got_replaced_by_broken_symblinks__44___how_to_get_them_back__63__/comment_7_37eaed2d7afa0c064e1b30a6f1e4dc01._comment b/doc/forum/files_got_replaced_by_broken_symblinks__44___how_to_get_them_back__63__/comment_7_37eaed2d7afa0c064e1b30a6f1e4dc01._comment
new file mode 100644
index 000000000..194f92d32
--- /dev/null
+++ b/doc/forum/files_got_replaced_by_broken_symblinks__44___how_to_get_them_back__63__/comment_7_37eaed2d7afa0c064e1b30a6f1e4dc01._comment
@@ -0,0 +1,49 @@
+[[!comment format=mdwn
+ username="simon.parzer@f837bbade0d93f560dc574b04e835b7875c4026f"
+ nickname="simon.parzer"
+ subject="Python script to recover git annex' lost files"
+ date="2016-05-05T11:58:31Z"
+ content="""
+Maybe someone else needs this too :|
+Use it at your own risk of course.
+```
+#!python3
+
+import os
+import re
+from shutil import copyfile
+
+targets = {}
+
+for path, dirs, files in os.walk('.'):
+ for f in files:
+ fp = os.path.join(path, f)
+ if fp.endswith('.py'): continue
+ fp_size = os.stat(fp).st_size
+ if fp_size < 72 or fp_size > 256: continue
+ with open(fp, 'r', encoding='latin1') as stream:
+ l = stream.readline()
+ hashmatch = re.match('.*SHA256E\-\w+\-\-(\w{16})', l)
+ if hashmatch:
+ targets[hashmatch.group(1)] = os.path.abspath(fp)
+
+#print(targets)
+
+target = os.path.abspath('.')
+while not os.path.exists('.git/annex/objects'):
+ os.chdir('..')
+
+for path, dirs, files in os.walk('.git/annex/objects'):
+ for f in files:
+ fp = os.path.join(path, f)
+ fp_size = os.stat(fp).st_size
+ if fp_size > 512:
+ hashmatch = re.match('.*SHA256E\-\w+\-\-(\w{16})', fp)
+ if hashmatch:
+ hash = hashmatch.group(1)
+ if hash in targets:
+ print(fp, '->', targets[hash])
+ copyfile(fp, targets[hash])
+
+```
+"""]]