Commit 380b65f1 authored by Kirill Smelkov's avatar Kirill Smelkov

Don't forget to save symlinks pointing to directories

os.walk() yields symlinks to directories in dirnames and do not follow
them. Our backup cycle expects all files that need to go to blob to be
in filenames and that dirnames are only recursed-into by walk().

Thus, until now, symlink to a directory was simply ignored and not
backup'ed. In particular *.git/hooks are usually symlinks to common
place.

The fix is to adjust our xwalk() to always represent blob-ish things in
filenames, and leave dirnames only for real directories.

/cc @kazuhiko
parent 32e1f7af
...@@ -60,7 +60,7 @@ NOTE the idea of pulling all refs together is similar to git-namespaces ...@@ -60,7 +60,7 @@ NOTE the idea of pulling all refs together is similar to git-namespaces
import os import os
import sys import sys
from os.path import join as pathjoin, exists as pathexists, dirname from os.path import join as pathjoin, exists as pathexists, dirname, islink
from time import strftime from time import strftime
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from stat import S_ISLNK from stat import S_ISLNK
...@@ -120,10 +120,18 @@ def xgit(*argv, **kw): ...@@ -120,10 +120,18 @@ def xgit(*argv, **kw):
return stdout return stdout
# like os.walk() but raise on error + entries are emitted in sorted order # like os.walk() but raise on error + entries are emitted in sorted order;
# symlinks (both to files and directories) are always yielded in filenames
def reraise(e): raise e def reraise(e): raise e
def xwalk(top): def xwalk(top):
for dirpath, dirnames, filenames in os.walk(top, onerror=reraise): for dirpath, dirnames, filenames in os.walk(top, onerror=reraise):
# os.walk yields symlinks to dirs in dirnames - move them to files
for i, _ in enumerate(dirnames):
if islink(pathjoin(dirpath, _)):
filenames.append(_)
dirnames[i] = None
removeall(dirnames, None)
dirnames.sort(); filenames.sort() dirnames.sort(); filenames.sort()
yield dirpath, dirnames, filenames yield dirpath, dirnames, filenames
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment