Details about trash implementation

Hi,

I’m writing a pet project implementing the Freedesktop.org Trash specification. I’m using the Gnome Files implementation for pointers, and noticed how it handles files/directories with the same name by adding an integer suffix. I was trying to look up the source code for this, but I can’t find the right place, beyond g_file_trash() in gio/gfile.c [1]. Can someone with knowledge in this area guide me to the correct place (I’m working with very basic C experience)?

I’m specifically looking for implementation details on this suffix and if there’s a ceiling to that value.

[1] - gio/gfile.c · main · GNOME / GLib · GitLab

Thanks!

Hi, what you’re looking for is in the implementation of the used interface: gio/glocalfile.c · main · GNOME / GLib · GitLab

1 Like

Thanks!!
Am I reading that part wrong, or does that code say there’s no ceiling for that integer suffix? It looks like the loop condition only checks the file open status and an error result.

Indeed there doesn’t seem to be an upper limit for the integer.

Thanks for the clarification!! Helped me a lot.

Btw, my code is at GitHub - chamilad/trash-rs: A freedesktop.org trash spec implementation in Rust. It’s a side project with main objective to learn rust incrementally. But I intend to bring it to a usable state.

Sorry if this is noisey, I felt this question would fall under the same topic.

I’m still working on this tool (slow progress), and noticed that Gnome files doesn’t seem to utilise directorysizes file at all.

In order to speed up the calculation of the total size of a particular trash directory, implementations (since version 1.0 of this specification) SHOULD create or update the $trash/directorysizes file, which is a cache of the sizes of the directories that were trashed into this trash directory.

https://specifications.freedesktop.org/trash-spec/trashspec-latest.html

I’ve implemented this in my tool, but I don’t have a restoration feature. So when I do restore from Gnome Files, directorysizes is not updated.

I did a brief search but couldn’t find any mail thread or a discussion on this decision. Can anyone help me find the rationale behind not implementing this part of the spec?

I understand it’s “SHOULD” and not “MUST”, but I’m interested in “why not”.

I suppose that you won’t find the rationale anywhere. The directorysizes functionality is the latest addition to the trash-spec. The GNOME trash implementation is way older…

1 Like

That makes so much sense tbh. I was thinking about it as a feature that was ignored, while it looks to be something wasn’t needed to be implemented as the spec got updated.

Thanks for your reply!!