Skip to content

Fall back from link upload to next file transfer #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025
Merged
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
4 changes: 3 additions & 1 deletion src/scitacean/transfer/link.py
Original file line number Diff line number Diff line change
@@ -225,8 +225,10 @@ def connect_for_upload(
"`LinkFileTransfer` cannot be used for uploading files. "
"If you have direct access to the file server, consider either "
"copying the files into place or writing them directly to the "
"'remote folder'."
"'remote folder'. See also scitacean.transfer.copy.CopyFileTransfer.",
)
# This is needed to make this function a context manager:
yield LinkUploadConnection(source_folder=self.source_folder) # type: ignore[unreachable]


__all__ = ["LinkDownloadConnection", "LinkFileTransfer", "LinkUploadConnection"]
2 changes: 1 addition & 1 deletion src/scitacean/transfer/select.py
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ def _connect_first_suitable(
# a different transfer if the actual download / upload fails
# but only if connecting fails.
connection = connection_manager.__enter__()
except RuntimeError as error:
except (RuntimeError, NotImplementedError) as error:
errors.append(error)
continue
success = True
3 changes: 2 additions & 1 deletion tests/transfer/link_test.py
Original file line number Diff line number Diff line change
@@ -88,7 +88,8 @@ def test_link_transfer_cannot_upload() -> None:
ds = Dataset(type="raw", source_folder=RemotePath("/data/upload"))
linker = LinkFileTransfer()
with pytest.raises(NotImplementedError):
linker.connect_for_upload(ds, cast(RemotePath, ds.source_folder))
with linker.connect_for_upload(ds, cast(RemotePath, ds.source_folder)):
...


def test_link_transfer_raises_if_file_does_not_exist(
24 changes: 24 additions & 0 deletions tests/transfer/select_transfer_test.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
from __future__ import annotations

import dataclasses
import sys
from collections.abc import Iterator
from contextlib import contextmanager
from pathlib import Path
@@ -11,6 +12,8 @@
import pytest

from scitacean import Dataset, File, RemotePath
from scitacean.transfer.copy import CopyFileTransfer
from scitacean.transfer.link import LinkFileTransfer
from scitacean.transfer.select import SelectFileTransfer


@@ -300,3 +303,24 @@ def test_select_upload_uses_second_child_transfer_success(dataset: Dataset) -> N
assert transfer_2.uploaded == [file.local_path]
assert not transfer_2.downloaded
assert not transfer_2.reverted


@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="Copy and link transfers do not support Windows",
)
@pytest.mark.parametrize("hard_link", [True, False])
def test_copy_and_link_transfers_fall_back(dataset: Dataset, hard_link: bool) -> None:
copier = CopyFileTransfer(hard_link=hard_link)
linker = LinkFileTransfer()
fallback = SuccessfulTransfer()
transfer = SelectFileTransfer([copier, linker, fallback])

file = File.from_local("/not-a-real-parent/local_file", remote_path="remote_file")
with transfer.connect_for_upload(dataset, RemotePath("remote_file")) as con:
con.upload_files(file)

assert not fallback.is_open_for_download
assert fallback.uploaded == [file.local_path]
assert not fallback.downloaded
assert not fallback.reverted