Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV Import/Export does not work with mounts on different devices #4638

Closed
2 tasks done
David-Development opened this issue Sep 29, 2024 · 3 comments · Fixed by #4640
Closed
2 tasks done

CSV Import/Export does not work with mounts on different devices #4638

David-Development opened this issue Sep 29, 2024 · 3 comments · Fixed by #4640
Assignees
Labels
self-hosting Anything self-hosted

Comments

@David-Development
Copy link

Past Issues Searched

  • I have searched open and closed issues to make sure that the bug has not yet been reported

Issue is a Bug Report

  • This is a bug report and not a feature request, nor asking for self-hosted support

Using official Plausible Cloud hosting or self-hosting?

Self-hosting

Describe the bug

When using an external docker mount (on a different device than the docker image) (as seen here: plausible/community-edition#163 (comment)) the import / export does not work.

The following error is shown in the logs:

plausible             | ** (File.RenameError) could not rename from "/tmp/plug-1727-SETA/live_view_upload-1727613873-224587708695-6" to "/var/lib/plausible/plausible-imports/2/live_view_upload-1727613873-224587708695-6": cross-device link
plausible             |     (elixir 1.17.1) lib/file.ex:793: File.rename!/2
plausible             |     (plausible 0.0.1) lib/plausible_web/live/csv_import.ex:48: anonymous fn/3 in PlausibleWeb.Live.CSVImport.mount/3
plausible             |     (phoenix_live_view 0.20.3) lib/phoenix_live_view/upload_channel.ex:21: Phoenix.LiveView.UploadChannel.consume/3
plausible             |     (elixir 1.17.1) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
plausible             |     (plausible 0.0.1) lib/plausible_web/live/csv_import.ex:222: PlausibleWeb.Live.CSVImport.handle_event/3
plausible             |     (phoenix_live_view 0.20.3) lib/phoenix_live_view/channel.ex:497: anonymous fn/3 in Phoenix.LiveView.Channel.view_handle_event/3
plausible             |     (telemetry 1.3.0) /app/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3
plausible             |     (phoenix_live_view 0.20.3) lib/phoenix_live_view/channel.ex:250: Phoenix.LiveView.Channel.handle_info/2
plausible             | Last message: %Phoenix.Socket.Message{topic: "lv:phx-F_m3qTX2RDI1MwXl", event: "event", payload: %{"event" => "submit-upload-form", "type" => "form", "value" => ""}, ref: "60", join_ref: "4"}

A quick chat with ChatGPT revealed that rename is not capable of moving a file past device boundaries. Thus the cp was suggested.

Use of mv or cp Instead of rename: Instead of using the rename function, which fails across devices or mounts, ensure that cp (copy) and rm (remove) are used to move files from /tmp to /var/lib/plausible/.

My understanding is that just the following three locations would need to be adjusted: https://github.com/search?q=repo%3Aplausible%2Fanalytics%20File.rename&type=code. Is that correct? I guess the mv function does not exist in Elixir thus a cp / rm solution would be required.

Expected behavior

Import / Export works even if data is stored on a different device than Docker Image itself.

Screenshots

No response

Environment

- OS: Docker
- Browser: -
- Browser Version: -
@ruslandoga
Copy link
Contributor

ruslandoga commented Sep 29, 2024

👋 @David-Development

Thank you for the report! I actually thought File.rename! was equivalent to unix mv for our purposes ... Live and learn :)

I'll try replacing it with a File.cp! followed by a File.rm! -- as you suggest -- tomorrow.

@ruslandoga ruslandoga added the self-hosting Anything self-hosted label Sep 29, 2024
@ruslandoga ruslandoga self-assigned this Sep 29, 2024
@ruslandoga
Copy link
Contributor

ruslandoga commented Sep 30, 2024

👋 @David-Development

I built a custom image (x86 only) for #4640: https://github.com/ruslandoga/plausible/pkgs/container/plausible/281532216?tag=build-file-rename-fallback

Would you be able to try it out?

plausible:
- image: ghcr.io/plausible/community-edition:v2.1.3
+ image: ghcr.io/ruslandoga/plausible:build-file-rename-fallback

Misc:

@David-Development
Copy link
Author

@ruslandoga It works! Thank you so much for the quick fix! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
self-hosting Anything self-hosted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants