Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pelican/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,18 @@ def test_copy_dir_create_dirs(self):
self._exist_dir("b0", "b1", "b2", "b3", "b")
self._exist_file("b0", "b1", "b2", "b3", "b", "a.txt")

def test_copy_file_to_existing_dir(self):
self._create_dir("a")
self._create_file("a", "a.txt")
self._create_dir("b0", "b1")
utils.copy(
os.path.join(self.root_dir, "a", "a.txt"),
os.path.join(self.root_dir, "b0", "b1"),
)
self._exist_dir("b0")
self._exist_dir("b0", "b1")
self._exist_file("b0", "b1", "a.txt")


class TestDateFormatter(unittest.TestCase):
"""Tests that the output of DateFormatter jinja filter is same as
Expand Down
3 changes: 3 additions & 0 deletions pelican/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ def walk_error(err):

def copy_file(source: str, destination: str) -> None:
"""Copy a file"""
if os.path.isdir(destination):
destination = os.path.join(destination, os.path.basename(source))

try:
shutil.copyfile(source, destination)
except OSError as e:
Expand Down
Loading