GoogleCloudPlatform / gsutil

A command line tool for interacting with cloud storage services.
Apache License 2.0
864 stars 331 forks source link

`mv` adds additional subfolder when subfolder exists #1787

Open boraberke opened 1 month ago

boraberke commented 1 month ago

When mv is used to move a file between buckets, it behaves differently depending on whether a subfolder with the same name exists.

Reproducing steps

  1. Create two buckets, test-bucket and test-bucket-2.
  2. Create a temp file in your local dir.
    touch 12345.txt
  3. Copy the file to test-bucket with the following subfolders.
    gsutil cp 12345.txt gs://test-bucket/folder/nested_folder/aaaa/bbbb/cccc/12345.txt 
  4. Move file to test-bucket-2.
    gsutil -m mv gs://test-bucket/folder/nested_folder gs://test-bucket-2/folder/nested_folder
  5. Check the contents of test-bucket-2.
    gsutil ls "gs://test-bucket-2/folder/nested_folder/**"

    First Output should be as follows:

    gs://test-bucket-2/folder/nested_folder/aaaa/bbbb/cccc/12345.txt
  6. Repeat the step 3, 4 and 5. Check that output of step 5 included a secondary nested_folder in it.
    gs://test-bucket-2/folder/nested_folder/aaaa/bbbb/cccc/12345.txt
    gs://test-bucket-2/folder/nested_folder/nested_folder/aaaa/bbbb/cccc/12345.txt

I am not sure if this is an expected behavior but same command producing two different results depending on the bucket structure does not feel right.