From b5d21b0857ed6ff3daad02d967f9fdaa868aa6fd Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Tue, 30 Jun 2015 16:59:26 -0400 Subject: [PATCH] fix: unlink symlinks before copying git hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit there was an issue where if a git hook with the same name existed already, but was a symlink, ka-clone would overrwrite the link destination’s contents rather than replacing the symlink! apparently this is what python’s `shutil.copyfile` does by design. as a fix, manually unlink any symlinks first to be extra safe, then use `shutil.copy` instead. #devenvfixup Auditors: csilvers, ethan, mopewa --- bin/ka-clone | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/ka-clone b/bin/ka-clone index 1725af2..46f4074 100755 --- a/bin/ka-clone +++ b/bin/ka-clone @@ -124,7 +124,10 @@ def _install_git_hook(template_name, hook_name): if not os.path.isdir(hooks_dir): os.makedirs(hooks_dir) dst = os.path.join(hooks_dir, hook_name) - shutil.copyfile(src, dst) + # if dst is a symlink, unlink (remove) it first, to avoid overwriting + if os.path.islink(dst): + os.unlink(dst) + shutil.copy(src, dst) os.chmod(dst, (os.stat(dst)).st_mode | 0111) # ensure chmod +x