livebook-dev / livebook

Automate code & data workflows with interactive Elixir notebooks
https://livebook.dev
Apache License 2.0
4.99k stars 427 forks source link

Fix file comparison #2707

Closed jonatanklosko closed 4 months ago

jonatanklosko commented 4 months ago

As of #2239 files with the same path created in different processes fail == comparison:

iex> Livebook.FileSystem.File.local("/tmp/") == Livebook.FileSystem.File.local("/tmp/")
true
iex> Livebook.FileSystem.File.local("/tmp/") == Task.await(Task.async(fn -> Livebook.FileSystem.File.local("/tmp/") end))
false

In many cases it's not an issue, because we pass the files around, but in a few it is, see https://github.com/livebook-dev/livebook/discussions/2706#discussioncomment-10030897. We probably need to introduce File.same?().

josevalim commented 4 months ago

Maybe we implement File.compare? Then it could be used for sorting in the future too.

jonatanklosko commented 4 months ago

I'm not sure if there's a one natural order for files if they come from different file systems. It could make sense to sort by path first, but it could also make sense to group files from the same file system and sort by path within that. Sorting by & &1.path is straightforward and explicit. I would start with File.equal?, once we have that it's easy to replace if we decide to :D

josevalim commented 4 months ago

Sounds good to me!