godot: Directory must be open before using remove (3.2.3 rc1)

Godot version: 3.2.3 rc1

OS/device including version: macOS 10.15.5

Issue description: As of 3.2.3 rc1 you must open a directory before using remove. Prior to 3.2.3 rc1 you didn’t have to open up a directory to delete it, which makes sense. If you are attempting to delete a directory, then you probably don’t care if it doesn’t exist. If you did, you’ d check for it first. The new functionality might be the “right” way but I would argue it is a breaking change and shouldn’t be introduced in a patch.

Steps to reproduce: Assuming a directory user://foo exists and it is empty.

var d = Directory.new()
d.remove('user://foo') # this causes error, the directory is not removed.  this works in 3.2.2

Minimal reproduction project: See code. Should be enough.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

The new behavior isn’t complicated, just different, and the behavior was intended by the start. All I did was fix the error condition.

Your PR isn’t complicated, but the repercussions of it are. Should a Directory instance:

  • be able to remove the directory it opened?
  • be able to remove paths that are not sub-paths of what it opened (i.e. opening res://foo but deleting from res://bar)?
  • what happens when whatever you have opened with open becomes invalid? For example you open res://foo in one Directory object, then delete res://foo in another Directory object. The first no longer is “open” to a valid directory.
  • Should each operation that requires a call to open verify that the path is still valid before each action?

The new behavior is correct, the previous one was quite dangerous. Directory auto-opens res:// when it’s instantiated, so if you did:

var dir = Directory.new()
dir.remove("test")

It would remove the res://test folder, and this is unexpected for many users as the implementation detail of Directory starting in res:// by default is not known to all.

If you want to delete a folder in e.g. user://, you should open user:// (and thus have the Directory configured for access to the user:// filesystem), and then you can remove anything you want in user://.