[Bug]: Local filesystem ancestor copies delete the source and unrelated files

Đang mở
#41,747 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@JustinBinber đang làm issue này rồi.

Từ ngày 29/11/2026.

  • #41748 của @JustinBinber — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

What happened?

FileSystems.copy() can delete the source and unrelated files when an existing destination directory is an ancestor of the source. The source and destination are distinct objects, so the existing same-file check does not prevent the deletion.

Reproduced on current master a9b9e8d3cd13e1b5109175968bf00d137f497cf8, Windows / Python 3.11.7, using current Python sources and real local filesystem operations.

Reproduction
from pathlib import Path
from tempfile import TemporaryDirectory
from apache_beam.io.filesystem import BeamIOError
from apache_beam.io.filesystems import FileSystems

with TemporaryDirectory() as temporary:
    tree = Path(temporary) / "tree"
    source = tree / "source"
    source.mkdir(parents=True)
    (source / "data").write_text("source data")
    (tree / "unrelated").write_text("keep this")
    try:
        FileSystems.copy([str(source)], [str(tree)])
    except BeamIOError as error:
        print(error)
    print((source / "data").exists())  # False
    print((tree / "unrelated").exists())  # False

A source file copied to its containing directory loses data in the same way. LocalFileSystem.copy() removes the existing destination before attempting to read the source.

Expected behavior

Reject the overlapping pair through the existing BeamIOError aggregation before removing any destination data. Copying a directory into one of its own output descendants should also be rejected before entering copytree. Independent valid pairs in the batch should continue as they currently do.

The check needs to account for source access through link entries/targets and Windows drive-relative paths. Looking only at the final resolved source misses a link inside the destination that points outside; looking only at original parents misses an outside link whose target or intermediate link is inside the destination. Normal disjoint copies, including a harmless source/../neighbor output, should continue to work.

This is a follow-up to #41561 / #41562, which addressed copying onto the same filesystem object. It does not require changing cloud filesystems or making local copies transactional.

Ngôn ngữ chính
Java
Star
8.7k
Fork
4.8k
Merge trung bình
3 ngày 16 giờ
Pull request đã merge (30 ngày)
445

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/beam

Tất cả issue của apache/beam

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.