s3fs icon indicating copy to clipboard operation
s3fs copied to clipboard

Add test that s3fs.put of single file in directory is repeatable

Open ianthomas23 opened this issue 2 years ago • 4 comments
trafficstars

I cannot reproduce issue #659 locally, which is that an s3fs.put of a single file in a directory produces different results the first and second times it is run. So this PR adds an explicit test for this situation, to run it through the full CI suite.

ianthomas23 avatar Nov 30 '22 14:11 ianthomas23

@tilan7663 , can you produce a test similar to the code here that shows your unexpected behaviour?

martindurant avatar Nov 30 '22 14:11 martindurant

@martindurant @ianthomas23 Thanks for taking a look. I can cherry-pick the change and see if it yields the same behaviour. The behaviour we noticed prior the upgrade is similar to the following

def test_put_single_repeat_2(s3, tmpdir):
    # See https://github.com/fsspec/s3fs/issues/659
    # Potential different behaviour if s3.put called multiple times with
    # a directory containing a single file
    import uuid

    directory = os.path.join(str(tmpdir), "issue659_dir")
    os.mkdir(directory)
    test_file = os.path.join(directory, "issue659_file")
    with open(test_file, "w") as f:
        f.write("some text")

    session_id = uuid.uuid4().hex
    s3_dir = os.path.join(test_bucket_name, session_id)
    s3_file = os.path.join(test_bucket_name, session_id, "issue659_file")
    s3_dir_not_exist = os.path.join(test_bucket_name, session_id, "issue659_dir")
    s3_file_not_exist = os.path.join(test_bucket_name, session_id, "issue659_dir", "issue659_file")

    assert not s3.exists(s3_path)

    for _ in range(2):
        s3.put(directory, s3_dir, recursive=True)
        assert s3.isdir(s3_dir)
        assert s3.isfile(s3_file)
        assert not s3.exists(s3_dir_not_exist)
        assert not s3.exists(s3_file_not_exist)
        assert s3.cat(s3_file) == b"some text"

tilan7663 avatar Dec 01 '22 02:12 tilan7663

@tilan7663 Thanks for the clarification. My test doesn't accurately represent your problem as I've missed out an extra directory level. I will look into it further.

ianthomas23 avatar Dec 01 '22 11:12 ianthomas23

I can confirm now that I can reproduce this but the issue is really in fsspec not just s3fs. Issue https://github.com/fsspec/filesystem_spec/issues/1062 has the relevant discussion. We should hold off from doing anything here until that is dealt with.

ianthomas23 avatar Dec 06 '22 14:12 ianthomas23

I am closing this PR as it has been superseded by #691.

ianthomas23 avatar Feb 01 '23 12:02 ianthomas23