Skip to content

Commit

Permalink
shutil.Error, not OSError - refs #744
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 29, 2020
1 parent e37f407 commit af3a5b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions datasette/utils/__init__.py
Expand Up @@ -598,14 +598,14 @@ def link_or_copy(src, dst):
# https://github.com/simonw/datasette/issues/141
try:
os.link(src, dst)
except OSError:
except shutil.Error:
shutil.copyfile(src, dst)


def link_or_copy_directory(src, dst):
try:
shutil.copytree(src, dst, copy_function=os.link)
except OSError:
except shutil.Error:
shutil.copytree(src, dst)


Expand Down
5 changes: 3 additions & 2 deletions tests/test_utils.py
Expand Up @@ -9,6 +9,7 @@
import os
import pathlib
import pytest
import shutil
import sqlite3
import tempfile
from unittest.mock import patch
Expand Down Expand Up @@ -253,8 +254,8 @@ def test_temporary_docker_directory_uses_hard_link():

@patch("os.link")
def test_temporary_docker_directory_uses_copy_if_hard_link_fails(mock_link):
# Copy instead if os.link raises OSError (normally due to different device)
mock_link.side_effect = OSError
# Copy instead if shutil.Error (normally due to different device)
mock_link.side_effect = shutil.Error
with tempfile.TemporaryDirectory() as td:
os.chdir(td)
open("hello", "w").write("world")
Expand Down

0 comments on commit af3a5b9

Please sign in to comment.