Example #1
0
def test_link_with_conflicting_broken_link_at_dest(file_a, dest):
    dest_file = os.path.join(dest, 'file_a_link')
    os.symlink('non_existant_source', dest_file)
    with pytest.raises(ValueError) as e:
        dploy.link(file_a, dest_file)
    assert (error.ConflictsWithExistingLink(subcmd=SUBCMD,
                                            source=file_a,
                                            dest=dest_file).msg
            in str(e.value))
Example #2
0
def test_link_with_conflicting_broken_link_at_dest(file_a, dest):
    dest_file = os.path.join(dest, 'file_a_link')
    os.symlink('non_existant_source', dest_file)
    message = str(
        error.ConflictsWithExistingLink(subcmd=SUBCMD,
                                        source=file_a,
                                        dest=dest_file))
    with pytest.raises(error.ConflictsWithExistingLink, match=message):
        dploy.link(file_a, dest_file)
Example #3
0
def test_stow_with_existing_broken_link(source_a, dest):
    conflicting_link = os.path.join(dest, 'aaa')
    os.symlink('non_existant_source', conflicting_link)
    source_file = os.path.join(source_a, 'aaa')
    message = str(
        error.ConflictsWithExistingLink(subcmd=SUBCMD,
                                        source=source_file,
                                        dest=conflicting_link))
    with pytest.raises(error.ConflictsWithExistingLink):
        dploy.stow([source_a], dest)
Example #4
0
def test_unstow_with_a_broken_link_dest(source_a, dest):
    conflicting_link = os.path.join(dest, 'aaa')
    source_file = os.path.join(source_a, 'aaa')
    os.symlink('non_existant_source', os.path.join(dest, 'aaa'))
    with pytest.raises(ValueError) as e:
        dploy.unstow([source_a], dest)
    assert (error.ConflictsWithExistingLink(subcmd=SUBCMD,
                                            source=source_file,
                                            dest=conflicting_link).msg
            in str(e.value))
Example #5
0
    def _collect_actions(self, source, dest):
        """
        Concrete method to collect required actions to perform a stow
        sub-command
        """

        if self.ignore.should_ignore(source):
            self.ignore.ignore(source)
            return

        if not StowInput(self.errors, self.subcmd).is_valid_collection_input(
                source, dest):
            return

        sources = self.get_directory_contents(source)

        for subsources in sources:
            if self.ignore.should_ignore(subsources):
                self.ignore.ignore(subsources)
                continue

            dest_path = dest / pathlib.Path(subsources.name)

            does_dest_path_exist = False
            try:
                does_dest_path_exist = dest_path.exists()
            except PermissionError:
                self.errors.add(error.PermissionDenied(self.subcmd, dest_path))
                return

            if does_dest_path_exist:
                self._collect_actions_existing_dest(subsources, dest_path)
            elif dest_path.is_symlink():
                self.errors.add(
                    error.ConflictsWithExistingLink(self.subcmd, subsources,
                                                    dest_path))
            elif not dest_path.parent.exists() and not self.is_unfolding:
                self.errors.add(
                    error.NoSuchDirectory(self.subcmd, dest_path.parent))
            else:
                self._are_other(subsources, dest_path)
Example #6
0
    def _collect_actions(self, source, dest):
        """
        Concrete method to collect required actions to perform a link
        sub-command
        """

        if dest.exists():
            if utils.is_same_file(dest, source):
                self.actions.add(
                    actions.AlreadyLinked(self.subcmd, source, dest))
            else:
                self.errors.add(
                    error.ConflictsWithExistingFile(self.subcmd, source, dest))
        elif dest.is_symlink():
            self.errors.add(
                error.ConflictsWithExistingLink(self.subcmd, source, dest))

        elif not dest.parent.exists():
            self.errors.add(
                error.NoSuchDirectoryToSubcmdInto(self.subcmd, dest.parent))

        else:
            self.actions.add(actions.SymbolicLink(self.subcmd, source, dest))