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

sync virtual file without opening #7264

Open
r2evans opened this issue Oct 3, 2024 · 1 comment
Open

sync virtual file without opening #7264

r2evans opened this issue Oct 3, 2024 · 1 comment

Comments

@r2evans
Copy link
Contributor

r2evans commented Oct 3, 2024

How to use GitHub

  • Please use the 👍 reaction to show that you are interested into the same feature.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Feature request

Which Nextcloud Version are you currently using: 29.0.7

Describe the solution you'd like

The ability to initiate sync of file but without opening it.

The current mechanism relies on using xdg-open (or mimeopen) for opening a file: the .nextcloud file extension (on linux) chains through several mime-related files, eventually resolving to using /usr/bin/nextcloud on the file. Its behavior is to sync it to the local directory and then open the file. (If you're curious to which files, read #3668 (comment).)

However, in my use-case I need to open it within the VM, which is certainly not something nextcloud should try to implement. Currently I have to open it in linux, which opens in what linux thinks is the appropriate app (it's insufficient but doesn't crash). I then close the app, then open the file from within the windows-guest VM (with a shared-folder to get to the real file).

A clear and concise description of what you want to happen.

Describe alternatives you've considered

  • nextcloudcmd only syncs whole directories, it does not support individual files; even if it did, I'm not certain that it signals that the file is the realization of a virtual file, and therefore not a change. I would not want this to cause an unnecessary false-signal that the newly downloaded is "new" and needs to be uploaded.
  • anything using webdav falls prey to the same false-signal that the downloaded file is "new" or "changed", which would overwrite the file on the server; at best this is inefficient.
  • I have tried to hack a script that "opens" it (using the default xdg-open/mimeopen mechanism) and immediately close the mime-defined application, but this is just a hack and often doesn't catch it quite in time.

Additional context

  • It is not unheard of that opening the file imposes some change on its contents, either by accident (such as imperfect MS-Office emulation in LibreOffice/OpenOffice, bug reports almost certainly) or by design (I have no example at this time). In this case, syncing the file is the only thing desired, anything more is irreversible.
  • My use-case to open it within a VM is just mine, I think the request is still relevant. For instance, if I'm syncing to the local drive and will then take it to another machine (on which I'm not running a nextcloud desktop client), it might be that the file cannot be run on the local system due to any number of reasons (such as the required software not installed alongside the desktop client).
@r2evans r2evans added 0. Needs triage enhancement enhancement of a already implemented feature/code labels Oct 3, 2024
@r2evans
Copy link
Contributor Author

r2evans commented Oct 18, 2024

I found a (really hackish) workaround until NC decides whether to add command-line control over VFS files (on linux at least).

Internally, /usr/bin/nextcloud calls /usr/bin/xdg-open, and after some sleuthing I discovered that when it is opened by the nextcloud desktop client, the envvar GIO_LAUNCHED_DESKTOP_FILE is set to something like ~/.config/autostart/com.nextcloud.desktopclient.nextcloud.desktop. With that knowledge, we can (relatively) unambiguously determine if we really want to open the file or skip it, optionally notifying the user that the file is now available.

First, we need to preserve the original /usr/bin/xdg-open. Debian-like distros can use dpkg-divert to "permanently" move the file out of the way so that future updates to the xdg-utils package will preserve the renamining:

$ sudo dpkg-divert --add --rename --divert /usr/bin/xdg-open-real /usr/bin/xdg-open

Non-debian like may have something similar (idk), but as a quick hack:

$ sudo mv -i /usr/bin/xdg-open /usr/bin/xdg-open-real

With that, we create a new script /usr/bin/xdg-open that does this:

#!/bin/bash
if [[ "$GIO_LAUNCHED_DESKTOP_FILE" =~ /com\.nextcloud\.desktopclient\.nextcloud\.desktop$ ]]; then
	notify-send --app-name xdg-open "file sync complete" "$@"
else
	exec /usr/bin/xdg-open-real "$@"
fi

I'm using notify-send since I'm on Ubuntu using Gnome, and that's an easy way to let me know that it is complete. You can insert just about anything in there (preferably something that is resilient to errors/mistakes).

@Rello Rello added feature-request new feature and removed enhancement enhancement of a already implemented feature/code labels Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants