mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af3a5b9150 |
2 changed files with 5 additions and 4 deletions
|
|
@ -598,14 +598,14 @@ def link_or_copy(src, dst):
|
||||||
# https://github.com/simonw/datasette/issues/141
|
# https://github.com/simonw/datasette/issues/141
|
||||||
try:
|
try:
|
||||||
os.link(src, dst)
|
os.link(src, dst)
|
||||||
except OSError:
|
except shutil.Error:
|
||||||
shutil.copyfile(src, dst)
|
shutil.copyfile(src, dst)
|
||||||
|
|
||||||
|
|
||||||
def link_or_copy_directory(src, dst):
|
def link_or_copy_directory(src, dst):
|
||||||
try:
|
try:
|
||||||
shutil.copytree(src, dst, copy_function=os.link)
|
shutil.copytree(src, dst, copy_function=os.link)
|
||||||
except OSError:
|
except shutil.Error:
|
||||||
shutil.copytree(src, dst)
|
shutil.copytree(src, dst)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import pytest
|
import pytest
|
||||||
|
import shutil
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import tempfile
|
import tempfile
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
@ -253,8 +254,8 @@ def test_temporary_docker_directory_uses_hard_link():
|
||||||
|
|
||||||
@patch("os.link")
|
@patch("os.link")
|
||||||
def test_temporary_docker_directory_uses_copy_if_hard_link_fails(mock_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)
|
# Copy instead if shutil.Error (normally due to different device)
|
||||||
mock_link.side_effect = OSError
|
mock_link.side_effect = shutil.Error
|
||||||
with tempfile.TemporaryDirectory() as td:
|
with tempfile.TemporaryDirectory() as td:
|
||||||
os.chdir(td)
|
os.chdir(td)
|
||||||
open("hello", "w").write("world")
|
open("hello", "w").write("world")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue