gcsfs icon indicating copy to clipboard operation
gcsfs copied to clipboard

Calling rm(path, recursive=true) on an empty bucket causes a FileNotFound error

Open NickAJScott opened this issue 4 years ago • 2 comments

What happened: Upgrading to version 0.7.1 from 0.6.2 i found behaviour had changed where calling remove on a bucket with recursive = true with the below parameters now throws a FileNotFoundError if the bucket is empty, if the bucket contains a file it successfully deletes it, however it also deletes the bucket as well.

path = "bucket_name//" file_system.rm(path, recursive=true)

What you expected to happen: In 0.6.2 this did not throw exceptions on empty buckets, and when the bucket contained files it just removed all the files from the bucket but did not delete the bucket.

Minimal Complete Verifiable Example:

# Put your MCVE code here
        import gcsfs
        path = "bucket_name//"
        file_system = gcsfs.GCSFileSystem()
        file_system.rm(path, recursive=True)

Anything else we need to know?: Realise this might be an intentional change, but i couldn't find anything mentioning it so thought i would check. Environment:

Exception is not thrown in:

  • Dask version: 0.6.2
  • Python version: 3.6
  • Operating System: docker container
  • Install method (conda, pip, source): pip

Behaviour Changed in:

  • Dask version: 0.7.1
  • Python version: 3.8
  • Operating System: docker container
  • Install method (conda, pip, source): pip

NickAJScott avatar Jan 07 '21 23:01 NickAJScott

if the bucket contains a file it successfully deletes it, however it also deletes the bucket as well.

This seems to me like correct behaviour (like rm -r for posix shells)

FileNotFoundError if the bucket is empty

This seems correct only if bucket does not exist at all. An existing but empty bucket should be deleted with rm(recursive=True) or rmdir.

martindurant avatar Jan 08 '21 18:01 martindurant

@NickScottKortical , do you have any interest in fixing the second point? It would amount to try/excepting FileNotFound in rm for the case that the path requested is a bucket.

martindurant avatar Jan 18 '21 15:01 martindurant