Godot-Project-Builds icon indicating copy to clipboard operation
Godot-Project-Builds copied to clipboard

Clear Directory Files task doesn't work in some circumstances

Open svetogam opened this issue 1 year ago • 8 comments

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.

svetogam avatar Sep 15 '24 00:09 svetogam

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.

KoBeWi avatar Sep 15 '24 14:09 KoBeWi

Yes, I have a "Trash" folder there, in app_userdata/Godot Project Builder/. It's empty.

svetogam avatar Sep 15 '24 16:09 svetogam

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.

KoBeWi avatar Sep 15 '24 16:09 KoBeWi

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.

svetogam avatar Sep 15 '24 22:09 svetogam

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.

KoBeWi avatar Sep 16 '24 10:09 KoBeWi

Yeah, I like the design of overwriting the last removed files, and I don't want the Config menu to get too cluttered.

svetogam avatar Sep 16 '24 19:09 svetogam

Godot issue: https://github.com/godotengine/godot/issues/97097

svetogam avatar Sep 17 '24 02:09 svetogam

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.

svetogam avatar Sep 17 '24 21:09 svetogam

The engine issue was closed. Can you test if it fixes the problem for you?

KoBeWi avatar Oct 15 '24 11:10 KoBeWi

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.

svetogam avatar Oct 15 '24 16:10 svetogam

You can use a build artifact: https://github.com/godotengine/godot/suites/29102792167/artifacts/2004437436

KoBeWi avatar Oct 15 '24 16:10 KoBeWi

Issue is fixed when using the linked build artifact.

svetogam avatar Oct 16 '24 20:10 svetogam