diff options
author | Jon Bernard <jbernard@tuxion.com> | 2011-10-05 09:27:08 -0400 |
---|---|---|
committer | Jon Bernard <jbernard@tuxion.com> | 2011-10-05 19:07:22 -0400 |
commit | 13cf54aee19b0d7fa269b503c3d6f328e5fc0552 (patch) | |
tree | b2b493d77554f3e1c74055a9fda863899e228c11 /test_dotfiles.py | |
parent | 92f6cd0b0a283d2a949e83838c48e2e8cece1156 (diff) | |
download | dotfiles-13cf54aee19b0d7fa269b503c3d6f328e5fc0552.tar.gz dotfiles-13cf54aee19b0d7fa269b503c3d6f328e5fc0552.tar.bz2 dotfiles-13cf54aee19b0d7fa269b503c3d6f328e5fc0552.zip |
Fix bug when syncing an unmanaged directory symlink
Closes #2
Diffstat (limited to 'test_dotfiles.py')
-rwxr-xr-x | test_dotfiles.py | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/test_dotfiles.py b/test_dotfiles.py index 360d7db..bb54578 100755 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -21,7 +21,7 @@ class DotfilesTestCase(unittest.TestCase): self.home = tempfile.mkdtemp() - # create a repository for the tests to use + # Create a repository for the tests to use. self.repo = os.path.join(self.home, 'Dotfiles') os.mkdir(self.repo) @@ -62,7 +62,7 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.sync() - # make sure sync() did the right thing + # Make sure sync() did the right thing. self.assertEqual( os.path.realpath(os.path.join(self.home, '.bashrc')), os.path.join(self.repo, 'bashrc')) @@ -76,6 +76,41 @@ class DotfilesTestCase(unittest.TestCase): os.path.realpath(os.path.join(self.home, '.bashrc')), os.path.join(target, 'bashrc')) + def test_sync_unmanaged_directory_symlink(self): + """Test a forced sync on a directory symlink. + + A bug was reported where a user wanted to replace a dotfile repository + with an other one. They had a .vim directory in their home directory + which was obviously also a symbolic link. This caused: + + OSError: Cannot call rmtree on a symbolic link + """ + + # Create a dotfile symlink to some directory + os.mkdir(os.path.join(self.home, 'vim')) + os.symlink(os.path.join(self.home, 'vim'), + os.path.join(self.home, '.vim')) + + # Create a vim directory in the repository. This will cause the above + # symlink to be overwritten on sync. + os.mkdir(os.path.join(self.repo, 'vim')) + + # Make sure the symlink points to the correct location. + self.assertEqual( + os.path.realpath(os.path.join(self.home, '.vim')), + os.path.join(self.home, 'vim')) + + dotfiles = core.Dotfiles( + home=self.home, repo=self.repo, prefix='', + ignore=[], externals={}) + + dotfiles.sync(force=True) + + # The symlink should now point to the directory in the repository. + self.assertEqual( + os.path.realpath(os.path.join(self.home, '.vim')), + os.path.join(self.repo, 'vim')) + def suite(): suite = unittest.TestLoader().loadTestsFromTestCase(DotfilesTestCase) |