Clear Directory Files task doesn't work in some circumstances
The Clear Directory Files task isn't working for me.
When I execute it with Target Directory: export/linux64 (a folder containing the 2 files found below), it fails with this output.
At the top:
Success Clear Files at /export/linux64
00:00:00 0 <path to program>/Project Builder.x86_64 --headless --script res://Scripts/Tools/ClearDirectory.gd -- <path to game>/export/linux64
Below it:
Failed! Error: 1
Failed! Error: 1
Godot Engine v4.3.stable.official.77dcf97d8 - https://godotengine.org
Removing file: My Game.pck
Removing file: My Game.x86_64
Cleanup finished. Cleared 0 files, 2 files failed.
I tried this on multiple folders. I didn't see it make a change in any of them.
I have the tasks defined in this repo https://codeberg.org/superpractica/superpractica, if you want to try it there yourself.
For safety reasons, Clear Directory Files just moves the files to a dedicated "Trash" folder. Do you have Trash folder in user data directory of Project Builder? If not, try printing the result of this line: https://github.com/KoBeWi/Godot-Project-Builds/blob/39fa06366bda60292d1bfbdf0cd2e578d234b74c/Scripts/Tools/ClearDirectory.gd#L11
I have the tasks defined in this repo https://codeberg.org/superpractica/superpractica, if you want to try it there yourself.
No problems on my side, but I'm on Windows.
Yes, I have a "Trash" folder there, in app_userdata/Godot Project Builder/. It's empty.
Then it means it failed to move the file for some reason. Error 1 is generic fail code, it doesn't give any information.
You could try using ProjectSettings.globalize_path() on the latter path here
https://github.com/KoBeWi/Godot-Project-Builds/blob/b96190ce1c0dff2653500e6a56fd5814203982b6/Scripts/Tools/ClearDirectory.gd#L17
and printing both paths to make sure they are correct.
Or replace the rename with move_to_trash(). The reason I did not use it originally is that "deleting" by moving will overwrite existing files, so they don't accumulate when you perform it multiple times.
OS.move_to_trash() worked, but the other suggestion didn't.
I did some testing and got these results.
Work:
var error := DirAccess.rename_absolute("user://1.txt", "user://Trash/2.txt")
var error := DirAccess.rename_absolute("/home/<user>/1.txt", "user://Trash/2.txt")
var error := DirAccess.rename_absolute("/<other partition>/1.txt", "/<other partition>/2.txt")
Fail:
var error := DirAccess.rename_absolute("/<other partition>/1.txt", "user://Trash/2.txt")
var error := DirAccess.rename_absolute("user://1.txt", "/<other partition>/2.txt")
So it looks like the reason this task fails for me is that DirAccess.rename_absolute() fails when moving between partitions, and my Godot project is on a different partition than the home partition, which is where the user data is.
Either way, this looks like an upstream Godot issue. I'll file a bug there, if it's not already tracked.
I could add an option to remove via move_to_trash(), but if it's engine issue, it's probably not worth it. I don't see it reported yet, so feel free to create an issue.
Yeah, I like the design of overwriting the last removed files, and I don't want the Config menu to get too cluttered.
Godot issue: https://github.com/godotengine/godot/issues/97097
I tried making a simple workaround for this because copy_absolute and remove_absolute together can do the same thing as rename_absolute. But safety and error-handling make this not actually simple. For example, there would have to be something to handle the case of copy not working but then remove working. So I don't think it's worth it.
The engine issue was closed. Can you test if it fixes the problem for you?
My MRP still fails in Godot 4.4 dev3. I think the fix barely missed the window for that one. I'll test it again with the next dev build. I don't really want to build it from source to test.
You can use a build artifact: https://github.com/godotengine/godot/suites/29102792167/artifacts/2004437436
Issue is fixed when using the linked build artifact.