|
| 1 | +import os |
1 | 2 | import pytest
|
2 | 3 |
|
| 4 | +from fsspec.implementations.local import LocalFileSystem |
3 | 5 | from fsspec.asyn import AsyncFileSystem
|
4 | 6 | from fsspec.implementations.dirfs import DirFileSystem
|
5 | 7 | from fsspec.spec import AbstractFileSystem
|
@@ -615,3 +617,38 @@ def test_from_url(m):
|
615 | 617 | assert fs.ls("", False) == ["file"]
|
616 | 618 | assert fs.ls("", True)[0]["name"] == "file"
|
617 | 619 | assert fs.cat("file") == b"data"
|
| 620 | + |
| 621 | + |
| 622 | +def test_dirfs_transaction_propagation(tmpdir): |
| 623 | + # Setup |
| 624 | + path = str(tmpdir) |
| 625 | + base = LocalFileSystem() |
| 626 | + fs = DirFileSystem(path=path, fs=base) |
| 627 | + |
| 628 | + # Test file path |
| 629 | + test_file = "transaction_test.txt" |
| 630 | + full_path = os.path.join(path, test_file) |
| 631 | + |
| 632 | + # Before transaction, both filesystems should have _intrans=False |
| 633 | + assert not base._intrans |
| 634 | + assert not fs._intrans |
| 635 | + |
| 636 | + # Enter transaction and write file |
| 637 | + with fs.transaction: |
| 638 | + # After fix, both filesystems should have _intrans=True |
| 639 | + assert base._intrans, "Base filesystem transaction flag not set" |
| 640 | + assert fs._intrans, "DirFileSystem transaction flag not set" |
| 641 | + |
| 642 | + # Write to file |
| 643 | + with fs.open(test_file, "wb") as f: |
| 644 | + f.write(b"hello world") |
| 645 | + |
| 646 | + # Check if file exists on disk - it should not until transaction commits |
| 647 | + assert not os.path.exists(full_path), "File exists during transaction, not deferred to temp file" |
| 648 | + |
| 649 | + # After transaction commits, file should exist |
| 650 | + assert os.path.exists(full_path), "File not created after transaction commit" |
| 651 | + |
| 652 | + # Verify content |
| 653 | + with open(full_path, "rb") as f: |
| 654 | + assert f.read() == b"hello world" |
0 commit comments